2015-11-23 18:28:38 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
CURRENT_DIR="$( dirname ${BASH_SOURCE[0]} )"
|
|
|
|
|
|
|
|
source "$CURRENT_DIR/../helpers.sh"
|
|
|
|
source "$CURRENT_DIR/../variables.sh"
|
|
|
|
|
|
|
|
template() {
|
|
|
|
local tmux_start_script="$1"
|
|
|
|
shift
|
|
|
|
local options="$@"
|
|
|
|
local content=""
|
2021-04-28 05:58:44 +00:00
|
|
|
local resurrect_save_script_path="$(get_tmux_option "$resurrect_save_path_option" "$(realpath ${CURRENT_DIR}/../../../tmux-resurrect/scripts/save.sh)")"
|
2022-01-20 23:28:17 +00:00
|
|
|
local tmux_path="$(command -v tmux)"
|
2015-11-23 18:28:38 +00:00
|
|
|
|
|
|
|
read -r -d '' content <<-EOF
|
|
|
|
[Unit]
|
|
|
|
Description=tmux default session (detached)
|
|
|
|
Documentation=man:tmux(1)
|
|
|
|
|
|
|
|
[Service]
|
2015-11-30 08:09:48 +00:00
|
|
|
Type=forking
|
2015-11-23 18:28:38 +00:00
|
|
|
Environment=DISPLAY=:0
|
2021-12-01 14:16:27 +00:00
|
|
|
ExecStart=${tmux_path} ${systemd_tmux_server_start_cmd}
|
2015-11-23 18:28:38 +00:00
|
|
|
|
2021-04-28 05:58:44 +00:00
|
|
|
ExecStop=${resurrect_save_script_path}
|
2021-12-01 14:16:27 +00:00
|
|
|
ExecStop=${tmux_path} kill-server
|
2015-11-23 18:28:38 +00:00
|
|
|
KillMode=none
|
|
|
|
|
2015-11-30 08:09:48 +00:00
|
|
|
RestartSec=2
|
|
|
|
|
2015-11-23 18:28:38 +00:00
|
|
|
[Install]
|
|
|
|
WantedBy=default.target
|
|
|
|
EOF
|
|
|
|
|
|
|
|
echo "$content"
|
|
|
|
}
|
|
|
|
|
|
|
|
systemd_tmux_is_enabled() {
|
2016-09-17 00:23:28 +00:00
|
|
|
systemctl --user is-enabled $(basename "${systemd_unit_file_path}") >/dev/null 2>&1
|
2015-11-23 18:28:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enable_tmux_unit_on_boot() {
|
|
|
|
if ! systemd_tmux_is_enabled; then
|
|
|
|
systemctl --user enable ${systemd_service_name}
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-11-28 17:11:12 +00:00
|
|
|
systemd_unit_file() {
|
2015-11-23 18:28:38 +00:00
|
|
|
local options="$(get_tmux_option "$auto_start_config_option" "${auto_start_config_default}")"
|
2015-11-26 08:33:06 +00:00
|
|
|
local systemd_tmux_server_start_cmd="$(get_tmux_option "${systemd_tmux_server_start_cmd_option}" "${systemd_tmux_server_start_cmd_default}" )"
|
2015-11-23 18:28:38 +00:00
|
|
|
local tmux_start_script_path="${CURRENT_DIR}/linux_start_tmux.sh"
|
|
|
|
local systemd_unit_file=$(template "${tmux_start_script_path}" "${options}")
|
2017-10-14 15:25:00 +00:00
|
|
|
mkdir -p "$(dirname ${systemd_unit_file_path})"
|
2018-11-28 17:11:12 +00:00
|
|
|
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
|
2015-11-23 18:28:38 +00:00
|
|
|
enable_tmux_unit_on_boot
|
|
|
|
}
|
|
|
|
main
|