Enhanced AppImage downloader with --extract option
[geeqie.git] / scripts / geeqie-download-appimage.sh
1 #!/bin/sh
2 #**********************************************************************
3 # Copyright (C) 2023 - The Geeqie Team
4 #
5 # Author: Colin Clark
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #**********************************************************************
21
22 ## @file
23 ## @brief Download full and minimal AppImages from the Continuous build release on GitHub.
24 ## Optionally extract the full size AppImage.
25 ##
26 ## $1: -e | --extract Extract full size AppImage
27 ## The user should modify the symbolic links as appropriate.
28 ##
29 ## Downloads will not be made unless the server version is newer than the local file.
30 ##
31
32 show_help()
33 {
34 printf "Download the latest Geeqie AppImages from the
35 Continuous Build release on GitHub.
36
37 The Continuous Build release is updated each
38 time the source code is updated.
39
40 You should read the contents of this file before
41 running it and modify it to your requirements.
42
43 The default action is to download both the
44 minimal and full size AppImages to \$HOME/bin.
45 Symbolic links will be set so that:
46 \"geeqie\" points to the minimal version
47 and
48 \"Geeqie\" points to the full version.
49
50 No downloads will be made unless the file on the
51 server at GitHub is newer than the local file.
52
53 The full size AppImage is about 120MB and the
54 minimal AppImage is about 10MB. Therefore the full
55 size version will load much slower and will have
56 a slightly slower run speed.
57
58 However the minimal version has limited capabilities
59 compared to the full size version.
60
61 The extract option (-e or --extract) will extract
62 The contents of the full size image into a sub-directory
63 of \$HOME/bin, and then set the symbolic link to the
64 extracted executable. This will take up disk space, but the
65 extracted executable will run as fast as a packaged release.
66
67 When a new file is downloaded the extracted files will
68 be replaced by the newly downloaded files\n\n"
69 }
70
71 extract=0
72
73 while :; do
74     case $1 in
75         -h|-\?|--help)
76             show_help
77             exit
78             ;;
79         -e|--extract)    # AppImage extraction is required
80             extract=1
81             ;;
82         --)              # End of all options.
83             shift
84             break
85             ;;
86         -?*)
87             printf 'ERROR: Unknown option %s\n' "$1" >&2
88             exit
89             ;;
90         *)
91             break
92     esac
93
94     shift
95 done
96
97 cd "$HOME/bin/" || exit
98 architecture=$(arch)
99
100 # Download full size AppImage
101 log_file=$(mktemp "${TMPDIR:-/tmp}/geeqie.XXXXXXXXXX")
102
103 wget --no-verbose --show-progress --backups=3 --output-file="$log_file" --timestamping "https://github.com/BestImageViewer/geeqie/releases/download/continuous/Geeqie-latest-$architecture.AppImage";
104
105 download_size=$(stat --printf "%s" "$log_file")
106 rm "$log_file"
107
108 # If a new file was downloaded, check if extraction is required
109 if [ "$download_size" -gt 0 ]
110 then
111         chmod +x "Geeqie-latest-$architecture.AppImage"
112
113         if [ "$extract" -eq 1 ]
114         then
115                 rm -rf "Geeqie-latest-$architecture-AppImage"
116                 mkdir "Geeqie-latest-$architecture-AppImage"
117                 cd "Geeqie-latest-$architecture-AppImage" || exit
118
119                 printf "Extracting AppImage\n"
120                 ../"Geeqie-latest-$architecture.AppImage" --appimage-extract | cut -c 1-50 | tr '\n' '\r'
121
122                 printf "\n"
123                 cd ..
124                 ln --symbolic --force "./Geeqie-latest-$architecture-AppImage/squashfs-root/AppRun" Geeqie
125         else
126                 ln --symbolic --force "Geeqie-latest-$architecture.AppImage" Geeqie
127         fi
128 fi
129
130 # Download minimal AppImage
131 wget --quiet --show-progress --backups=3 --timestamping "https://github.com/BestImageViewer/geeqie/releases/download/continuous/Geeqie-minimal-latest-$architecture.AppImage";
132 chmod +x "Geeqie-minimal-latest-$architecture.AppImage"
133 ln --symbolic --force "Geeqie-minimal-latest-$architecture.AppImage" geeqie