From f1197ab2d2ac12933e8020da177c389924c972e9 Mon Sep 17 00:00:00 2001 From: andydna Date: Wed, 28 Nov 2018 11:11:12 -0600 Subject: [PATCH] don't overwrite systemd unit file if it already exists --- .../systemd_enable.sh | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/scripts/handle_tmux_automatic_start/systemd_enable.sh b/scripts/handle_tmux_automatic_start/systemd_enable.sh index d37c889..7a2cf15 100755 --- a/scripts/handle_tmux_automatic_start/systemd_enable.sh +++ b/scripts/handle_tmux_automatic_start/systemd_enable.sh @@ -44,13 +44,27 @@ enable_tmux_unit_on_boot() { fi } -main() { +systemd_unit_file() { local options="$(get_tmux_option "$auto_start_config_option" "${auto_start_config_default}")" local systemd_tmux_server_start_cmd="$(get_tmux_option "${systemd_tmux_server_start_cmd_option}" "${systemd_tmux_server_start_cmd_default}" )" local tmux_start_script_path="${CURRENT_DIR}/linux_start_tmux.sh" local systemd_unit_file=$(template "${tmux_start_script_path}" "${options}") mkdir -p "$(dirname ${systemd_unit_file_path})" - echo "$systemd_unit_file" > "${systemd_unit_file_path}" + echo "$systemd_unit_file" +} + +write_unit_file() { + systemd_unit_file > "${systemd_unit_file_path}" +} + +write_unit_file_unless_exists() { + if ! [ -e "${systemd_unit_file_path}" ]; then + write_unit_file + fi +} + +main() { + write_unit_file_unless_exists enable_tmux_unit_on_boot } main