@@ -5,21 +5,24 @@ set -euo pipefail
55usage () {
66 cat << 'USAGE '
77Usage:
8- platforms/linux/install-gnome-autostart.sh [--repo-root PATH] [--autostart-name NAME] -- <ppuc-pinmame args...>
8+ platforms/linux/install-gnome-autostart.sh [--repo-root PATH] [--autostart-name NAME] [--terminal CMD] -- <ppuc-pinmame args...>
99
1010Examples:
1111 platforms/linux/install-gnome-autostart.sh -- -c examples/t2.yml -n -i
1212 platforms/linux/install-gnome-autostart.sh --repo-root /opt/ppuc -- -c /opt/ppuc/examples/t2.yml -n -i
13+ platforms/linux/install-gnome-autostart.sh --terminal kgx -- -c examples/t2.yml -n -i
1314
1415Notes:
1516 - The script writes ~/.config/autostart/<name>.desktop for GNOME/XDG autostart.
17+ - It also writes a small launcher script under ~/.local/share/ppuc/autostart/.
1618 - The repo build output is expected at <repo-root>/ppuc/ppuc-pinmame.
1719 - Any relative paths after -- are resolved from <repo-root> before being written.
1820USAGE
1921}
2022
2123repo_root=" $( pwd) "
2224autostart_name=" ppuc-pinmame"
25+ terminal_cmd=" "
2326
2427while [[ $# -gt 0 ]]; do
2528 case " $1 " in
@@ -33,6 +36,11 @@ while [[ $# -gt 0 ]]; do
3336 [[ $# -gt 0 ]] || { echo " Missing value for --autostart-name" >&2 ; exit 1; }
3437 autostart_name=" $1 "
3538 ;;
39+ --terminal)
40+ shift
41+ [[ $# -gt 0 ]] || { echo " Missing value for --terminal" >&2 ; exit 1; }
42+ terminal_cmd=" $1 "
43+ ;;
3644 --help|-h)
3745 usage
3846 exit 0
@@ -62,6 +70,9 @@ binary="$workdir/ppuc-pinmame"
6270template=" $repo_root /platforms/linux/autostart/ppuc-pinmame.desktop.in"
6371autostart_dir=" ${XDG_CONFIG_HOME:- $HOME / .config} /autostart"
6472desktop_file=" $autostart_dir /$autostart_name .desktop"
73+ data_home=" ${XDG_DATA_HOME:- $HOME / .local/ share} "
74+ launcher_dir=" $data_home /ppuc/autostart"
75+ launcher_script=" $launcher_dir /$autostart_name .sh"
6576
6677if [[ ! -x " $binary " ]]; then
6778 echo " Expected executable not found: $binary " >&2
@@ -93,16 +104,57 @@ for arg in "$@"; do
93104 esac
94105done
95106
96- printf -v quoted_exec ' %q ' " $binary " " ${resolved_args[@]} "
97- quoted_exec=" ${quoted_exec% } "
107+ if [[ -z " $terminal_cmd " ]]; then
108+ if command -v gnome-terminal > /dev/null 2>&1 ; then
109+ terminal_cmd=" gnome-terminal"
110+ elif command -v kgx > /dev/null 2>&1 ; then
111+ terminal_cmd=" kgx"
112+ elif command -v x-terminal-emulator > /dev/null 2>&1 ; then
113+ terminal_cmd=" x-terminal-emulator"
114+ else
115+ echo " No supported terminal emulator found. Use --terminal <command>." >&2
116+ exit 1
117+ fi
118+ fi
119+
98120mkdir -p " $autostart_dir "
121+ mkdir -p " $launcher_dir "
122+
123+ {
124+ echo " #!/bin/bash"
125+ echo " set -euo pipefail"
126+ echo " cd $( printf ' %q' " $workdir " ) "
127+ printf ' exec %q' " $binary "
128+ for arg in " ${resolved_args[@]} " ; do
129+ printf ' %q' " $arg "
130+ done
131+ printf ' \n'
132+ } > " $launcher_script "
133+
134+ chmod 755 " $launcher_script "
135+
136+ case " $terminal_cmd " in
137+ gnome-terminal)
138+ printf -v autostart_exec ' %q --wait -- %q' " $terminal_cmd " " $launcher_script "
139+ ;;
140+ kgx)
141+ printf -v autostart_exec ' %q -- %q' " $terminal_cmd " " $launcher_script "
142+ ;;
143+ x-terminal-emulator)
144+ printf -v autostart_exec ' %q -e %q' " $terminal_cmd " " $launcher_script "
145+ ;;
146+ * )
147+ printf -v autostart_exec ' %q -e %q' " $terminal_cmd " " $launcher_script "
148+ ;;
149+ esac
99150
100151sed \
101- -e " s|@PPUC_WORKDIR@|$workdir |g" \
102- -e " s|@PPUC_EXEC@|$quoted_exec |g" \
152+ -e " s|@AUTOSTART_EXEC@|$autostart_exec |g" \
103153 " $template " > " $desktop_file "
104154
105155chmod 644 " $desktop_file "
106156
107157echo " Installed GNOME autostart entry: $desktop_file "
108- echo " Command: $quoted_exec "
158+ echo " Launcher: $launcher_script "
159+ echo " Terminal: $terminal_cmd "
160+ echo " Command: $binary ${resolved_args[*]} "
0 commit comments