Skip to content

Commit b108b71

Browse files
authored
Merge pull request #651 from ivan-hc/dev
Improve option "--rollback" to downgrade the apps
2 parents a4e04e5 + 627b0d5 commit b108b71

File tree

5 files changed

+59
-59
lines changed

5 files changed

+59
-59
lines changed

APP-MANAGER

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

3-
AMVERSION="6.10.4"
3+
AMVERSION="6.11"
44

55
# Determine main repository and branch
66
AMREPO="https://raw.githubusercontent.com/ivan-hc/AM/main"
@@ -509,6 +509,7 @@ function _generate_options_list() {
509509
apikey
510510
backup
511511
clean
512+
downgrade
512513
download
513514
files
514515
install
@@ -1001,7 +1002,7 @@ case "$1" in
10011002
'-b'|'backup'|\
10021003
'-o'|'overwrite'|\
10031004
'-R'|'-r'|'remove'|\
1004-
'--rollback'|\
1005+
'--rollback'|'downgrade'|\
10051006
'lock'|'unlock'|\
10061007
'nolibfuse')
10071008
MODULE="management.am"

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
- [How to enable bash completion](#how-to-enable-bash-completion)
3636
- [Snapshots: backup your app and restore to a previous version](#snapshots-backup-your-app-and-restore-to-a-previous-version)
3737
- [Update/remove programs without "AM"](#updateremove-programs-without-am)
38-
- [Rollback](#rollback)
38+
- [Downgrade](#downgrade)
3939
- [Convert old Type2 AppImages to Type3](#convert-old-type2-appimages-to-type3)
4040
- [Manage local AppImages](#manage-local-appimages)
4141
- [Sandbox using Firejail](#sandbox-using-firejail)
@@ -591,7 +591,7 @@ to have a list of the installed programs use the option `-f` or `files` (syntax
591591
DESCRIPTION: Embed one or more local AppImages in the applications menu. I suggest dragging the files into the terminal to get the desired effect. Launchers are located in ~/.local/share/applications/AppImages by default.
592592
___________________________________________________________________________
593593

594-
`--rollback`
594+
`--rollback`, `downgrade`
595595

596596
SYNOPSIS:
597597

@@ -759,11 +759,11 @@ sudo /opt/$PROGRAM/remove
759759
</details>
760760

761761
------------------------------------------------------------------------
762-
### Rollback
762+
### Downgrade
763763
<details>
764764
<summary></summary>
765765

766-
From version 4.4 it is possible to directly select from a list of URLs the version of the app that interests you most from the main source. Use the `--rollback` option in this mode:
766+
From version 4.4 it is possible to directly select from a list of URLs the version of the app that interests you most from the main source. Use the `--rollback` option or `downgrade` in this mode:
767767
```
768768
am --rollback ${PROGRAM}
769769
```
@@ -884,7 +884,7 @@ Use the `-a` option and go to the developer's site to report the problem. The ta
884884
There can be many reasons:
885885
- check your internet connection;
886886
- if the app is hosted on github.com, you have probably exceeded the hourly limit of API calls;
887-
- the referring link may have been changed, try the `--rollback` option;
887+
- the referring link may have been changed, try the `--rollback` option or `downgrade`;
888888
- the reference site has changed, report any changes at https://github.com/ivan-hc/AM/issues
889889

890890
</details>
@@ -993,7 +993,7 @@ NOTE, the binary is called from a script in /usr/local/bin that runs "wget" with
993993
<summary></summary>
994994

995995
The reasons may be two:
996-
- the referring link may have been changed, try the `--rollback` option;
996+
- the referring link may have been changed, try the `--rollback` option or `downgrade`;
997997
- the reference site has changed, report any changes at https://github.com/ivan-hc/AM/issues
998998

999999
</details>

modules/help.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ function _help_body() {
262262
I suggest dragging the files into the terminal to get the desired effect.
263263
__________________________________________________________________________
264264
265-
--rollback
265+
--rollback, downgrade
266266
267267
SYNOPSIS: --rollback {PROGRAM}
268268

modules/management.am

Lines changed: 48 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -61,60 +61,59 @@ function _remove() {
6161
######################################
6262

6363
function _do_rollback() {
64-
if test -f "$APPSPATH"/$2/AM-updater; then
65-
if test -f "$APPSPATH"/$2/$2-rollback; then
66-
cd "$APPSPATH"/$2 || return
67-
./$2-rollback
64+
if test -f "$APPSPATH"/"$2"/AM-updater; then
65+
if test -f "$APPSPATH"/"$2"/"$2"-rollback; then
66+
cd "$APPSPATH"/"$2" || return
67+
./"$2"-rollback
6868
exit
69-
elif test -f "$APPSPATH"/$2/*.zsync; then
70-
echo " AppImage packages updatable with zsync have not previous versions."; exit
71-
elif test -f "$APPSPATH"/$2/updater; then
72-
echo ' When an executable called "updater" is available, the app is only updateable.'; exit
73-
else
74-
if grep -q "api.github.com" "$APPSPATH"/$2/AM-updater; then
75-
rm -f "$AMCACHEDIR/rollback-args";
76-
extension=$(cat "$APPSPATH"/$2/version | tr '.' '\n' | tail -1)
77-
REPO=$(grep -i "REPO=" "$APPSPATH"/$2/AM-updater | grep -o -P '(?<=").*(?=")')
78-
printf "%s\n" "$(curl -Ls $HeaderAuthWithGITPAT https://api.github.com/repos/$REPO/releases?per_page=100 \
79-
| grep browser_download_url | cut -d '"' -f 4)" | tr ' ' '\n' | grep -i "$extension$" >> "$AMCACHEDIR/rollback-args"
80-
if ! grep -q "[0-9]" "$AMCACHEDIR"/rollback-args; then
81-
echo " ERROR: No valid links found, sorry!"
82-
exit
69+
elif grep -q "api.github.com" "$APPSPATH"/"$2"/AM-updater; then
70+
cd "$APPSPATH"/"$2" || return
71+
rm -f "$AMCACHEDIR/rollback-args";
72+
extension=$(cat ./version | tr '.' '\n' | tail -1)
73+
if grep -q "^REPO=" ./AM-updater; then
74+
REPO=$(grep -i "REPO=" ./AM-updater | grep -o -P '(?<=").*(?=")')
75+
elif grep -q "^SITE=" ./AM-updater; then
76+
REPO=$(grep -i "SITE=" ./AM-updater | grep -o -P '(?<=").*(?=")')
77+
fi
78+
entries_list=$(grep "^version=" ./AM-updater | sed '1,${ s/version=$(//g; s/head -1)/head -100/g; s#$REPO#'"$REPO"'#g; s#releases/latest#releases#g; s#releases #releases?per_page=100 #g; }')
79+
printf "%s\n" "$(eval "$entries_list")" | tr ' ' '\n' | grep -i "$extension$" >> "$AMCACHEDIR/rollback-args"
80+
if ! grep -q "[0-9]" "$AMCACHEDIR"/rollback-args; then
81+
echo " ERROR: No valid links found, sorry!"
82+
exit
83+
else
84+
echo "-----------------------------------------------------------------------"
85+
echo "You have chosen to roll back $2."
86+
echo "Rollback will be done from https://github.com/$REPO"
87+
echo "-----------------------------------------------------------------------"
88+
printf "Select a URL from this menu (read carefully) or press CTRL+C to abort:\n-----------------------------------------------------------------------\n"; sleep 1;
89+
select d in $(cat "$AMCACHEDIR/rollback-args"); do test -n "$d" && break; echo ">>> Invalid Selection"; done
90+
91+
cp ./AM-updater ./AM-rollback
92+
sed -i 's/version0/#version0/g' ./AM-rollback
93+
94+
if test -f ./"$2".zsync; then mv ./"$2".zsync ./"$2".zsync.old; fi
95+
96+
if wget --version | head -1 | grep -q ' 1.'; then
97+
sed -i '/wget/c\wget -q --show-progress '"$d"'' ./AM-rollback
8398
else
84-
echo "-----------------------------------------------------------------------"
85-
echo "You have chosen to roll back $2."
86-
echo "Rollback will be done from https://github.com/$REPO"
87-
echo "-----------------------------------------------------------------------"
88-
printf "Select a URL from this menu (read carefully) or press CTRL+C to abort:\n-----------------------------------------------------------------------\n"; sleep 1;
89-
select d in $(cat "$AMCACHEDIR/rollback-args"); do test -n "$d" && break; echo ">>> Invalid Selection"; done
90-
cp "$APPSPATH"/$2/AM-updater "$APPSPATH"/$2/AM-rollback
91-
sed -i 's/version0/#version0/g' "$APPSPATH"/$2/AM-rollback
92-
sed -i '/show-progress/c\wget -q --show-progress '$d'' "$APPSPATH"/$2/AM-rollback
93-
if test -f ./AM-rollback; then
94-
if grep -q '/$APP/*.zsync' ./AM-rollback; then
95-
mv "$APPSPATH"/$2/AM-rollback "$APPSPATH"/$2/AM-rollback.old
96-
sed -n '1,6p' "$APPSPATH"/$2/AM-rollback.old >> "$APPSPATH"/$2/AM-rollback
97-
sed -n '17,36p' "$APPSPATH"/$2/AM-rollback.old >> "$APPSPATH"/$2/AM-rollback
98-
rm -f "$APPSPATH"/$2/AM-rollback.old
99-
sed -i 's/ //g' "$APPSPATH"/$2/AM-rollback
100-
chmod a+x "$APPSPATH"/$2/AM-rollback
101-
fi
102-
fi
103-
"$APPSPATH"/$2/AM-rollback
104-
rm -f "$APPSPATH"/$2/AM-rollback
105-
rm -f "$APPSPATH"/$2/version
106-
echo $d >> "$APPSPATH"/$2/version
107-
_clean_amcachedir
108-
_list_updatable_apps
109-
echo -e "\nROLLBACK SUCCESSFUL!"
110-
exit
99+
sed -i '/wget/c\wget '"$d"'' ./AM-rollback
111100
fi
112-
else
113-
echo " The option '$1' only works for https://github.com"; exit
101+
./AM-rollback
102+
rm -f ./AM-rollback
103+
104+
if test -f ./"$2".zsync.old; then mv ./"$2".zsync.old ./"$2".zsync; fi
105+
106+
echo "$d" > ./version
107+
_clean_amcachedir
108+
_list_updatable_apps
109+
echo -e "\nROLLBACK SUCCESSFUL!"
110+
exit
114111
fi
112+
else
113+
echo " The option \"$1\" only works for https://github.com"; exit
115114
fi
116115
else
117-
echo ' No AM-updater available for '$2', cannot detect any URL!'; exit
116+
echo " No AM-updater available for \"$2\", cannot detect any URL!"; exit
118117
fi
119118
}
120119

@@ -413,7 +412,7 @@ case "$1" in
413412
shift
414413
;;
415414

416-
'--rollback') # THIS OPTION ALLOWS YOU TO DOWNGRADE THE INSTALLED APP TO A PREVIOUS VERSION, IF EXISTS
415+
'--rollback'|'downgrade') # THIS OPTION ALLOWS YOU TO DOWNGRADE THE INSTALLED APP TO A PREVIOUS VERSION, IF EXISTS
417416
_online_check
418417
while [ -n "$1" ]; do
419418
_do_rollback "${@}"

templates/AM-SAMPLE-AppImage

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ chmod a+x "/opt/$APP/remove"
1414
# DOWNLOAD AND PREPARE THE APP, $version is also used for updates
1515
version=$(FUNCTION)
1616
wget "$version" || exit 1
17-
wget "$version.zsync" 2> /dev/null
17+
#wget "$version.zsync" 2> /dev/null # Comment out this line if you want to use zsync, warning that more often than not it is broken
1818
echo "$version" > /opt/$APP/version
1919
# Use tar fx ./*tar* here for example in this line in case a compressed file is downloaded.
2020
cd ..

0 commit comments

Comments
 (0)