Skip to content

Commit 7fb4322

Browse files
authored
Merge pull request #571 from ivan-hc/dev
Easily switch from "AM" to "AppMan" and back to "AM"
2 parents 1bf42fd + e95be3f commit 7fb4322

File tree

8 files changed

+154
-28
lines changed

8 files changed

+154
-28
lines changed

APP-MANAGER

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
AMVERSION="6.7.1"
3+
AMVERSION="6.8"
44

55
# Determine main repository and branch
66
AMREPO="https://raw.githubusercontent.com/ivan-hc/AM/main"
@@ -476,6 +476,7 @@ cat <<-HEREDOC >> "$AMPATH/options"
476476
--rollback
477477
--sandbox
478478
--silent
479+
--system
479480
--user
480481
HEREDOC
481482

@@ -512,20 +513,53 @@ function _completion_lists() {
512513
# OTHER FUNCTIONS RELATED TO INTERNAL OPTIONS
513514
#############################################
514515

515-
# Function for the option "appman" or "--user" that helps "AM" function like "AppMan", via alias
516+
# Function for the option "appman" or "--user" that helps "AM" function like "AppMan"
517+
function _appman_mode_enabled_message() {
518+
if [ "$CLI" == am ] 2>/dev/null; then
519+
echo '--------------------------------------------------------------------------'
520+
#echo " \"AppMan Mode\" enabled!" | tr a-z A-Z
521+
echo -e " \"AM\" is running as \"AppMan\", use ${Green}am --system\033[0m to switch it back to \"AM\""
522+
echo '--------------------------------------------------------------------------'
523+
fi
524+
}
525+
526+
function _if_appman_mode_enabled() {
527+
if [ "$CLI" == am ]; then
528+
if test -f "$APPMANCONFIG"/appman-mode; then
529+
_appman_mode_enabled_message
530+
fi
531+
fi
532+
}
533+
516534
function _use_appman() {
517535
_online_check
518-
if [ "$AMCLI" == appman ] 2>/dev/null; then
536+
if [ "$CLI" == appman ] 2>/dev/null; then
519537
echo " This function only works for AM"
520538
exit
521539
fi
522-
if test -f /opt/am/appman; then
540+
if test -f "$APPMANCONFIG"/appman-mode; then
523541
_appman
524-
echo -e "Please run '${RED}alias am=/opt/am/appman\033[0m' to made 'AM' act exactly like 'AppMan' for\nthe current session or save this command to your '"'~/.bashrc'"' file to make the\nchanges permanent. Visit ${LightBlue}https://github.com/ivan-hc/appman\033[0m for more!"
542+
_appman_mode_enabled_message
525543
else
544+
touch "$APPMANCONFIG"/appman-mode
526545
_appman
527-
wget -q "$AMREPO"/APP-MANAGER -O /opt/am/appman && chmod a+x /opt/am/appman
528-
echo -e "Please run '${RED}alias am=/opt/am/appman\033[0m' to made 'AM' act exactly like 'AppMan' for\nthe current session or save this command to your '"'~/.bashrc'"' file to make the\nchanges permanent."
546+
_appman_mode_enabled_message
547+
fi
548+
}
549+
550+
if [ "$AMCLI" == am ] 2>/dev/null; then
551+
if test -f "$APPMANCONFIG"/appman-mode; then
552+
_appman
553+
AMCLIPATH="/opt/am/APP-MANAGER"
554+
fi
555+
fi
556+
557+
function _back_to_am() {
558+
if test -f "$APPMANCONFIG"/appman-mode; then
559+
rm -f "$APPMANCONFIG"/appman-mode
560+
echo '--------------------------------------------------------------------------'
561+
echo " \"AppMan Mode\" disabled!" | tr a-z A-Z
562+
echo '--------------------------------------------------------------------------'
529563
fi
530564
}
531565

@@ -554,6 +588,7 @@ case "$1" in
554588
# OPTIONS BASED ON EXTERNAL MODULES
555589
'-a'|'about'|'-l'|'list'|'-q'|'query')
556590
MODULE="database.am"
591+
_if_appman_mode_enabled
557592
_use_module "$@"
558593
;;
559594
'-b'|'backup'|'-o'|'overwrite'|'lock'|'unlock')
@@ -571,11 +606,13 @@ case "$1" in
571606
;;
572607
'-f'|'files')
573608
MODULE="files.am"
609+
_if_appman_mode_enabled
574610
_use_module "$@"
575611
_betatester_message_on
576612
;;
577613
'-h'|'help')
578614
MODULE="help.am"
615+
_if_appman_mode_enabled
579616
_use_module "$@"
580617
;;
581618
'-H'|'--home'|'--firejail'|'--sandbox')
@@ -585,6 +622,7 @@ case "$1" in
585622
'-i'|'install')
586623
MODULE="install.am"
587624
_online_check
625+
_if_appman_mode_enabled
588626
_betatester_message_on
589627
_portable_dependences_setup
590628
_use_module "$@"
@@ -643,6 +681,9 @@ case "$1" in
643681
'--enable-completion')
644682
_use_enable_completion
645683
;;
684+
'--system')
685+
_back_to_am
686+
;;
646687
'--user'|'appman')
647688
_use_appman
648689
;;

CONTRIBUTING.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ appman newrepo https://raw.githubusercontent.com/$USER/AM/dev
2929

3030
-----------------------------------------------
3131

32+
## Want to make code refactor?
33+
“AM” is provided as-is, and each line has been tested to work as it should, based on user feedback and needs, as well as the aesthetic and practical preferences of the developer who created it, who provided it to you, and who constantly maintains it to make it work at its best.
34+
35+
Unfortunately, many contributors in the past, by relying exclusively on the logic of software such as "Shellcheck", without first verifying that the code worked, have caused more harm than good, both to the software and to its main developer, who ended up having to rewrite everything from scratch, losing time, mental health and trust towards their collaborators who had committed the mess.
36+
37+
The priority of this project is only one: **"AM" must work and that's it!**
38+
39+
Not out of malice, but if you got here and you like "AM" and how it works, you liked the work that the main developer did for you.
40+
41+
If you intend to carry out a "sensible" refactoring that doesn't risk breaking everything as it has already happened, you are welcome. But at the slightest mistake, you will be rejected, no ifs or buts. You are warned. Further errors will no longer be tolerated in this project and will be seen as attempts at sabotage!
42+
43+
If you believe that something needs improvement, let us know, but it is better for the refactoring to be carried out by someone who already knows the commands he wrote. It is certainly the best way to prevent everything from breaking and avoid irreversible damage.
44+
45+
-----------------------------------------------
46+
3247
## Want to contribute to the Development Branch and test newer features?
3348
Enter the developer mode using the command
3449
```

README.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,15 @@ For everything else, the controls and operation are always the same for both com
121121
<details>
122122
<summary></summary>
123123

124-
If you usa "AM" and have the needing of installing apps at system level and locally, use the option `--user` that allows you to create an alias to install and manage apps in your $HOME folder. When executing the `am --user` command you will be suggested an alias to use temporarily or if you want you can add it in your ~/.bashrc to make it permanent. "AppMan" will be used while still using the usual `am` command.
125-
126-
The `--user` option does not immediately enable "AppMan Mode", instead it will show you an alias to use temporarily in the current session or to add to your ~/.bashrc to make it permanent:
124+
If you use "AM" and have the needing of installing apps at system level and locally, use the option `--user` that allows to run "AM" in "AppMan Mode":
125+
```
126+
am --user
127+
```
128+
To switch "AM" back to "AM" from "AppMan Mode", use the option `--system`:
127129
```
128-
alias am=/opt/am/appman
130+
am --system
129131
```
130-
AppMan is downloaded to the AM's installation folder, but without affecting the existing installation.
132+
To perform a test and see if you are in "AppMan Mode" or not, run for example the command `am -f` to see the list of the installed apps.
131133

132134
***NOTE: using AM with the `--user` option enabled and the alias for AppMan, "sudo" allows normal use of AM, absence allows use of AppMan.***
133135

@@ -605,7 +607,16 @@ to have a list of the installed programs use the option `-f` or `files` (syntax
605607
___________________________________________________________________________
606608

607609
## EXTRA OPTIONS
608-
___________________________________________________________________________
610+
__________________________________________________________________________
611+
612+
`--system`
613+
614+
SYNOPSIS:
615+
616+
`--system`
617+
618+
DESCRIPTION: Switch "AM" back to "AM" from "AppMan Mode" (see --user).
619+
__________________________________________________________________________
609620

610621
`--user`, `appman` (only available for "AM")
611622

modules/database.am

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,7 @@ case "$1" in
154154
_completion_lists
155155
fi
156156
ARGS=$(echo "$@" | sed 's/-q //')
157-
echo ""
158-
printf ' Search results for %s:' "$ARGS" | tr a-z A-Z
159-
echo ""
157+
echo -e "\n Search results for \"$ARGS\":\n" | tr a-z A-Z
160158
grep -i -E "$2" "$AMPATH/$arch-apps" | grep -i -E "$3" | grep -i -E "$4" | grep -i -E "$5" | grep -i -E "$6" | grep -i -E "$7" | grep -i -E "$8" | grep -i -E "$9" | _clean_lists_and_queries
161159
grep -i -E "$2" "$AMPATH/libs-list" | grep -i -E "$3" | grep -i -E "$4" | grep -i -E "$5" | grep -i -E "$6" | grep -i -E "$7" | grep -i -E "$8" | grep -i -E "$9" | _clean_lists_and_queries
162160
echo ""

modules/help.am

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,13 @@ function _help_body() {
329329
EXTRA OPTIONS
330330
__________________________________________________________________________
331331
332+
--system
333+
334+
SYNOPSIS: --system
335+
336+
DESCRIPTION: Switch "AM" back to "AM" from "AppMan Mode" (see --user).
337+
__________________________________________________________________________
338+
332339
--user, appman ( only works with "AM" )
333340
334341
SYNOPSIS: --user

modules/sync.am

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,24 @@ fi
6767
function _sync_amcli() {
6868
echo "-----------------------------------------------------------------------------"
6969
_completion_lists
70-
CURRENT_AM_VERSION=$($AMCLIPATH -v)
71-
echo -ne '\n ◆ SYNCHRONIZING "'"$(echo $AMCLI | tr a-z A-Z)"'" VERSION '"$CURRENT_AM_VERSION"'...\r'; sleep 1
72-
rm -R -f $AMPATH/.cache/* 1>/dev/null; cd $AMPATH/.cache || return
73-
if [ $AMCLI == am ] 2>/dev/null; then
74-
wget -q $AMREPO/APP-MANAGER && chmod a+x ./APP-MANAGER
70+
CURRENT_AM_VERSION=$("$AMCLIPATH" -v)
71+
echo -ne '\n ◆ SYNCHRONIZING "'"$(echo "$AMCLI" | tr a-z A-Z)"'" VERSION '"$CURRENT_AM_VERSION"'...\r'; sleep 1
72+
rm -R -f "$AMPATH"/.cache/* 1>/dev/null; cd "$AMPATH"/.cache || return
73+
if [ "$CLI" == am ] 2>/dev/null; then
74+
wget -q "$AMREPO"/APP-MANAGER && chmod a+x ./APP-MANAGER
7575
cd ..
76-
mv $AMPATH/.cache/APP-MANAGER $AMPATH; chmod 777 $AMPATH
76+
mv "$AMPATH"/.cache/APP-MANAGER /opt/am/APP-MANAGER; chmod 777 "$AMPATH"
7777
else
78-
wget -q $AMREPO/APP-MANAGER -O appman && chmod a+x ./$AMCLI
78+
wget -q "$AMREPO"/APP-MANAGER -O appman && chmod a+x ./"$AMCLI"
7979
cd ..
80-
mv $AMPATH/.cache/$AMCLI $AMCLIPATH
80+
mv "$AMPATH"/.cache/"$AMCLI" "$AMCLIPATH"
8181
fi
82-
if [ ! "$CURRENT_AM_VERSION" == "$($AMCLIPATH -v)" ] ; then
83-
echo -ne ' A new release of "'"$(echo $AMCLI | tr a-z A-Z)"'" is available, please wait...\r'
84-
echo -e ' ◆ "'"$(echo $AMCLI | tr a-z A-Z)"'" IS NOW UPDATED TO THE BRAND NEW '"$($AMCLIPATH -v)"' VERSION! \n\n Replacement of version '"$CURRENT_AM_VERSION"' currently in use, COMPLETED!'
82+
if [ ! "$CURRENT_AM_VERSION" == "$("$AMCLIPATH" -v)" ] ; then
83+
echo -ne ' A new release of "'"$(echo "$AMCLI" | tr a-z A-Z)"'" is available, please wait...\r'
84+
echo -e ' ◆ "'"$(echo "$AMCLI" | tr a-z A-Z)"'" IS NOW UPDATED TO THE BRAND NEW '"$("$AMCLIPATH" -v)"' VERSION! \n\n Replacement of version '"$CURRENT_AM_VERSION"' currently in use, COMPLETED!'
8585
echo -e "\n See https://github.com/ivan-hc/AM/commits/main\n"
8686
else
87-
echo -e ' ◆ "'"$(echo $AMCLI | tr a-z A-Z)"'" IS ALREADY UPDATED, CURRENT VERSION '"$CURRENT_AM_VERSION"''
87+
echo -e ' ◆ "'"$(echo "$AMCLI" | tr a-z A-Z)"'" IS ALREADY UPDATED, CURRENT VERSION '"$CURRENT_AM_VERSION"''
8888
echo -e "\n See https://github.com/ivan-hc/AM/commits/$AMBRANCH\n"
8989
fi
9090
}

programs/x86_64-apps

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,7 @@
916916
◆ lepton : Democratizing Code Snippets Management (macOS/Win/Linux).
917917
◆ lescovex : Lescovex decentralized exchange, wallet and contract issuer.
918918
◆ levior : Converts web pages on-the-fly to the gemtext format.
919+
◆ lf : lf (as in "list files") is a terminal file manager written in Go.
919920
◆ libassist : Library Assistant.
920921
◆ libertem : Pixelated scanning transmission electron microscopy.
921922
◆ librecad : 2D CAD program written in C++11 using the Qt framework.

programs/x86_64/lf

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/sh
2+
3+
APP=lf
4+
SITE="gokcehan/lf"
5+
6+
# CREATE THE FOLDER
7+
mkdir /opt/$APP
8+
cd /opt/$APP
9+
10+
# ADD THE REMOVER
11+
echo '#!/bin/sh' >> /opt/$APP/remove
12+
echo "rm -R -f /opt/$APP /usr/local/bin/$APP" >> /opt/$APP/remove
13+
chmod a+x /opt/$APP/remove
14+
15+
# DOWNLOAD THE ARCHIVE
16+
mkdir tmp
17+
cd ./tmp
18+
19+
version=$(curl -Ls https://api.github.com/repos/"$SITE"/releases | jq '.' | sed 's/[()",{}]/ /g; s/ /\n/g' | grep -o 'https.*lf-linux-amd64.*gz$' | head -1)
20+
wget $version
21+
echo "$version" >> /opt/$APP/version
22+
tar fx ./*tar*; rm -R -f ./*tar*
23+
cd ..
24+
mv --backup=t ./tmp/* ./$APP
25+
rm -R -f ./tmp
26+
27+
# LINK
28+
ln -s /opt/$APP/$APP /usr/local/bin/$APP
29+
30+
# SCRIPT TO UPDATE THE PROGRAM
31+
cat >> /opt/$APP/AM-updater << 'EOF'
32+
#!/bin/sh
33+
APP=lf
34+
SITE="gokcehan/lf"
35+
version0=$(cat /opt/$APP/version)
36+
version=$(curl -Ls https://api.github.com/repos/"$SITE"/releases | jq '.' | sed 's/[()",{}]/ /g; s/ /\n/g' | grep -o 'https.*lf-linux-amd64.*gz$' | head -1)
37+
if [ $version = $version0 ]; then
38+
echo "Update not needed!"
39+
else
40+
notify-send "A new version of $APP is available, please wait"
41+
mkdir /opt/$APP/tmp
42+
cd /opt/$APP/tmp
43+
wget $version
44+
tar fx ./*tar*; rm -R -f ./*tar*
45+
cd ..
46+
mv --backup=t ./tmp/* ./$APP
47+
rm ./version
48+
echo $version >> ./version
49+
rm -R -f ./tmp ./*~
50+
notify-send "$APP is updated!"
51+
fi
52+
EOF
53+
chmod a+x /opt/$APP/AM-updater

0 commit comments

Comments
 (0)