File: geeqie-download-appimage.sh

package info (click to toggle)
geeqie 1%3A2.5-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 16,780 kB
  • sloc: cpp: 110,189; xml: 11,497; sh: 3,681; awk: 124; perl: 88; python: 80; makefile: 23
file content (333 lines) | stat: -rwxr-xr-x 8,486 bytes parent folder | download
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
#!/bin/sh
#**********************************************************************
# Copyright (C) 2023 - The Geeqie Team
#
# Author: Colin Clark
#
# 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 2 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.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#**********************************************************************

## @file
## @brief Download full and minimal AppImages from the Continuous build release on GitHub.
## Optionally extract the full size AppImage.
##
## Downloads are made to $HOME/bin.
## It is expected that $HOME/bin exists and that it is in $PATH.
##
## Downloads will not be made unless the server version is newer than the local file.
##

version="2024-04-14"
backups=3

show_help()
{
	printf "Download the latest Geeqie AppImages from the
Continuous Build release on GitHub.

-b --backups <n> Set number of backups (default is 3)
-d --desktop Install desktop icon and menu item
-e --extract Extract AppImage
-h --help Display this message
-m --minimal Download minimal version of AppImage
-r --revert <n> Revert to downloaded AppImage backup. For the latest version set <n> to 0
-v --version Display version of this file

The Continuous Build release is updated each
time the source code is updated.

The default action is to download an AppImage to
\$HOME/bin. A symbolic link will be set so that
\"geeqie\" points to the executable

No downloads will be made unless the file on the
server at GitHub is newer than the local file.

The full size AppImage is about 120MB and the
minimal AppImage is about 10MB. Therefore the full
size version will load much slower and will have
a slightly slower run speed.

However the minimal version has limited capabilities
compared to the full size version.

The minimal option (-m or --minimal) will download
the minimal version.

The extract option (-e or --extract) will extract
The contents of the AppImage into a sub-directory
of \$HOME/bin, and then set the symbolic link to the
extracted executable.

This will take up some disk space, but the
extracted executable will run as fast as a
packaged release.

If the extract option is selected, a symbolic link from
\$HOME/.local/share/bash-completion/completions/geeqie
to the extracted executable will be set to enable command line completion.
\n\n"
}

show_version()
{
	printf "Version: %s\n" "$version"
}

spinner()
{
	message="$1"
	character_count=$((${#message} + 4))
	pid=$!
	delay=0.75
	spinstr='\|/-'

	while kill -0 "$pid" 2> /dev/null
	do
		temp=${spinstr#?}
		printf "$message [%c]" "$spinstr"
		spinstr=$temp${spinstr%"$temp"}
		sleep "$delay"
		printf "%$character_count""s" | tr " " "\b"
	done
}

architecture=$(arch)

extract=0
minimal=""
desktop=0
backups_option=0
revert=""
revert_option=0

while :
do
	case $1 in
		-h | -\? | --help)
			show_help

			exit 0
			;;
		-v | --version)
			show_version

			exit 0
			;;
		-d | --desktop)
			desktop=1
			;;
		-b | --backups)
			backups_option=1
			if [ -n "$2" ]
			then
				backups=$2
				shift
			else
				printf '"--backups" requires a non-empty option argument.\n' >&2

				exit 1
			fi
			;;
		-r | --revert)
			revert_option=1
			if [ -n "$2" ]
			then
				revert=$2
				shift
			else
				printf '"--revert" requires a non-empty option argument.\n' >&2

				exit 1
			fi
			;;
		-e | --extract)
			extract=1
			;;
		-m | --minimal)
			minimal="-minimal"
			;;
		--) # End of all options.
			shift
			break
			;;
		?*)
			printf 'Unknown option %s\n' "$1" >&2

			exit 1
			;;
		*)
			break
			;;
	esac

	shift
done

if [ ! -d "$HOME/bin" ]
then
	printf "\$HOME/bin does not exist.
It is required for this script to run.
Also, \$HOME/bin should be in \$PATH.\n"

	exit 1
fi

if [ "$backups_option" -eq 1 ] && {
	[ "$minimal" = "-minimal" ] || [ "$extract" -eq 1 ] || [ "$revert_option" -eq 1 ]
}
then
	printf "backups must be the only option\n"

	exit 1
fi

if [ "$desktop" -eq 1 ] && {
	[ "$minimal" = "-minimal" ] || [ "$extract" -eq 1 ]
}
then
	printf "desktop must be the only option\n"

	exit 1
fi

if [ "$backups_option" -eq 1 ]
then
	if ! [ "$backups" -gt 0 ] 2> /dev/null
	then
		printf "%s is not an integer\n" "$backups"

		exit 1
	else
		tmp_file=$(mktemp "${TMPDIR:-/tmp}/geeqie.XXXXXXXXXX")
		cp "$0" "$tmp_file"
		sed --in-place "s/^backups=.*/backups=$backups/" "$tmp_file"
		chmod +x "$tmp_file"
		mv "$tmp_file" "$0"

		exit 0
	fi
fi

if [ "$desktop" -eq 1 ]
then
	if [ -f "$HOME/Desktop/org.geeqie.Geeqie.desktop" ]
	then
		printf "Desktop file already exists\n"

		exit 0
	fi

	file_count=$(find "$HOME/bin/" -name "Geeqie*latest*\.AppImage" -print | wc -l)
	if [ "$file_count" -eq 0 ]
	then
		printf "No AppImages have been downloaded\n"

		exit 1
	fi

	tmp_dir=$(mktemp --directory "${TMPDIR:-/tmp}/geeqie.XXXXXXXXXX")
	cd "$tmp_dir" || exit 1

	app=$(find "$HOME/bin/" -name "Geeqie*latest*\.AppImage" -print | sort --reverse | head -1)
	$app --appimage-extract "usr/local/share/applications/org.geeqie.Geeqie.desktop" > /dev/null
	$app --appimage-extract "usr/local/share/pixmaps/geeqie.png" > /dev/null
	xdg-desktop-icon install --novendor "squashfs-root/usr/local/share/applications/org.geeqie.Geeqie.desktop"
	xdg-icon-resource install --novendor --size 48 "squashfs-root/usr/local/share/pixmaps/geeqie.png"
	xdg-desktop-menu install --novendor "squashfs-root/usr/local/share/applications/org.geeqie.Geeqie.desktop"
	rm --recursive --force "$tmp_dir"

	exit 0
fi

# The cd needs to be here because the --backups option needs PWD
cd "$HOME/bin/" || exit 1

if [ "$revert_option" -eq 1 ]
then
	if ! [ "$revert" -ge 0 ] 2> /dev/null
	then
		printf "%s is not an integer\n" "$revert"

		exit 1
	else
		if [ "$revert" -eq 0 ]
		then
			revert=""
		else
			revert=".$revert"
		fi
	fi

	if ! [ -f "$HOME/bin/Geeqie$minimal-latest-$architecture.AppImage$revert" ]
	then
		printf "Backup $HOME/bin/Geeqie%s-latest-$architecture.AppImage%s does not exist\n" "$minimal" "$revert"

		exit 1
	fi

	if [ "$extract" -eq 1 ]
	then
		rm --recursive --force "Geeqie$minimal-latest-$architecture-AppImage"
		mkdir "Geeqie$minimal-latest-$architecture-AppImage"
		cd "Geeqie$minimal-latest-$architecture-AppImage" || exit 1

		(../Geeqie-latest-x86_64.AppImage --appimage-extract > /dev/null) & spinner "Extracting Geeqie AppImage..."

		printf "\nExtraction complete\n"

		cd ..
		ln --symbolic --force "./Geeqie$minimal-latest-$architecture-AppImage/squashfs-root/AppRun" geeqie
	else
		ln --symbolic --force "$HOME/bin/Geeqie$minimal-latest-$architecture.AppImage$revert" geeqie
	fi

	exit 0
fi

log_file=$(mktemp "${TMPDIR:-/tmp}/geeqie.XXXXXXXXXX")

wget --no-verbose --show-progress --backups="$backups" --output-file="$log_file" --timestamping "https://github.com/BestImageViewer/geeqie/releases/download/continuous/Geeqie$minimal-latest-$architecture.AppImage"

download_size=$(stat --printf "%s" "$log_file")
rm "$log_file"

# If a new file was downloaded, check if extraction is required
if [ "$download_size" -gt 0 ]
then
	chmod +x "Geeqie$minimal-latest-$architecture.AppImage"

	if [ "$extract" -eq 1 ]
	then
		rm --recursive --force "Geeqie$minimal-latest-$architecture-AppImage"
		mkdir "Geeqie$minimal-latest-$architecture-AppImage"
		cd "Geeqie$minimal-latest-$architecture-AppImage" || exit 1

		(../Geeqie-latest-x86_64.AppImage --appimage-extract > /dev/null) & spinner "Extracting Geeqie AppImage..."

		printf "\nExtraction complete\n"

		if [ ! -f "$HOME/.local/share/bash-completion/completions/geeqie" ]
		then
			mkdir --parents "$HOME/.local/share/bash-completion/completions/"
			ln --symbolic "$HOME/bin/Geeqie-latest-x86_64-AppImage/squashfs-root/usr/local/share/bash-completion/completions/geeqie" "$HOME/.local/share/bash-completion/completions/geeqie"
		fi

		cd ..
		ln --symbolic --force "./Geeqie$minimal-latest-$architecture-AppImage/squashfs-root/AppRun" geeqie
	else
		ln --symbolic --force "Geeqie$minimal-latest-$architecture.AppImage" geeqie
	fi
fi