-
Notifications
You must be signed in to change notification settings - Fork 2
/
qqX_setup_and_install
executable file
·837 lines (584 loc) · 33.6 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
#!/usr/bin/env bash
## THIS SCRIPT SHOULD BE RUN FROM INSIDE THE qqX DOWNLOAD/SOURCE FOLDER, where it will expect to find the right files
## TO INSTALL:
# if your file manager allows > mouse click & 'run as program' or 'run in terminal'
# OR:
# in the folder > right click > open in terminal > type "./qqX_setup_and_install" (note prefix ./)
## CUSTOM TERMINAL SIZES & PROFILE may be set further down, just after the initial system checks
## Copyright (c) Alex Genovese https://github.com/TuxVinyards
# SMALL CODE SNIPPETS eg the function printColor MAY BE USED
# PERMISSIVELY in projects as MIT or similar, providing CLEAR ATTRIBUTIONS are shown.
# Otherwise:
# 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.
## qqX - quickemu quickget X terminal project
# STANDARD INSTALLATION default, next to quickemu @ /usr/bin/qqX && link @ /usr/bin/qqx
# From qqX 1.6 onwards, a folder /usr/share/qqX should be created for the subfolder and files of qqX.main
# Although popular, using a start line of "#!/usr/bin/env bash" will mask process names & inhibit process controls.
# It is not a silver bullet & can also cause problems with bash exec clauses ...
# Some users may need to change the qqX script start line from #!/bin/bash, or other, to point to where their bash binary is located.
# Only the main qqX script itself should need to be changed. This is easiest if done before running the installer but can also be done afterwards.
# The commands "type -p bash" or "which bash" should help locate this.
# See https://unix.stackexchange.com/questions/29608/why-is-it-better-to-use-usr-bin-env-name-instead-of-path-to-name-as-my#29620
# Differences may be present in non FHS distros & may need special installation
# See var 'qqX_Std_Bin_Dir' below & https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard
# In NixOS we need to change '#!/bin/bash' to '#!/run/current-system/sw/bin/bash' but as every program needs its own unique store ID,
# this probably (@ 2023/10) is a work in progress & a special qqX installer is needed, in the same way to that quickemu itself does ...
# See https://github.com/TuxVinyards/qqX/issues/1 & https://discourse.nixos.org/t/install-executable-at-usr-bin/21756
# From qqX 1.6 onwards, a folder /usr/share/qqX should be created. This location may be group edited, further on in the script.
# $1 as 'Upgrade' may be supplied to change the menu look eg "./qqX_setup_and_install Upgrade" (see qqX updater function)
# https://www.shellcheck.net/wiki/SC1090 for file sourcing, SC2317 for reachability
# shellcheck disable=SC1090
# shellcheck disable=SC2317
# shellcheck disable=SC2034
if [[ ! "$(type -p bash)" ]] || ((BASH_VERSINFO[0] < 5)); then
echo; echo " Sorry, you probably need Bash 5.0 or newer to run this script."; echo
echo " qqX has only been tested on up-to-date versions of Bash ...."; echo
echo " Your version: "; echo
bash --version
echo
read -rp " Press [enter] to try anyway [e] to exit and update > " UpdateBash
if [[ $UpdateBash ]]; then echo; exit 1;
else echo; echo " I understand the risks and have made backups" ; echo ; read -rp " [enter] to confirm [e] to exit > " UpdateBash ; fi
echo
[[ $UpdateBash ]] && exit 1
fi
HideFHSwarnings= # To disable FHS warnings. Set =1
if [[ ! $HideFHSwarnings ]] && [[ ! -d "/tmp" || ! -d "/usr/share" ]]; then
# https://superuser.com/questions/332610/where-is-the-temporary-directory-in-linux#332616
printf "\n\n\n Please read the notes at the start of this installer script."
printf "\n\n NON Filesystem_Hierarchy_Standard system: \"/tmp\" or \"/usr/share\" not located"
printf "\n\n [q] to quit [enter] ignore & continue \n\n"
read -rp " > " FHS_Alert
[[ $FHS_Alert ]] && exit
fi
# Auto-change of the qqX shebang could be implemented BUT it is likely that users encountering this problem
# will need more adjustments than just this, so flag up for them to read the notes & probably other:
# Use 'type -p' which is the 'newer' method and qqX tests have shown problems using 'command -v'
# Using caps (type -P) will show aliases and qqX re-routes
OS_BashLocation="$(type -p bash)"
if [[ ! $HideFHSwarnings ]] && [[ "$OS_BashLocation" != "/usr/bin/bash" ]]; then
printf "\n\n\n Please read the notes at the start of this installer script."
if [[ ! $OS_BashLocation ]]; then printf "\n\n Bash has not been found ....."
else
printf "\n\n The start line to the qqX main script may need to be adjusted."
printf "\n\n Bash has been located at %s" "$OS_BashLocation"
fi
printf "\n\n [q] to quit [enter] to ignore or continue \n\n"
read -rp " > " FHS_Alert
[[ $FHS_Alert ]] && exit
fi
# Set this session to bash. Attempt to make things work better if subsitute shell has been used eg. fishshell
export SHELL="$OS_BashLocation"
if [[ ! $HideFHSwarnings ]] && ! tput -V | grep -q ncurses 2> /dev/null; then
printf "\n\n Check your OS > \n\n An 'ncurses' installation should normally be present. Test using 'tput -V' "
printf "\n\n [q] to quit [enter] to ignore or continue \n\n"
read -rp " > " FHS_Alert
[[ $FHS_Alert ]] && exit
fi
if [[ ! $HideFHSwarnings ]] && [[ ! $(type -p bc) ]]; then
printf "\n\n Check your OS > \n\n A 'bc' installation should normally be present and is required by qqX ..."
printf "\n\n [q] to quit [enter] to ignore or continue \n\n"
read -rp " > " FHS_Alert
[[ $FHS_Alert ]] && exit
fi
## Check for 'curl' as not in all distros (where $1 test is true if command line is being used)
if [[ ! $(type -p curl) ]]; then
printf "\n\n 'Curl' is a listed dependency of QuickEmu and is also used by qqX ...\n\n"
if [[ $1 ]]; then exit 1 ; else read -rp " [enter] to ignore or continue > " ; fi
fi
## Check for 'jq' as not in all distros (where $1 test is true if command line is being used)
if [[ ! $(type -p jq) ]]; then
printf "\n\n 'jq' is a listed dependency of QuickEmu ...\n\n"
if [[ $1 ]]; then exit 1 ; else read -rp " [enter] to ignore or continue > " ; fi
fi
## Check for 'bc' as not in all distros (where $1 test is true if command line is being used)
if [[ ! $(type -p bc) ]]; then
printf "\n\n A 'bc' installation should normally be present and is required by qqX ...\n\n"
if [[ $1 ]]; then exit 1 ; else read -rp " [enter] to ignore or continue > " ; fi
fi
## Check for 'wget' as not in all distros (where $1 test is true if command line is being used)
if [[ ! $(type -p wget) ]]; then
printf "\n\n A 'wget' installation should normally be present and is needed in certain places ...\n\n"
if [[ $1 ]]; then exit 1 ; else read -rp " [enter] to ignore or continue > " ; fi
fi
if [[ ! $(type -p spicy) ]]; then
printf "\n\n Check for 'spice' installations 'spicy', 'spice-vdagent' and 'spice-gtk'/'spice-client-gtk' ...\n\n"
if [[ $1 ]]; then exit 1 ; else read -rp " [enter] to ignore or continue > " ; fi
fi
qqX_Version="$(./qqX --version 2>/dev/null)"
# Default location is next to quickemu in "/usr/bin" This may frequently be set just to "/bin"
# as this is often just a symlink and qqX will actually install to "/usr/bin".
# However, this doesn't always follow. Although the bash shebang itself starts at "/bin"
# some systems have not adopted or allowed for the newer standard method and will only route
# items on an individual basis.
# In ref to https://github.com/TuxVinyards/qqX/issues/1 edit here for unusuals eg. nix/store/uniques etc
Current_qqX_Location="$(type -p qqX)"
if [[ ! $Current_qqX_Location ]]; then
# new install
qqX_Std_Bin_Dir="/usr/bin"
else
# updating existing install
qqX_Std_Bin_Dir="$(dirname "$Current_qqX_Location")"
fi
qqX_Std_File_Path="$qqX_Std_Bin_Dir/qqX"
qqX_Std_lc_Link_Path="$qqX_Std_Bin_Dir/qqx"
# From qqX 1.6 onwards, a folder /usr/share/qqX should be created for the subfolder and files of qqX.main
# And from 1.8 the subfolder qqX.builtins
# For non FHS OS's also edit at start of main file 'qqX' ...
qqX_Std_Share_Path="/usr/share/qqX"
# See $: xdg-desktop-menu --manual # See https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-1.0.1.html
# qqX 1.9 on, move .desktop "$HOME/.local/share/applications" to "/usr/share/applications"
XDG_GUI_desktop_Folder="/usr/share/applications"
XDG_GUI_desktop_Name="qqX.desktop"
XDG_GUI_desktop_PathName="$XDG_GUI_desktop_Folder/$XDG_GUI_desktop_Name"
function print_manual_uninstall_notes {
cat << Notes
Manual uninstall, standard procedure >> remove the hidden .qqX folder from $HOME
and any desktop items in folder: $qqX_Std_Share_Path
followed by: sudo update-desktop-database "$XDG_GUI_desktop_Folder"
Sudo remove the scripts > sudo rm /usr/bin/qqX & sudo rm /usr/bin/qqx
From qqX 1.6 onwards also remove sudo rm -r /usr/share/qqX
Notes
}
## TERMINAL:
function print_terminal_notes {
# See https://stackoverflow.com/questions/22697688/how-to-cat-eof-a-file-containing-code
# ( NB use of escape EOF, or quotes, not used )
cat << Notes
TO MANUALLY SPECIFY the terminal name, the installer script's 'UserTerm' variable may be used.
From qqX version 1.10.02 onwards, a 'CustomTerminalProfile' will now be stored in the qqX settings folder.
This file will be checked and auto-read when carrying out updates.
For first installs or profile re-imposition this installer script may be directly edited.
Open the script in a standard text editor at around line 240.
If updating, the file '$HOME/.qqX/qqX_term.conf' may also be edited (hidden)
MAKE SURE to SELECT option [r] reconfigure desktop launcher, as this where the terminal command is finally used.
It is quite common for different distros to rename or tweak a standard terminal.
Typing the terminal name, followed by '--help' should give you a list of the parameters that you can use.
Note that options can vary slightly and can also be subject to theming or desktop environment overides.
For actual 'XTERM' itself, also edit the installer script's 'CustomTerminalProfile'
eg xterm -geometry 145x50 -fa truetype -fs 12
For CUSTOM PROFILES, only one profile line is required and the actual sizes are best stated.
Auto-updating size variable lines are difficult to set, due to 'escaping' routines,
but may be initially be copied, if wished. Size variables will eventually become overwritten as numerics.
eg. CustomTerminalProfile=" --geometry=145x50 --hide-menubar --title=qqX "
Remember that width and height are column/row units which are based on the size of your terminal font
and that the window size will alter when the font size is changed.
Notes
}
## SET TERMINAL SIZES & PROFILE
# Changes made to height and width values will be transitory only.
# Use 'CustomTerminalProfile' for customization ....
Term_Width=145
Term_Height=50
Term_Taller=55
# EDIT HERE to either set or to rewrite 'qqX_term.conf'
UserTerm=
CustomTerminalProfile=
# REVIEW qqX 1.9 changes desktop command slightly and 'desktop-file-validate' no says to remove the single quotes: --title='qqX'
# MATE:
MateTerminalProfile_Taller=" --geometry=${Term_Width}x${Term_Taller} --hide-menubar --title=qqX "
MateTerminalProfile_Standard=" --geometry=${Term_Width}x${Term_Height} --hide-menubar --title=qqX "
# GNOME:
GnomeTerminalProfile_Taller=" --geometry=${Term_Width}x${Term_Taller} --hide-menubar --title=qqX "
GnomeTerminalProfile_Standard=" --geometry=${Term_Width}x${Term_Height} --hide-menubar --title=qqX "
# XFCE4:
XfceTerminalProfile_Taller=" --geometry=${Term_Width}x${Term_Taller} --hide-menubar --hide-toolbar --title=qqX --icon=$HOME/.qqX/icons/qqX.std.logo.96.png"
XfceTerminalProfile_Standard=" --geometry=${Term_Width}x${Term_Height} --hide-menubar --hide-toolbar --title=qqX --icon=$HOME/.qqX/icons/qqX.std.logo.96.png"
# KONSOLE:
KonsoleTitle="qqX"
KonsoleTerminalProfile_Taller=" --title $KonsoleTitle --hide-menubar --hide-tabbar --notransparency -p TerminalColumns=${Term_Width} -p TerminalRows=${Term_Taller} "
KonsoleTerminalProfile_Standard=" --title $KonsoleTitle --hide-menubar --hide-tabbar --notransparency -p TerminalColumns=${Term_Width} -p TerminalRows=${Term_Height}"
# REVIEW normal KDE behaviour is to overide the launcher options if 'remember konsole size and position' has been set
## Check we are in the right place
if [[ ! -d "$(pwd)/qqX.system" ]]; then
printf "\n\n ERROR qqX install script must be run from inside the original qqX folder \n\n"
sleep 8 ; exit 1
fi
# Chrome up the display
source "qqX.system/qqX_add_in_boot_level_chrome"
# and add in the settings updater
source "qqX.system/qqX_settings_update_transposer"
## START
printf "\033c"
echo
qqX_logo_title "quickemu quickget X terminal project - setup, install, uninstall & update script for qqX $qqX_Version "
if [[ "$(whoami)" == root ]]; then
UserLand_Name="$(users)"
printColor "\n\n User-Interactive Scripts:\n\n Root installation is not currently available. "
printColor "\n\n Select a trusted UserLand folder (%s) etc\n\n" "$UserLand_Name"
read -rp " See setup script and installation notes > "
# Root will not have xdg data ....
fi
echo
## PROBE SYSTEM ENVIRONMENT
LinuxType=$(uname -o)
LinuxMachine=$(uname -m)
if [[ ! $LinuxType ]] || [[ "$LinuxType" != *Linux ]] && [[ $LinuxMachine != "x86_64" ]] ; then
printf "\n\n ERROR OS found: %s %s " "$LinuxType" "$LinuxMachine"
printColor "\n\n @ 2023 Quickemu scripts are intended for 64 bit LINUX X86 distributions only \n\n"
printf "\n Make sure that you have read this script and the docs before continuing \n\n"
read -rp " Use 'ctrl-c' to exit or [enter] to continue > "
fi
if [[ -d "/mnt/c/Windows" ]]; then WSL_Install=1 ; else WSL_Install= ; fi
# INITIAL MENU:
printf "\033c"
echo
qqX_logo_title "quickemu quickget X terminal project - setup script $qqX_Version "
if [[ ! -e "./qqX_settings" ]] && [[ ! -e "./qqX" ]] && [[ ! -d "./qqX.system" ]] && [[ ! -d "./qqX.main" ]] && [[ ! -d "./qqX.builtins" ]]; then
printColor "\n\n ERROR qqX source files not found \n\n"
sleep 5; exit 1
else
InstallSelect=
if [[ $(type -p qqX) ]]; then Current_qqX_Version="$(qqX --version)" ; else Current_qqX_Version= ; fi
if [[ $1 == "Upgrade" ]] || [[ -d "$HOME/.qqX" ]]; then printf "\n Upgrade the current release %s ..." "$Current_qqX_Version"
else printColor "\n Install a settings file to %s & add program scripts?" "$HOME"
fi
cat "qqX.system/icons/qqX.ascii.logo.8bit.25.txt"
printColor "\n [enter] to auto-install from this terminal"
[[ $(type -p qqx) || $(type -p qqX) ]] && printf "\n\n [u] un-install scripts and settings [enter] re-install/upgrade"
printf " [m] use manual installation"
printf " [q] to quit \n\n"
read -rp " > " InstallSelect
if [[ $InstallSelect == "q" ]]; then
sleep 0.6 ; exit
elif [[ $InstallSelect == "u" ]]; then
printf "\n\n"
print_manual_uninstall_notes
printColor "\n\n Remove any qqX taskbar icons BEFORE proceeding. Some distros may need this this."
qqX_RemovalTarget="$(type -p qqx)"
qqX_RemovalTarget_X="$(type -p qqX)"
qqX_Remove=
printColor "\n\n [y] sudo auto removal of qqX scripts and settings and builtins."
printf " \n\n All VM folders will be left as they are ... [enter] to quit \n\n"
read -rp " > " qqX_Remove
printf "\n\n"
if [[ $qqX_Remove == "y" ]]; then
[[ $qqX_RemovalTarget ]] && sudo rm "$qqX_RemovalTarget"
[[ $qqX_RemovalTarget_X ]] && sudo rm "$qqX_RemovalTarget_X"
[[ -d "/usr/share/qqX" ]] && sudo rm -r "/usr/share/qqX"
[[ -d "$HOME/.qqX" ]] && rm -r "$HOME/.qqX"
[[ -e "$XDG_GUI_desktop_Folder/qqX.desktop" ]] && sudo rm "$XDG_GUI_desktop_Folder/qqX.desktop"
[[ $(type -p update-desktop-database) ]] && sudo update-desktop-database "$XDG_GUI_desktop_Folder"
printColor "\n\n Auto-closure of this script may not happen in some desktop environments ... "
printColor "\n\n Removal processing complete \n\n"
read -rp " [enter] to quit > "
printf "\n\n"
tput cnorm
exit
else sleep 0.6 ; exit
fi
else
# install / re-install > includes option [r]
SeparateSudo=
if [[ $InstallSelect == "m" ]] ; then
printf "\n\n Open another terminal IN THE SOURCE FOLDER"
printf "\n where the following commands should be issued:"
printColor "\n\n sudo cp \"qqX\" \"%s\" " "$qqX_Std_File_Path"
printColor "\n\n sudo ln -s \"%s\" \"%s\" " "$qqX_Std_File_Path" "$qqX_Std_lc_Link_Path"
printf "\n\n From qqX 1.6 onwards, a folder /usr/share/qqX should also be created"
printf "\n for the subfolders and files of qqX.main and from 1.8 onwards of qqX.builtins"
printColor "\n\n sudo mkdir -p \"%s/qqX.main\" " "$qqX_Std_Share_Path"
printColor "\n\n sudo cp \"./qqX.main/qqX_\"* \"%s/qqX.main/\" " "$qqX_Std_Share_Path"
printColor "\n\n sudo cp -r \"./qqX.builtins/\"* \"%s/qqX.builtins/\" " "$qqX_Std_Share_Path"
printColor "\n\n sudo chmod a+rx -R \"%s/\" " "$qqX_Std_Share_Path"
printf "\n\n NOTE command line installation only. Use auto for desktop launchers and shortcuts"
printf "\n\n [enter] changed mind, use auto-install [y] to confirm action completed \n\n"
read -rp " > " SeparateSudo
printf "\n"
fi
if [[ $SeparateSudo != "y" ]]; then
printColor "\n Auto-Installing .... \n\n"
sudo cp "qqX" "$qqX_Std_File_Path"
[[ ! -e "$qqX_Std_lc_Link_Path" ]] && sudo ln -s "$qqX_Std_File_Path" "$qqX_Std_lc_Link_Path"
[[ ! -d "$qqX_Std_Share_Path" ]] && sudo mkdir -p "$qqX_Std_Share_Path/qqX.main"
sudo cp "./qqX.main/qqX_"* "$qqX_Std_Share_Path/qqX.main"
sudo cp -r "./qqX.builtins"* "$qqX_Std_Share_Path/"
sudo chmod a+rx -R "$qqX_Std_Share_Path/"
fi
# Make symbolic link lowercase 'qqx' , as in: ln -s textfile.txt my_link.
# Means copying to qqx will copy to qqX, and vice versa.
# And check that the right version is there:
if [[ -e "$qqX_Std_File_Path" && -e "$qqX_Std_lc_Link_Path" ]] && [[ "$(qqx --version 2>/dev/null)" == "$qqX_Version" ]] ; then
printColor "\n ...... All good "
else printColor "\n\n ERROR qqX version %s not installed correctly. Check 'bin' path in installer script. Quit and retry." "$qqX_Version" ; sleep 2000
fi
Default_VM_Folder=
if grep -q -s Default_VM_Folder= "$HOME/.qqX/qqX_settings" ; then
TestDefVMs="$(grep -m 1 -s Default_VM_Folder= "$HOME/.qqX/qqX_settings")"
if [[ $TestDefVMs ]]; then eval "$TestDefVMs"; fi
fi
if [[ -d "$HOME/VMQs" ]] ; then
printColor "\n\n Standard default VM directory has been found >> "
printf "\n\n %s " "$HOME/VMQs"
elif [[ -d "$Default_VM_Folder" ]]; then
printColor "\n\n Custom default VM directory has been found >> "
printf "\n\n %s " "$Default_VM_Folder"
else
MkDefDir=
printColor "\n\n\n A default VM directory is required >> "
printf "\n\n %s\n\n This location can be easily moved and/or renamed later," "$HOME/VMQs"
printf "\n\n simply by using the file manager and by editing the qqX settings."
printColor "\n\n [enter] make folder '%s'" "$HOME/VMQs"
printColor " [n] not yet >> edit the settings file later ... \n\n"
read -rp " > " MkDefDir
if [[ ! $MkDefDir && ! -d "$HOME/VMQs" ]]; then mkdir "$HOME/VMQs" || printColor "\n\n ERROR making Default VM folder %s \n\n" ; fi
# qqX default location: has to be slightly opinionated here (and at end of script) for the updater to work REVIEW
fi
if [[ ! -d "$HOME/.qqX" ]]; then mkdir "$HOME/.qqX" || printColor "\n\n Settings folder ERROR creating \n\n" ; fi
if [[ -e "$HOME/.qqX/qqX_settings" ]]; then update_old_settings_file_with_new_options ""
else cp "qqX_settings" "$HOME/.qqX/qqX_settings"
fi
cp -r "qqX.system/icons" "$HOME/.qqX"
printColor "\n\n Installing settings file and desktop icons \n\n"
if [[ ! $(type -p qqx) && ! $(type -p qqX) ]] || [[ ! -e "$HOME/.qqX/qqX_settings" ]] || [[ ! -e "$HOME/.qqX/icons/qqX.std.logo.128.png" ]]; then
printColor "\n\n ERROR qqX files not installed correctly \n\n"
[[ ! $(type -p qqx) && ! $(type -p qqX) ]] && printf "\n\n The main qqX files in /usr/bin"
[[ ! -e "$HOME/.qqX/qqX_settings" ]] && printf "\n\n The hidden files .qqX/qqX_settings in the Home directory"
[[ ! -e "$HOME/.qqX/icons/qqX.std.logo.128.png" ]] && printf "\n\n The hidden icon files .qqX/icons/.. in the Home directory"
printf "\n\n [enter] to close & investigate \n\n"
read -rp " > "
exit 1
fi
fi
fi
## DESKTOP LAUNCHER
SkipMkLauncher=
if [[ -e "$XDG_GUI_desktop_PathName" ]] ; then
printColor "\n\n A desktop launcher already exists >> "
if grep -q -s 'x-cd-image' "$XDG_GUI_desktop_PathName" ; then
printf "\n\n Unless changing the terminal size, the icon or similar, may be skipped ..."
else
printf "\n\n BUT... to enable new qqX features, we need to take a few seconds to reconfigure the launcher"
ForceReconfigure=1
fi
printColor "\n\n [enter] to skip "
printf "[r] to reconfigure \n\n"
read -rp " > " SkipMkLauncher
if [[ $SkipMkLauncher == "r" || $ForceReconfigure ]]; then SkipMkLauncher= ; else SkipMkLauncher=1 ; fi
fi
if [[ ! $SkipMkLauncher ]]; then
if [[ -e "$HOME/.qqX/qqX_term.conf" ]]; then
source "$HOME/.qqX/qqX_term.conf"
fi
if [[ $UserTerm || $CustomTerminalProfile ]]; then
# from an edit at the start of the installer (which also allows for overwrites of qqX_term.conf)
if [[ ! -d "$HOME/.qqX" ]]; then mkdir "$HOME/.qqX" || printColor "\n\n Settings folder ERROR creating \n\n" ; fi
if [[ ! $UserTerm ]]; then AddFound_UserTerm=1 ; else AddFound_UserTerm= ; fi
{
printf "\n UserTerm=\"%s\"" "$UserTerm"
printf "\n\n CustomTerminalProfile=\"%s\"\n" "$CustomTerminalProfile"
} > "$HOME/.qqX/qqX_term.conf"
elif [[ -e "$HOME/.qqX/qqX_term.conf" ]]; then
# empty or errored file, so remove it
rm "$HOME/.qqX/qqX_term.conf"
fi
# The name of the terminal emulator is needed (may also be manually specified at start of script)
[[ ! $UserTerm ]] && source "$(pwd)/qqX.system/qqX_termfind"
if [[ $AddFound_UserTerm && $UserTerm ]]; then
{
printf "\n UserTerm=\"%s\"" "$UserTerm"
printf "\n\n CustomTerminalProfile=\"%s\"\n" "$CustomTerminalProfile"
} > "$HOME/.qqX/qqX_term.conf"
fi
## HOW THE INTERFACE WILL LOOK
printf "\033c"
echo
qqX_logo_title "Setting up the desktop:"
if [[ $UserTerm ]]; then
printColor "\n\n qqX standard window size is %s columns wide & %s lines high" "$Term_Width" "$Term_Height"
if [[ -e "$HOME/.qqX/qqX_term.conf" ]]; then
printf "\n\n A custom terminal profile is being used: \n\n"
cat "$HOME/.qqX/qqX_term.conf"
fi
if [[ ! -e "$HOME/.qqX/qqX_term.conf" ]]; then
printf "\n\n Use extra height (%s) to help show multifile or quickget output better" "$Term_Taller"
printf "\n but be aware this will hide more of the file manager output"
printf "\n while some menu screens may contain empty space."
printf "\n\n The setting 'CustomTerminalProfile' near the start of this script, may also be edited."
fi
printf "\n\n Note that when starting qqX directly from the command line, the system's window sizes will apply."
printf "\n System defaults may usually be changed in the terminal settings, under 'profile'"
printf "\n\n Remember that column width units are based on the size of your terminal font,"
printf "\n so changing the font will also change the physical terminal size."
printf "\n\n\n"
# REVIEW add W H number entry?
printColor " [enter] continue "
if [[ ! -e "$HOME/.qqX/qqX_term.conf" ]]; then
printColor "at standard height "
printf " [t] extra height or "
fi
else
print_terminal_notes
printColor "\n https://github.com/TuxVinyards/qqX/wiki "
printf "\n\n https://github.com/TuxVinyards/qqX/wiki/Translation \n\n"
fi
printf " [q] to exit \n\n"
read -rp " > " TerminalHeightChoice
if [[ ! $UserTerm || $TerminalHeightChoice == "q" ]]; then
sleep 0.6 ; exit
elif [[ $TerminalHeightChoice == "t" ]]; then
printf "\n Height selected = %s " "$Term_Taller"
MateTerminalProfile="$MateTerminalProfile_Taller"
GnomeTerminalProfile="$GnomeTerminalProfile_Taller"
XfceTerminalProfile="$XfceTerminalProfile_Taller"
KonsoleTerminalProfile="$KonsoleTerminalProfile_Taller"
elif [[ ! -e "$HOME/.qqX/qqX_term.conf" ]]; then
printf "\n Height selected = %s " "$Term_Height"
MateTerminalProfile="$MateTerminalProfile_Standard"
GnomeTerminalProfile="$GnomeTerminalProfile_Standard"
XfceTerminalProfile="$XfceTerminalProfile_Standard"
KonsoleTerminalProfile="$KonsoleTerminalProfile_Standard"
fi
SelectedTerminalProfile=
if [[ -e "$HOME/.qqX/qqX_term.conf" ]]; then
# allows for zero entry profiles having been written
GrepLine="$(eval grep -s CustomTerminalProfile "$HOME/.qqX/qqX_term.conf")"
[[ $GrepLine ]] && eval "$GrepLine"
SelectedTerminalProfile="$CustomTerminalProfile"
elif [[ $UserTerm == "mate-terminal" ]]; then SelectedTerminalProfile="$MateTerminalProfile"
elif [[ $UserTerm == "gnome-terminal" ]]; then SelectedTerminalProfile="$GnomeTerminalProfile"
elif [[ $UserTerm == "xfce4-terminal" ]]; then SelectedTerminalProfile="$XfceTerminalProfile"
elif [[ $UserTerm == "konsole" ]]; then
SelectedTerminalProfile="$KonsoleTerminalProfile"
fi
printf "\n"
# Select Icon colour (to go with text shade)
printf "\n\n Select Desktop icon/logo color "
printColor "\n\n [enter] standard yellow ICON"
tput setaf 6
printf " [b] alternative blue ICON"
tput sgr0
printf "\n\n Text color adjustments are found in the general settings file \n\n"
read -rp " > " IconSelect
if [[ $IconSelect == "b" ]]; then Icon_Var="blu"
else Icon_Var="std"; fi
## RUN .desktop CREATOR
if [[ ! $XDG_SESSION_DESKTOP ]] || [[ ! $XDG_CURRENT_DESKTOP ]] ; then
printColor "\n\n XDG desktop not fully set up or not found."
UserLand_Name="$(users)"
[[ ! $WSL_Install ]] && No_XDG=1
if [[ "$(whoami)" == root ]]; then printf "\n\n User-Interactive Scripts: Root installation adds complications ... \n\n Select a UserLand folder (%s) etc\n\n" "$UserLand_Name"
else printf "\n\n For menu links, only XDG desktop compliant OS's are supported. \n\n Running from CLI may be possible.\n\n"
fi
fi
if [[ ! $(type -p update-desktop-database) ]] || [[ $No_XDG ]] ; then
printColor "\n\n Incomplete XDG desktop installation. \n\n Check your distro repository for ""'""desktop-file-utils""'"" "
printColor "\n\n or see https://www.freedesktop.org/software/desktop-file-utils/releases/ \n\n"
read -rp " [q] to quit or [enter] to install traditional links only " Missing_XDG_Utils
[[ $Missing_XDG_Utils == "q" ]] && sleep 0.6 && exit
fi
if [[ ! -d "$XDG_GUI_desktop_Folder" ]] || [[ $No_XDG ]]; then
mkdir "$XDG_GUI_desktop_Folder" || printColor "\n\n ERROR making basic XDG folders \n\n"
fi
if [[ ! -d $XDG_GUI_desktop_Folder ]]; then
printColor "\n\n ERROR: The default XDG user desktop folder cannot be created or found\n\n See https://www.freedesktop.org/wiki/ \n\n"
fi
if [[ $No_XDG ]]; then
printColor "\n\n An XDG desktop cannot be found or cannot be set up. Type 'qqX' at the command line for starting.\n\n"
sleep 3 ; exit 1
else
## Add Icon to links: https://askubuntu.com/a/617311 https://people.gnome.org/~bmsmith/build/gosnautilus-203.html
#[Desktop Entry]
#Type=Link
#Name=qqX
#Icon=$HOME/.qqX/icons/qqX.std.logo.128.png
#URL=/usr/bin/qqX
# https://specifications.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html#icon_lookup # $HOME/.icons ?
# https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-1.1.html#recognized-keys
# https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-1.1.html#exec-variables
# https://wiki.archlinux.org/index.php/Desktop_entries#Validation & use folder .local/share/applications
# https://stackoverflow.com/questions/41516147/pass-filename-from-nautilus-to-shell-script#41517222
# & https://stackoverflow.com/questions/41516147/pass-filename-from-nautilus-to-shell-script#41517774
# Remove any old launcher file & create a new one
[[ -f "$XDG_GUI_desktop_PathName" ]] && sudo rm "$XDG_GUI_desktop_PathName"
# Plus remove any from pre qqX 1.9
if [[ -f "$HOME/.local/share/applications/qqX.desktop" ]]; then
rm "$HOME/.local/share/applications/qqX.desktop"
update-desktop-database "$HOME/.local/share/applications"
printColor "\n\n qqX desktop links have been moved, any pinned links may need re-pinning \n\n"
fi
# NoDisplay: means don't show in the main menu (Use =false)
# Use: Terminal=false (true means $TERM which is often a fallback mode 'xterm' )
make_desktop_content() {
echo "[Desktop Entry]"
echo "Type=Application"
echo "Terminal=false"
echo "Name=qqX Virtual Machine Manager"
echo "NoDisplay=false"
echo "Comment=qqX - quickemu quickget X terminal project"
# needs quotes - plus REVIEW -e deprecation in other terminals
if [[ "$SelectedTerminalProfile" == *'gnome-terminal'* ]]; then echo "Exec=$UserTerm $SelectedTerminalProfile -- " '"' "$qqX_Std_File_Path XDG %f" '"'
elif [[ $SelectedTerminalProfile ]]; then echo "Exec=$UserTerm $SelectedTerminalProfile -e " '"' "$qqX_Std_File_Path XDG %f" '"'
else echo "Exec=$UserTerm -e " '"' "$qqX_Std_File_Path XDG %f" '"'
fi
echo "Icon=$HOME/.qqX/icons/qqX.""$Icon_Var"".logo.128.png"
echo "Categories=System;Emulator"
# https://specifications.freedesktop.org/menu-spec/latest/apa.html#main-category-registry
# MimeType section used only for right click, open with, menu functions # one line, or causes errors
printf "MimeType=application/x-qemu-disk;application/x-cd-image;application/vnd.efi.iso\n"
echo "Keywords=qqX;qqx;qqX-Project;quickemu;quickget;qemu;kvm;KVM;qcow2;vm;VM;virt;;virtual-machine;emulator"
echo "#"
echo "#https://specifications.freedesktop.org/desktop-entry-spec/latest/"
}
make_desktop_content | sudo tee "$XDG_GUI_desktop_PathName" 1>/dev/null
sudo chmod +x "$XDG_GUI_desktop_PathName"
# Useful:
# xdg-mime query filetype "filename.ext" # xdg-mime query default "video/x-matroska" etc See: man xdg-mime >> examples
# desktop-file-validate qqX.desktop
# See https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-1.0.1.html
# Important:
sudo update-desktop-database "$XDG_GUI_desktop_Folder"
# https://wiki.archlinux.org/index.php/Desktop_entries#Installation
# REVIEW Different distros may have different setups.
fi
fi
## Read the .desktop file for Start_qqX as maybe Skippping MkLauncher
# Needs eg. Start_qqX="$UserTerm $CustomTerminalProfile -e $qqX_Std_File_Path XDG "
Start_qqX=
GrepExecLine="$(grep -s Exec "$XDG_GUI_desktop_Folder/qqX.desktop")"
if [[ $GrepExecLine ]]; then GrepExecLine="${GrepExecLine/'Exec='/}" ; Start_qqX="${GrepExecLine/'%f'/}" ; fi
End_Install=
printColor "\n\n Install process finished: "
printf "\n\n\n Start qqX straight from the system's MAIN MENU,"
printf "\n by typing 'qqX' the terminal, or by mouse clicks on VM or ISO files ..."
printf "\n\n Start qqX to edit the settings file, or before starting"
printf "\n at %s \n\n\n" "$HOME/.qqX/qqX_settings"
if [[ $UserTerm == "qterminal" ]]; then
printColor "\n\n LXQT 'qterminal' does not have size commands BUT it may be resized quite easily \n\n and should remember its sizes between uses."
fi
[[ $Start_qqX ]] && printColor " [enter] to close current window and start"
printf " [q] to quit \n\n "
read -rp " > " End_Install
# Typically KDE and when 'run in konsole' started from Dolphin. Or when Bash has been started by a Fish Shell session etc ...
# See https://askubuntu.com/questions/19397/is-there-a-command-to-close-a-terminal-window-via-commandline
# And https://superuser.com/questions/178587/how-do-i-detach-a-process-from-terminal-entirely
# https://github.com/jinliu/kdotool https://github.com/ReimuNotMoe/ydotool
# Probably easier just to put a message up than mess around with dependencies .... REVIEW
printColor "\n\n Auto-closure of this script may not happen in some desktop environments ... "
if [[ $End_Install == "q" ]]; then exit ; fi
if [[ $Start_qqX ]]; then
printf "\n\n If this window stays open, then keep it open until qqX is no longer running.\n\n"
if [[ $UserTerm == "konsole" || "$(pgrep konsole)" ]]; then
sleep 2
eval "$Start_qqX"
read -rp " > "
exit
else
exec bash -c "$Start_qqX"
fi
else
exit
fi
# This script is based on ffX - the ff(mpeg) X-terminal project - AV processing scripts for ffmpeg
# Also copyright (c) Alex Genovese https://github.com/TuxVinyards https://github.com/theffxproject