-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathqqX_setup_and_install
executable file
·199 lines (146 loc) · 9.08 KB
/
qqX_setup_and_install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/usr/bin/env sh
# Copyright (c) Alex Genovese https://github.com/TuxVinyards
# THIS SCRIPT SHOULD BE RUN FROM INSIDE THE qqX DOWNLOAD/SOURCE FOLDER, where it will expect to find the right files
# OR run the target script "./qqX_system_install" from qqX.system folder directly
# From version 1.10.03 A POSIX FRIENDLY .sh SCRIPT is USED AS A WRAPPER, to make sure that it double click executes properly
# in Qt / KDE XFCE etc desktop environments.
# IF: your file manager allows > double mouse click & 'run in terminal' or 'execute'
# OR: in the script's folder > right click > 'run as program' or 'run in konsole' or 'run in terminal'
# OR: in the script's folder > right click > open in terminal > type "./qqX_setup_and_install" (note prefix ./)
# FOR ANY NEWER OR NON-STANDARD TERMINAL, SETTING UP A CUSTOM TERMINAL PROFILE IS RECOMMENDED
# as this will cause the values to be stored for future updates.
# CUSTOM terminal sizes & profile should be initially set just after the initial system checking lines, at around line 290
# in the target script "./qqX_system_install" in the qqX.system folder. See notes in the target script.
# shellcheck disable=SC2009,SC2034
# Terminal name may also be set here, for one-time usage, if '-e' exec functions are recognised:
UserTerm=
printf "" > "/tmp/qqX.termlist"
if [ -n "$UserTerm" ]; then printf "%s\n" "$UserTerm" > "/tmp/qqX.termlist"
fi
# https://stackoverflow.com/questions/35385962/arrays-in-a-posix-compliant-shell#59353917
# NB 'Type' is a Bash builtin, type -p is not supported in 'dash' so command -v needed.
## Selection of terminal:
# Priority is given to main stream user bases and those offering geometry parameters
# 85% of users are probably covered by the first four: "gnome-terminal" "konsole" "mate-terminal" "xfce4-terminal"
# Over 95% probably when "qterminal" and "alacritty" are added.
# There are several popular post-install terminals with various special feature sets.
# However, it is very unlikely to find these and these alone. An underlying standard desktop environment terminal
# can generally be expected to be available so exhaustive checks are not needed.
# Kitty is relatively stable and has more or less standard behaviour, so it has been added for good measure.
# On the other hand, many of these leading edge, often cross-platform terminals are still in active development
# and are liable to change. We need to view these as unstable.
# But, development should be encouraged and revisits made:
# Wezterm @ 10/2024, for example, has much potential but an idiosyncratic command line,
# requests manual closure and has over 900 open issues with which to contend ...
# At the other extreme, and with the advent of Wayland, other projects have been abandoned completely.
# Termite, for example, now encourages the use of Alacritty ...
# Users with Window Managers, not Desktop Envs will be familiar with terminals and settings at the cmd line
# However add some well known interfaces where possible, eg. urxvt that comes with 'i3' as this helps with running of QF
set -- "gnome-terminal" "konsole" "mate-terminal" "xfce4-terminal" "qterminal" "lxterminal" "roxterm" "urxvt" "uxterm" "xterm"
set "$@" -- "alacritty" "kitty" "foot"
while [ -n "$1" ] ; do
if [ -n "$(command -v "$1")" ] ; then printf "%s\n" "$1" >> "/tmp/qqX.termlist"
fi
shift
done
# Priority listing should have placed the top entry as being the most main stream and being one with sufficient size.
# At this stage we are looking for something reliable to run the actual terminal selection script.
if [ -n "$(cat "/tmp/qqX.termlist")" ]; then UserTerm="$(head -n 1 "/tmp/qqX.termlist")"
fi
# If there is still nothing, try a barrel scrape for something running that might have 'term' in the name ...
if [ -z "$UserTerm" ]; then TermGrep="$(pgrep -a term | grep qqX | tr -cd '[:print:]' | awk '{print $2}')"
if [ -n "$TermGrep" ]; then UserTerm="$(basename "$TermGrep")"
fi
fi
DefWidth=150
DefHeight=45
if [ "$UserTerm" = "gnome-terminal" ]; then
"$UserTerm" --geometry ${DefWidth}x${DefHeight} --wait -- "./qqX.system/qqX_system_install"
elif [ "$UserTerm" = "konsole" ]; then
"$UserTerm" --hide-menubar --hide-tabbar --notransparency -p TerminalColumns=145 -p TerminalRows=50 -e "./qqX.system/qqX_system_install"
elif [ "$UserTerm" = "mate-terminal" ]; then
"$UserTerm" --geometry=145x50 --hide-menubar -e "./qqX.system/qqX_system_install"
elif [ "$UserTerm" = "xfce4-terminal" ]; then
"$UserTerm" --geometry=145x50 --hide-menubar --hide-toolbar -e "./qqX.system/qqX_system_install"
elif [ "$UserTerm" = "qterminal" ]; then
# create profile for geometry
if [ -e "$HOME/.config/qterminal.org/qterminal.ini" ]; then
TermConf_User="$HOME/.config/qterminal.org/qterminal.ini"
TermConf_Tmp="/tmp/qq-qterminal.ini"
# sed -i is not always present, use grep.
# But not 'grep -i' as lower case 'size=@' is separate from other camelCase entries with *Size=@
grep -B 500 'size=@' "$TermConf_User" | head -n -1 > "$TermConf_Tmp"
echo "size=@(1200 600)" >> "$TermConf_Tmp"
grep -A 500 'size=@' "$TermConf_User" | tail -n +2 >> "$TermConf_Tmp"
"$UserTerm" -p "$TermConf_Tmp" -e "./qqX.system/qqX_system_install"
else
"$UserTerm" -e "./qqX.system/qqX_system_install"
fi
elif [ "$UserTerm" = "alacritty" ]; then
# create profile for geometry
if [ -e "$HOME/.config/alacritty/alacritty.toml" ]; then
TermConf_User="$HOME/.config/alacritty/alacritty.toml"
TermConf_Tmp="/tmp/qq-alacritty.toml"
# sed -i is not always present, use grep.
grep -B 500 'window.dimensions' "$TermConf_User" > "$TermConf_Tmp"
{ echo "columns = 150" ; echo "lines = 45"; } >> "$TermConf_Tmp"
grep -A 500 'window.dimensions' "$TermConf_User" | tail -n +4 >> "$TermConf_Tmp"
"$UserTerm" --config-file "$TermConf_Tmp" -e "./qqX.system/qqX_system_install"
else
"$UserTerm" -e "./qqX.system/qqX_system_install"
fi
elif [ "$UserTerm" = "lxterminal" ] || [ "$UserTerm" = "roxterm" ]; then
"$UserTerm" --geometry=145x50 -e "./qqX.system/qqX_system_install"
elif [ "$UserTerm" = "urxvt" ]; then
"$UserTerm" -e "./qqX.system/qqX_system_install"
elif [ "$UserTerm" = "uxterm" ] || [ "$UserTerm" = "xterm" ]; then
"$UserTerm" -geometry 145x50 -fa truetype -fs 12 -fg white -bg black -e "./qqX.system/qqX_system_install"
# A popular (and cross-platform) choice for lightweight Wayland is Alacritty, which is higher up the 'set' list.
elif [ "$UserTerm" = "kitty" ] ; then
# Unlikely to be a primary terminal but added as is quite popular, especially with cross-platform users.
"$UserTerm" "./qqX.system/qqX_system_install"
elif [ "$UserTerm" = "foot" ] ; then
# FOO Terminal is a lightweight terminal starting to appear in places for Wayland
# but @ 2024 tests have shown it to throw trivial warnings when switching shells,
# hence the '2>/dev/null' and placement (for now) towards the end
"$UserTerm" "./qqX.system/qqX_system_install" 2>/dev/null
# elif [ "$UserTerm" = "wezterm" ] ; then
#"$UserTerm" start --cwd "$(pwd)" -- "./qqX.system/qqX_system_install" # REVIEW
elif [ -n "$UserTerm" ]; then
# Standard start for unknown possibilities, size params not used:
# Terminals will normally accept '-e' even if it is not the preferred method # REVIEW
"$UserTerm" -e "./qqX.system/qqX_system_install"
elif [ -t 1 ] ; then
# Probably 97 to 100% chance of finding the matching desktop environment default terminal.
# If none found, where possible, if stdout is available, give help message.
# https://stackoverflow.com/a/911213
printf "\n\n TERMINAL NAME not found \n\n"
# show the help notes at top of script
grep -m 1 -A 10 'IF:' "$0"
printf "\n\n [enter] to exit \n\n "
read -r reply
fi
# Exit the script. But also check whether it has been run with a --hold optioned terminal, as Dolphin does, for example.
PidRun="$(ps -eF | grep sh | grep "$$" | grep "$0" | tr -cd '[:print:]' | awk '{print $3}')"
# Needs SIGHUP in KDE or logs out of desktop session... See https://en.wikipedia.org/wiki/Signal_(IPC)#Handling_signals
if [ -n "$PidRun" ]; then kill -s 1 "$PidRun"
else exit
fi
# Licence GPL3 https://www.gnu.org/licenses
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# https://www.gnu.org/licenses
# IF CODE IN GENERAL BECOMES USED IN ANY OTHER PROJECT,
# THE GPL3 LICENCE APPLIES & YOU SHOULD SHOW CLEAR ATTRIBUTIONS.
# But, that said, and without prejudice to the above,
# SMALL CODE SNIPPETS, eg the function printColor, MAY BE USED PERMISSIVELY
# in projects, as MIT or similar, providing CLEAR ATTRIBUTIONS are shown.
# qqX - quickemu quickget X terminal project
# https://code.visualstudio.com/ (recommended)
# vim:tabstop=2:shiftwidth=2:expandtab