/
APP-MANAGER
executable file
·764 lines (692 loc) · 23.3 KB
/
APP-MANAGER
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
#!/usr/bin/env bash
AMVERSION="6.8.3-1"
# Determine main repository and branch
AMREPO="https://raw.githubusercontent.com/ivan-hc/AM/main"
AMBRANCH=$(basename "$AMREPO")
# Determine the name of this script and its working directory
DIR="$( cd "$( dirname "$0" )" && pwd )"
CLI=$(basename "$0")
# Determine system architecture and current user
arch="$HOSTTYPE"
export currentuser="$USER"
# XDG Variables
DATADIR="${XDG_DATA_HOME:-$HOME/.local/share}"
CONFIGDIR="${XDG_CONFIG_HOME:-$HOME/.config}"
CACHEDIR="${XDG_CACHE_HOME:-$HOME/.cache}"
APPMANCONFIG="$CONFIGDIR/appman"
export SCRIPTDIR="$(if command -v xdg-user-dir &>/dev/null; then xdg-user-dir DESKTOP; else echo $HOME; fi)"
# Determine sytem package manager
function _system_package_manager_check() {
for cmd in dnf pacman emerge zypper apt-get apk; do
if command -v $cmd &> /dev/null; then
osPKGman="$cmd"
return
fi
done
osPKGman=""
}
# Colors
RED='\033[0;31m'; LightBlue='\033[1;34m'; Green='\033[0;32m'
# Prevent the use of "sudo" ("AM")
function _no_sudo() {
if [ -n "$SUDO_COMMAND" ]; then
printf '\n Please do not use "sudo" to execute "'"$CLI"'", try again.\n\n'
exit 1
fi
}
_no_sudo
#####################
# "AM" CORE VARIABLES
#####################
function _am() {
AMCLI="am"
AMCLIPATH="$AMCLI"
SUDOCOMMAND="sudo"
COMPLETIONPATH="/etc/bash_completion.d"
COMPLETIONFILE="am-completion.sh"
APPSPATH="/opt"
AMPATH="$APPSPATH/$AMCLI"
mkdir -p "$AMPATH"/.cache
mkdir -p "$AMPATH"/modules
}
#######################################
# "APPMAN" CORE VARIABLES AND FUNCTIONS
#######################################
function _patch_bashrc_and_profile() {
# Fix order in "echo $PATH" in case "$HOME/.local/bin" is placed at the beginning instead of the end
# Check if the custom PATH is not already in .bashrc, then append it (fix - exclamation mark negates the entire command substitution)
if test -f "$HOME/.bashrc"; then
if ! grep -q 'export PATH=$PATH:$HOME/.local/bin' "$HOME/.bashrc"; then
echo 'export PATH=$(echo $PATH | tr ":" "\n" | grep -v "/.local/bin" | tr "\n" ":" | sed ''s/.$//'')' >> "$HOME/.bashrc"
echo -e 'export PATH=$PATH:$HOME/.local/bin\n' >> "$HOME/.bashrc"
fi
fi
# Correct the order of .local/bin in .profile if necessary
if test -f "$HOME/.profile"; then
if grep -q 'PATH="$HOME/.local/bin:$PATH"' "$HOME/.profile"; then
sed -i 's#PATH="$HOME/.local/bin:$PATH"#PATH="$PATH:$HOME/.local/bin"#g' "$HOME/.profile"
fi
elif test -f "$HOME/.bash_profile"; then
if grep -q 'PATH="$HOME/.local/bin:$PATH"' "$HOME/.bash_profile"; then
sed -i 's#PATH="$HOME/.local/bin:$PATH"#PATH="$PATH:$HOME/.local/bin"#g' "$HOME/.bash_profile"
fi
fi
}
function _appman_initialize() {
APPSDIR=$1
mkdir -p ~/"$APPSDIR"/appman/.cache
mkdir -p ~/"$APPSDIR"/appman/modules
mkdir -p ~/.local/bin "$DATADIR"/applications "$DATADIR"/icons
AMCLI="appman"
AMCLIPATH="$DIR/$AMCLI"
SUDOCOMMAND=""
COMPLETIONPATH="$HOME"
COMPLETIONFILE=".bash_completion"
APPSPATH="$HOME/$APPSDIR"
AMPATH="$HOME/$APPSDIR/$AMCLI"
}
function _appman_prompt_for_directory() {
local location
read -r -ep "Please, write the name or the path of your custom application's folder: $(echo -e '\n\n '$HOME'/')" location
echo "$location"
}
function _appman_validate_directory() {
local location=$1
if [[ "$location" == "" ]]; then
echo -e "--------------------------------------------------------------------------"
echo "OPERATION ABORTED!"
exit 1
elif [[ "$location" == ".local/bin" ]]; then
echo -e "--------------------------------------------------------------------------\n"
echo -e " 💀 ERROR, you can't install applications into a '$PATH'\n\n The directory ~/.local/bin and 'bin' folders are used for executables.\n\n Please, choose a different path and retry! \n"
echo -e "--------------------------------------------------------------------------\n"
exit 1
else
local location_appman="${location/#$HOME}"
location_appman="${location_appman// /-}"
location_appman="${location_appman#/}"
location_appman="${location_appman%/}"
echo "$location_appman"
fi
}
function _appman() {
if [[ ! -f "$APPMANCONFIG"/appman-config ]]; then
echo "--------------------------------------------------------------------------"
echo " >>> Thank you for choosing AppMan!"
echo "--------------------------------------------------------------------------"
echo "Before proceeding with any task, write the name of the directory in which"
echo 'you will install the apps, for example "Programs" or "My-apps", you can '
echo 'also choose a subfolder, for example ".local/My-apps" or a deeper path.'
echo -e "\nThe destination folder will be created in $HOME"
echo -e "\nSYNTAX: PATH/TO/DIRNAME\n"
echo 'NOTE, any spaces or "/" at the beginning and end will be removed. If you '
echo 'decide to change your choice in the future, first remove all the programs'
echo 'and then edit the ~/.config/appman/appman-config text file.'
echo -e "--------------------------------------------------------------------------\n"
local location=$(_appman_prompt_for_directory)
local validated_location=$(_appman_validate_directory "$location")
mkdir -p "$APPMANCONFIG"
echo "$validated_location" >> "$APPMANCONFIG"/appman-config
echo '--------------------------------------------------------------------------'
echo 'You are ready! Start installing your favorite apps locally!!'
echo "All apps will be installed in $HOME/$validated_location"
echo -e '\nIn case of problems, use the option "-h".'
echo '--------------------------------------------------------------------------'
fi
_appman_initialize "$(<"$APPMANCONFIG"/appman-config)"
_patch_bashrc_and_profile
}
########################################
# DETERMINE WHEN TO USE "AM" OR "APPMAN"
########################################
if [[ "$DIR/$CLI" == "/usr/local/bin/am" ]] 2>/dev/null; then
_am
else
_appman
fi
# Set header authorization if GitHub API key file exists
[ -f "$AMPATH/ghapikey.txt" ] && HeaderAuthWithGITPAT=" --header \"Authorization: token $(<"$AMPATH/ghapikey.txt")\" "
################
# DEVELOPER MODE
################
if test -f "$AMPATH"/betatester; then
AMREPO="https://raw.githubusercontent.com/ivan-hc/AM/dev"
AMBRANCH=$(basename "$AMREPO")
fi
function _betatester_message_on() {
if test -f "$AMPATH"/betatester; then
echo '--------------------------------------------------------------------------'
echo "\"$AMCLI\" $AMVERSION: developer mode" | tr a-z A-Z
echo '--------------------------------------------------------------------------'
fi
}
function _use_betatester_on() {
touch "$AMPATH"/betatester
}
function _use_betatester_off() {
rm -f "$AMPATH"/betatester
}
###############################
# DOWNLOAD PORTABLE DEPENDENCES
###############################
function _jq_installer() {
if ! command -v jq 1>/dev/null; then
_system_package_manager_check
if [[ -z "$osPKGman" ]];then
echo -e " ${RED}💀 ERROR!\033[0m Missing essential command ${Green}jq\033[0m\n"
read -p " Do you wish to install it using $AMCLI (Y,n)? " yn
case $yn in
'N'|'n')
echo -e "\n The \"jq\" command is essential for parsing JSON files on sites"
echo " for example api.github.com, to list the URLs of apps to download."
echo -e " You need to install it at least via your package manager to use \"$AMCLI\".\n\n Missing essential command ${RED}jq\033[0m, aborted!"; exit
;;
'Y'|'y'|*)
rm -f "$AMPATH"/.cache/*
echo ""
source "$AMPATH"/modules/install.am -i jq 2>&1 | grep "INSTALLED"
echo ""
;;
esac
else
echo -e " ${RED}💀 ERROR!\033[0m Missing essential command ${Green}jq\033[0m\n"
echo " Install it from your system package manager and retry!"; exit
fi
fi
}
function _portable_dependences_setup() {
_jq_installer
}
###########################################
# FUNCTIONS RELATED TO THE SAFE USE OF "AM"
###########################################
function _am_dependences_check() {
# Check for essential commands required by the application
missing_deps=()
AMDEPENDENCES="cat chmod chown curl grep sed wget"
for name in $AMDEPENDENCES; do
if ! command -v "$name" &>/dev/null; then
missing_deps+=("$name")
fi
done
# Exit if any essential command is missing
if [ -n "$missing_deps" ]; then
echo '--------------------------------------------------------------------------'
printf " ${RED}💀 ERROR! MISSING ESSENTIAL COMMANDS\033[0m: %s\n\n Install the above and try again! \n" "${missing_deps[*]}"
echo '--------------------------------------------------------------------------'
echo -e "\n ${Green}List of the $(echo "$AMCLI" | tr a-z A-Z) $AMVERSION core dependences\033[0m:\n"
echo $AMDEPENDENCES | tr ' ' ',' | sed 's/,/, /g' | sed 's/^/ /g'
echo -e '\n--------------------------------------------------------------------------'
echo " If this message appears it is because you are missing some dependency"
echo " and if its the first time its because something new has been introduced."
echo -e "\n See ${LightBlue}https://github.com/ivan-hc/AM#dependences\033[0m for more information"
echo '--------------------------------------------------------------------------'
exit 1
fi
}
function _am_security_check() {
_am_dependences_check
# Check and create the $AMPATH directory if it does not exist
if [ ! -d "$AMPATH" ]; then
$SUDOCOMMAND mkdir -p "$AMPATH"
fi
}
# Function to check online connections (uses github.com by default, as the database and CLI itself are stored/hosted there)
function _online_check() {
if ! wget -q --tries=10 --timeout=20 --spider https://github.com; then
echo -e "\n $AMCLI is offline, please check your internet connection and try again\n"
exit
fi
}
#######################
# SECURE INSTALLED APPS
#######################
function _prevent_apps_from_being_removed_by_third_parties() {
# Add a security layer to scripts named "remove" of installed apps to prevent file removal by non-privileged users
if [ $AMCLI == am ] 2>/dev/null; then
if ! grep -q '"$SUDO_COMMAND"' /opt/*/remove 2> /dev/null; then
for r in /opt/*/; do
if test -f $r/remove; then
sed -i '1 a if [ -z "$SUDO_COMMAND" ]; then echo "Permission denied"; exit 1; fi' $r/remove 2> /dev/null
fi
done
fi
fi
}
###########################################
# FUNCTIONS RELATED TO THE DATABASE OF APPS
###########################################
function _am_newrepo_check() {
# Determine if the CLI uses the "main" branch of https://github.com/ivan-hc/AM or an alternative one
if [[ -f "$AMPATH"/new-repo.txt ]]; then
AMREPO=$(<"$AMPATH/new-repo.txt") # Utilizing command substitution with < for more efficient file reading
export AMBRANCH=$(basename "$AMREPO")
export APPSDB="$AMREPO/programs/$arch"
export APPSLISTDB="$AMREPO/programs/$arch-apps"
export LIBSLISTDB="$AMREPO/programs/libs-list"
if [[ "$*" != "newrepo off" ]]; then
echo '--------------------------------------------------------------------------'
echo " Source: $AMREPO"
echo '--------------------------------------------------------------------------'
fi
else
export APPSDB="$AMREPO/programs/$arch"
export APPSLISTDB="$AMREPO/programs/$arch-apps"
export LIBSLISTDB="$AMREPO/programs/libs-list"
fi
}
function _am_databases_check() {
# Determine catalogue in use
export AMCATALOGUEMARKDOWNS="https://raw.githubusercontent.com/Portable-Linux-Apps/Portable-Linux-Apps.github.io/main/apps"
export AMCATALOGUEICONS="https://raw.githubusercontent.com/Portable-Linux-Apps/Portable-Linux-Apps.github.io/main/icons"
_am_newrepo_check
# To implement future application database changes
if [ -f "$AMPATH/neodb" ]; then
if grep -q "://" "$AMPATH/neodb"; then
if grep -q "#STATUS=quiet" "$AMPATH/neodb"; then
case "$1" in
'-a'|'about'|'-d'|'download'|'-i'|'install'|'-l'|'list'|'-q'|'query')
echo '--------------------------------------------------------------------------'
echo " Source: Third party repositories are enabled"
echo '--------------------------------------------------------------------------'
;;
esac
fi
fi
fi
}
#####################################
# CHECK VERSION OF THE INSTALLED APPS
#####################################
function _check_version_if_any_version_reference_is_somewhere() {
APPVERSION=$(grep -i "version=" $APPSPATH/$arg/* 2>/dev/null | grep -Eo "([0-9]{1,}\.)+[0-9]{1,}" | head -1)
}
function _check_version_if_zsync_file_exists() {
APPVERSION=$(strings -d ./$arg/*.zsync | grep -i "$(echo $arg | sed 's/-appimage//g')" | grep -Eo "([0-9]{1,}\.)+[0-9]{1,}" | head -1)
}
function _check_version_if_version_file_exists() {
APPVERSION=$(cat $APPSPATH/$arg/version | head -1 | grep -Eo "([0-9]{1,}\.)+[0-9]{1,}" | head -1)
if [ -z "$APPVERSION" ]; then
if grep -q -- "-$arch/" ./$arg/version; then
ALPHANUMERICTEST=$(cat $APPSPATH/$arg/version | tr '-' '\n' | grep -vi "appimage\|$arg\|$arch" | tail -1)
if ! [[ "$ALPHANUMERICTEST" =~ [^a-zA-Z0-9] ]]; then
APPVERSION="$ALPHANUMERICTEST"
fi
elif ! sed "s/$arch//g" $APPSPATH/$arg/version | grep -q "[0-9]"; then
if grep -qi "/continuous/" $APPSPATH/$arg/version 2>/dev/null; then
APPVERSION="continuous"
fi
else
APPVERSION=$(cat $APPSPATH/$arg/version | sed 's:.*/::' | tr '-' '\n' | tr '_' '\n' | grep -vi "appimage\|$arg\|$arch\|amd64" | grep "[0-9]" | head -1)
fi
fi
}
function _check_version_if_an_updater_exists() {
APPVERSION=$($APPSPATH/$arg/updater -d $APPSPATH/$arg/$arg 2>/dev/null | grep -i $arg | grep -Eo "([0-9]{1,}\.)+[0-9]{1,}" | head -1)
if [ -z "$APPVERSION" ]; then
_check_version_if_any_version_reference_is_somewhere
fi
}
function _check_version_if_amcli() {
APPVERSION="$AMVERSION"
}
function _check_version_if_firefox_webapp() {
APPVERSION="WebApp"
}
function _check_version_if_library() {
APPVERSION=$(strings -d $(cat $APPSPATH/$arg/remove | tr ' ' '\n' | grep "usr/local/lib") | grep -Eo "([0-9]{1,}\.)+[0-9]{1,}" | tail -1)
}
function _check_version_if_no_version_found() {
APPVERSION="unknown"
}
function _check_version() {
rm -f "$AMPATH"/.cache/version-args
cd "$APPSPATH" &&
INSTALLED_APPS=$(find -name 'remove' -printf "%h\n" 2>/dev/null | du -sh -- * 2> /dev/null | sort -rh | sed 's@.* @@')
for arg in $INSTALLED_APPS; do
if test -f ./$arg/remove 2>/dev/null; then
if test -f ./$arg/*.zsync 2>/dev/null; then
_check_version_if_zsync_file_exists
elif test -f ./$arg/version 2>/dev/null; then
_check_version_if_version_file_exists
elif test -f ./$arg/updater 2>/dev/null; then
_check_version_if_an_updater_exists
elif [ "$arg" == "$AMCLI" ]; then
_check_version_if_amcli
elif grep -qi "version=" ./$arg/* 2>/dev/null; then
_check_version_if_any_version_reference_is_somewhere
elif echo "$arg" | grep -q "ffwa-"; then
_check_version_if_firefox_webapp
elif cat "$APPSPATH"/$arg/remove 2> /dev/null | grep -q "usr/local/lib"; then
_check_version_if_library
else
_check_version_if_no_version_found
fi
if [ -z "$APPVERSION" ]; then
_check_version_if_no_version_found
fi
echo " ◆ $arg | $APPVERSION" >> "$AMPATH"/.cache/version-args
fi
done
}
function _check_version_for_auto_updatable_apps() {
cd "$APPSPATH" &&
INSTALLED_APPS=$(find -name 'remove' -printf "%h\n" 2>/dev/null | du -sh -- * 2> /dev/null | sort -rh | sed 's@.* @@')
for arg in $INSTALLED_APPS; do
if test -f ./$arg/updater 2>/dev/null; then
if [ -z "$(strings -d "./$arg/$arg" 2>/dev/null | grep -F 'appimage')" ] 2>/dev/null; then
_check_version_if_an_updater_exists
OLDAPPVERSION=$(cat "$AMPATH"/.cache/version-args | grep " ◆ $arg |" | tr '|' '\n' | sed 's/ //g' | head -2 | tail -1)
sed -i "/ ◆ $arg |/s#$OLDAPPVERSION#$APPVERSION#" "$AMPATH"/.cache/*
fi
fi
done
}
if test -f "$AMPATH"/.cache/version-args; then
_check_version_for_auto_updatable_apps
fi
function _remove_info_files() {
rm -f "$AMPATH"/.cache/files-args*
rm -f "$AMPATH"/.cache/version-args
}
###################################################################################
# FUNCTIONS RELATED TO INTERNAL OPTIONS TO ENABLE/DISABLE BASH (AND ZSH) COMPLETION
###################################################################################
function _use_disable-completion() {
if [ "$(grep -o "$AMCLI" 0<"$COMPLETIONPATH/$COMPLETIONFILE" | head -1)" == "$AMCLI" ]; then
grep -v 'complete -W "$(cat '"$AMPATH"'/list 2>/dev/null)" '"$AMCLI"'' "$COMPLETIONPATH/$COMPLETIONFILE" > "$AMPATH"/$COMPLETIONFILE.backup &&
$SUDOCOMMAND mv "$AMPATH"/$COMPLETIONFILE.backup "$COMPLETIONPATH/$COMPLETIONFILE"
echo " Completion disabled! "
else
echo " Completion script is NOT enabled! "
fi
}
function _use_enable_completion() {
if [ "$(grep -o "$AMCLI" 0<"$COMPLETIONPATH/$COMPLETIONFILE" | head -1)" == "$AMCLI" ]; then
echo " Completion script is already enabled!"
else
$SUDOCOMMAND mkdir -p "$COMPLETIONPATH"
if [ "$AMCLI" == appman ]; then
if ! test -f "$COMPLETIONPATH/$COMPLETIONFILE"; then
echo '#!/usr/bin/env bash' >> "$COMPLETIONFILE"
fi
else
echo '#!/usr/bin/env bash' >> "$COMPLETIONFILE"
fi
echo 'complete -W "$(cat '"$AMPATH"'/list 2>/dev/null)" '"$AMCLI"'' >> "$COMPLETIONFILE"
chmod a+x "$COMPLETIONFILE"
$SUDOCOMMAND mv "$COMPLETIONFILE" "$COMPLETIONPATH/" 2> /dev/null
echo " Completion has been enabled!"
fi
if [ -f "$HOME/.zshrc" ] || [ -f "$ZDOTDIR/.zshrc" ]; then
if [ -n "$ZDOTDIR" ]; then
ZSHDIR="$ZDOTDIR"
else
ZSHDIR="$HOME"
fi
if grep -q "source $ZSHDIR/$COMPLETIONFILE" "$ZSHDIR/.zshrc"; then
echo "Zsh completion already enabled!"
else
echo '#!/usr/bin/env bash' >> "$ZSHDIR/$COMPLETIONFILE"
echo 'complete -W "$(cat '"$AMPATH"'/list 2>/dev/null)" '"$AMCLI"'' >> "$ZSHDIR/$COMPLETIONFILE"
chmod a+x "$ZSHDIR/$COMPLETIONFILE"
echo -e "\nautoload bashcompinit\nbashcompinit\nsource $ZSHDIR/$COMPLETIONFILE" >> "$ZSHDIR/.zshrc"
fi
fi
}
# Generate a list of words to use in bash completion
rm -rf "$AMPATH/options"
cat <<-HEREDOC >> "$AMPATH/options"
about
apikey
backup
clean
download
files
install
list
lock
neodb
newrepo
nolibfuse
overwrite
query
remove
sync
template
test
unlock
update
web
--apps
--byname
--convert
--debug
--devmode-disable
--devmode-enable
--disable-completion
--enable-completion
--firejail
--force-latest
--home
--launcher
--less
--rollback
--sandbox
--silent
--system
--user
HEREDOC
function _completion_lists() {
# Remove existing lists and download new ones
rm -Rf "$AMPATH"/{$arch-apps,list,libs-list} &&
wget -q "$APPSLISTDB" -P "$AMPATH" &&
wget -q "$LIBSLISTDB" -P "$AMPATH"
# THIRD PARTY APPS
if test -f "$AMPATH/neodb"; then
rm -R -f "$AMPATH/.cache/multirepo-args"
MULTIREPO=$(cat "$AMPATH/neodb" | grep "List=" | grep -E "$arch-apps" | sed 's/List=//g')
for anyrepo in $MULTIREPO; do
if curl --output /dev/null --silent --head --fail "$anyrepo" 1>/dev/null; then
wget -q "$anyrepo" -O - | grep "◆" >> "$AMPATH"/$arch-apps
fi
done
cat "$AMPATH"/$arch-apps | sort | uniq > "$AMPATH"/$arch-apps-backup
rm -R -f "$AMPATH"/$arch-apps
mv "$AMPATH"/$arch-apps-backup "$AMPATH"/$arch-apps
fi
# Extract and append program and library names to the list
for file in $arch-apps libs-list; do
awk -v FS="(◆ | : )" '{print $2}' <$AMPATH/$file >> $AMPATH/list
done
# Append options to the list
cat "$AMPATH"/options >> "$AMPATH"/list
}
#############################################
# OTHER FUNCTIONS RELATED TO INTERNAL OPTIONS
#############################################
# Function for the option "appman" or "--user" that helps "AM" function like "AppMan"
function _appman_mode_enabled_message() {
if [ "$CLI" == am ] 2>/dev/null; then
echo '--------------------------------------------------------------------------'
#echo " \"AppMan Mode\" enabled!" | tr a-z A-Z
echo -e " \"AM\" is running as \"AppMan\", use ${Green}am --system\033[0m to switch it back to \"AM\""
echo '--------------------------------------------------------------------------'
fi
}
function _if_appman_mode_enabled() {
if [ "$CLI" == am ]; then
if test -f "$APPMANCONFIG"/appman-mode; then
_appman_mode_enabled_message
fi
fi
}
function _use_appman() {
_online_check
if [ "$CLI" == appman ] 2>/dev/null; then
echo " This function only works for AM"
exit
fi
if test -f "$APPMANCONFIG"/appman-mode; then
_appman
_appman_mode_enabled_message
else
mkdir -p "$APPMANCONFIG"
touch "$APPMANCONFIG"/appman-mode
_appman
_appman_mode_enabled_message
fi
}
function _back_to_am() {
if test -f "$APPMANCONFIG"/appman-mode; then
rm -f "$APPMANCONFIG"/appman-mode
echo '--------------------------------------------------------------------------'
echo " \"AppMan Mode\" disabled!" | tr a-z A-Z
echo '--------------------------------------------------------------------------'
fi
}
if [ "$AMCLI" == am ] 2>/dev/null; then
if test -f "$APPMANCONFIG"/appman-mode; then
case "$1" in
'--system')
_back_to_am
;;
''|*)
if ! test -f "$APPMANCONFIG"/appman-config; then
_appman_mode_enabled_message
fi
_appman
AMCLIPATH="/opt/am/APP-MANAGER"
;;
esac
fi
fi
#############################################
# FUNCTION TO HANDLE ALL THE EXTERNAL MODULES
#############################################
function _use_module() {
# Test if module exists
if ! test -f "$AMPATH/modules/$MODULE"; then
wget -q "$AMREPO/modules/$MODULE" -O "$AMPATH/modules/$MODULE"
chmod a+x "$AMPATH/modules/$MODULE"
fi
# Source module
source "$AMPATH/modules/$MODULE" "$@"
}
_am_security_check
_prevent_apps_from_being_removed_by_third_parties 2> /dev/null
_am_databases_check
case "$1" in
'')
echo -e "\n USAGE: '$AMCLI [option]'\n '$AMCLI [option] [argument]'\n\n Run the '$AMCLI -h' command to find out more\n"
;;
# OPTIONS BASED ON EXTERNAL MODULES
'-a'|'about'|'-l'|'list'|'-q'|'query')
MODULE="database.am"
_if_appman_mode_enabled
_use_module "$@"
;;
'-b'|'backup'|'-o'|'overwrite'|'lock'|'unlock')
MODULE="no-updates.am"
_use_module "$@"
;;
'-c'|'clean')
MODULE="clean.am"
_use_module
;;
'-d'|'download')
MODULE="download.am"
_online_check
_use_module "$@"
;;
'-f'|'files')
MODULE="files.am"
_if_appman_mode_enabled
_use_module "$@"
_betatester_message_on
;;
'-h'|'help')
MODULE="help.am"
_if_appman_mode_enabled
_use_module "$@"
;;
'-H'|'--home'|'--firejail'|'--sandbox')
MODULE="sandboxes.am"
_use_module "$@"
;;
'-i'|'install')
MODULE="install.am"
_online_check
_if_appman_mode_enabled
_betatester_message_on
_portable_dependences_setup
_use_module "$@"
;;
'-R'|'-r'|'remove')
MODULE="remove.am"
_use_module "$@"
;;
'-s'|'sync')
MODULE="sync.am"
_online_check
_betatester_message_on
_use_module "$@"
;;
'-t'|'template')
MODULE="template.am"
_online_check
_use_module "$@"
;;
'-u'|'-U'|'update'|'--force-latest')
MODULE="update.am"
_online_check
_portable_dependences_setup
_use_module "$@"
;;
'--launcher')
MODULE="launcher.am"
_use_module "$@"
;;
'--rollback')
MODULE="rollback.am"
_online_check
_use_module "$@"
;;
'neodb'|'apikey'|'newrepo')
MODULE="devtools.am"
_online_check
_use_module "$@"
;;
'nolibfuse')
MODULE="nolibfuse.am"
_online_check
_use_module "$@"
;;
# INBUILT OPTIONS
'--devmode-disable')
_use_betatester_off
;;
'--devmode-enable')
_use_betatester_on
_betatester_message_on
;;
'--disable-completion')
_use_disable-completion
;;
'--enable-completion')
_use_enable_completion
;;
'--system')
_back_to_am
;;
'--user'|'appman')
_use_appman
;;
'version'|'-v'|'--version')
echo "$AMVERSION"
;;
*)
exec "$AMCLIPATH"
;;
esac
# vim:tabstop=4:shiftwidth=4:expandtab