Enhanced script for compiling on Debian systems
[geeqie.git] / web / geeqie-install-debian.sh
1 #!/bin/bash
2 version="2018-07-26"
3 description=$'
4 Geeqie is an image viewer.
5 This script will download, compile, and install Geeqie on Debian-based systems.
6 If run from a folder that already contains the Geeqie sources, the source
7 code will be updated from the repository.
8 Dialogs allow the user to install additional features, including
9 additional pixbuf loaders.
10
11 Command line options are:
12 -v --version The version of this file
13 -h --help Output this text
14 -c --commit Checkout and compile commit ident
15 -t --tag Checkout and compile tag (e.g. v1.4 or v1.3)
16 '
17
18 # Essential for compiling
19 essential_array=(
20 "git"
21 "build-essential"
22 "autoconf"
23 "libglib2.0-0"
24 "intltool"
25 )
26
27 # Optional for both GTK2 and GTK3
28 optional_array=(
29 "LCMS (for color management)"
30 "liblcms2-dev"
31 "exiv2 (for exif handling)"
32 "libgexiv2-dev"
33 "lua (for --remote commands)"
34 "liblua5.1-0-dev"
35 "libffmpegthumbnailer (for mpeg thumbnails)"
36 "libffmpegthumbnailer-dev"
37 "libtiff (for tiff support)"
38 "libtiff-dev"
39 "libjpeg (for jpeg support"
40 "libjpeg-dev"
41 "librsvg2 (for viewing .svg images"
42 "librsvg2-common"
43 "libwmf (for viewing .wmf images)"
44 "libwmf0.2-7-gtk"
45 "exiftran (for image rotation)"
46 "exiftran"
47 "imagemagick (for image rotation)"
48 "imagemagick"
49 "ufraw (for RAW file handling)"
50 "ufraw"
51 "markdown (for generating README help file)"
52 "markdown"
53 )
54
55 # Optional for GTK3 only
56 optional_gtk3_array=(
57 "libchamplain gtk (for GPS maps)"
58 "libchamplain-gtk-0.12-dev"
59 "libchamplain (for GPS maps)"
60 "libchamplain-0.12-dev"
61 "libpoppler (for pdf file preview)"
62 "libpoppler-glib-dev"
63 )
64
65 # Optional pixbuf loaders
66 optional_loaders_array=(
67 ".webp WebP images"
68 "webp"
69 ".psd Photoshop images"
70 "psd"
71 ".xcf Gimp files"
72 "xcf"
73 )
74
75 install_essential()
76 {
77 arraylength=${#essential_array[@]}
78 for (( i=0; i<${arraylength}; i=i+1 ));
79 do
80         res=$(dpkg-query --show --showformat='${Status}' ${essential_array[$i]} 2>&1)
81         if [[ $res != "install ok installed"* ]]
82         then
83                 sudo apt-get --assume-yes install ${essential_array[$i]}
84         fi
85 done
86
87 if [[ $1 == "GTK3" ]]
88 then
89         res=$(dpkg-query --show --showformat='${Status}' "libgtk-3-dev" 2>&1)
90         if [[ $res != "install ok installed"* ]]
91         then
92                 sudo apt-get --assume-yes install libgtk-3-dev
93         fi
94 else
95         res=$(dpkg-query --show --showformat='${Status}' "libgtk2.0-dev" 2>&1)
96         if [[ $res != "install ok installed"* ]]
97         then
98                 sudo apt-get --assume-yes install libgtk2.0-dev
99         fi
100 fi
101 }
102
103 install_options()
104 {
105 if [ -n "$options" ]
106 then
107         OLDIFS=$IFS
108         IFS='|'
109         set $options
110         while [ $# -gt 0 ];
111         do
112                 sudo apt-get --assume-yes install $1
113                 shift
114         done
115         IFS=$OLDIFS
116 fi
117 return
118 }
119
120 install_webp()
121 {
122 rm -rf webp-pixbuf-loader-master
123 sudo apt-get --assume-yes install libglib2.0-dev libgdk-pixbuf2.0-dev libwebp-dev
124 wget https://github.com/aruiz/webp-pixbuf-loader/archive/master.zip
125 unzip master.zip
126 cd webp-pixbuf-loader-master
127 ./waf configure
128 ./waf build
129 sudo ./waf install
130 sudo gdk-pixbuf-query-loaders --update-cache
131 cd -
132 rm -rf webp-pixbuf-loader-master
133 rm master.zip
134 }
135
136 install_psd()
137 {
138 rm -rf gdk-pixbuf-psd
139 git clone https://github.com/and-rom/gdk-pixbuf-psd.git
140 cd gdk-pixbuf-psd
141 ./autogen.sh
142 make
143 sudo make install
144 sudo gdk-pixbuf-query-loaders --update-cache
145 cd -
146 rm -rf gdk-pixbuf-psd
147 }
148
149 install_xcf()
150 {
151 rm -rf xcf-pixbuf-loader
152 git clone https://github.com/StephaneDelcroix/xcf-pixbuf-loader.git
153 cd xcf-pixbuf-loader
154 ./autogen.sh
155 make
156
157 # There must be a better way...
158 loader_locn=$(gdk-pixbuf-query-loaders | grep "LoaderDir"  | tr -d '#[:space:]')
159
160 OLDIFS=$IFS
161 IFS='='
162 set $loader_locn
163 OLDIFS=$IFS
164
165 if [ -d $2 ]
166 then
167         sudo cp .libs/libioxcf.so $2
168         sudo gdk-pixbuf-query-loaders --update-cache
169 fi
170 cd -
171 rm -rf  xcf-pixbuf-loader
172 }
173
174 install_extra_loaders()
175 {
176 if [ -n "$extra_loaders" ]
177 then
178         OLDIFS=$IFS
179         IFS='|'
180         set $extra_loaders
181         while [ $# -gt 0 ];
182         do
183                 case $1 in
184                 "webp" )
185                         install_webp
186                 ;;
187                 "psd" )
188                         install_psd
189                 ;;
190                 "xcf" )
191                         install_xcf
192                 ;;
193                 esac
194
195                 shift
196         done
197         IFS=$OLDIFS
198 fi
199 return
200 }
201
202 uninstall()
203 {
204 current_dir=$(basename $PWD)
205 if [[ $current_dir == "geeqie" ]]
206 then
207         sudo make uninstall
208         zenity --title="Uninstall Geeqie" --width=370 --text="WARNING.\nThis will delete folder:\n\n$PWD\n\nand all sub-folders!" --question --ok-label="Cancel" --cancel-label="OK"  2>/dev/null
209
210         if [[ $? == 1 ]]
211         then
212                 cd ..
213                 sudo rm -rf geeqie
214         fi
215 else
216         zenity --title="Uninstall Geeqie" --width=370 --text="This is not a geeqie installation folder!\n\n$PWD" --warning  2>/dev/null
217 fi
218 exit
219 }
220
221
222 # Entry point
223 # Parse the comand line
224 OPTS=$(getopt -o vhc:t: --long version,help,commit:,tag: -- "$@")
225 eval set -- "$OPTS"
226
227 while true;
228 do
229         case "$1" in
230         -v | --version )
231                 echo "$version"
232                 exit
233                 ;;
234         -h | --help )
235                 echo "$description"
236                 exit
237                 ;;
238         -c | --commit )
239                 COMMIT="$2"
240                 shift
241                 shift
242                 ;;
243         -t | --tag )
244                 TAG="$2"
245                 shift;
246                 shift
247                 ;;
248         * ) break
249                 ;;
250         esac
251 done
252
253 # If a Geeqie folder already exists here, warn the user
254 if [ -d "geeqie" ]
255 then
256         zenity --info --title="Install Geeqie and dependencies" --width=370 --text="This script is for use on Ubuntu and other\nDebian-based installations.\nIt will download, compile, and install Geeqie source\ncode and its dependencies.\n\nA sub-folder named \"geeqie\" will be created in the\nfolder this script is run from, and the source code\nwill be downloaded to that sub-folder.\n\nA sub-folder of that name already exists.\nPlease try another folder." 2>/dev/null
257
258         exit
259 fi
260
261 # If it looks like a Geeqie download folder, assume an update
262 if [ -d ".git" ] && [ -d "src" ] && [ -f "geeqie.1" ]
263 then
264         mode="update"
265 else
266         # If it looks like something else is already installed here, warn the user
267         if [ -d ".git" ] || [ -d "src" ]
268         then
269                 zenity --info --title="Install Geeqie and dependencies" --width=370 --text="This script is for use on Ubuntu and other\nDebian-based installations.\nIt will download, compile, and install Geeqie source\ncode and its dependencies.\n\nIt looks like you are running this script from a folder which already has software installed.\n\nPlease try another folder." 2>/dev/null
270
271                 exit
272         else
273                 mode="install"
274         fi
275 fi
276
277 if [[ $mode == "install" ]]
278 then
279         message="This script is for use on Ubuntu and other\nDebian-based installations.\nIt will download, compile, and install Geeqie source\ncode and its dependencies.\n\nA sub-folder named \"geeqie\" will be created in the\nfolder this script is run from, and the source code\nwill be downloaded to that sub-folder.\n\nIn this dialog you must select whether to compile\nfor GTK2 or GTK3.\nIf you want to use GPS maps or pdf preview,\nyou must choose GTK3.\nThe GTK2 version has a slightly different\nlook-and-feel compared to the GTK3 version,\nbut otherwise has the same features.\nYou may easily switch between the two after\ninstallation.\n\nIn subsequent dialogs you may choose which\noptional features to install."
280
281         title="Install Geeqie and dependencies"
282 else
283         message="This script is for use on Ubuntu and other\nDebian-based installations.\nIt will update the Geeqie source code and its\ndependencies, and will compile and install Geeqie.\n\nYou may also switch the installed version from\nGTK2 to GTK3 and vice versa.\n\nIn this dialog you must select whether to compile\nfor GTK2 or GTK3.\nIf you want to use GPS maps or pdf preview,\nyou must choose GTK3.\nThe GTK2 version has a slightly different\nlook-and-feel compared to the GTK3 version,\nbut otherwise has the same features.\n\nIn subsequent dialogs you may choose which\noptional features to install."
284
285         title="Update Geeqie and re-install"
286 fi
287
288 # Ask whether to install GTK2 or GTK3 or uninstall
289
290 gtk_version=$(zenity --title="$title" --width=370 --text="$message" --list --radiolist --column "" --column "" TRUE "GTK3 (required for GPS maps and pdf preview)" FALSE "GTK2" FALSE "Uninstall" --cancel-label="Cancel" --ok-label="OK" --hide-header 2>/dev/null)
291
292 if [[ $? == 1 ]]
293 then
294         exit
295 fi
296
297 if [[ $gtk_version == "Uninstall" ]]
298 then
299         uninstall
300         exit
301 fi
302
303 sleep 100 | zenity --title="$title" --text="Checking for installed files" --width=370 --progress --pulsate 2>/dev/null &
304 zen_pid=$!
305
306 # Get the standard options that are not yet installed
307 arraylength=${#optional_array[@]}
308 for (( i=0; i<${arraylength}; i=i+2 ));
309 do
310         res=$(dpkg-query --show --showformat='${Status}' ${optional_array[$i+1]}  2>&1)
311         if [[ $res != "install ok installed"* ]]
312         then
313                 if [ -z "$option_string" ]
314                 then
315                         option_string=$'TRUE\n'"${optional_array[$i]}"$'\n'"${optional_array[$i+1]}"
316                 else
317                         option_string="$option_string"$'\nTRUE\n'"${optional_array[$i]}"$'\n'"${optional_array[$i+1]}"
318                 fi
319         fi
320 done
321
322 # If GTK3 required, get the GTK3 options not yet installed
323 if [[ "$gtk_version" == "GTK3"* ]]
324 then
325         arraylength=${#optional_gtk3_array[@]}
326         for (( i=0; i<${arraylength}; i=i+2 ));
327         do
328                 res=$(dpkg-query --show --showformat='${Status}' ${optional_gtk3_array[$i+1]}  2>&1)
329                 if [[ $res != "install ok installed"* ]]
330                 then
331                         if [ -z "$option_string" ]
332                         then
333                                 option_string=$'TRUE\n'"${optional_gtk3_array[$i]}"$'\n'"${optional_gtk3_array[$i+1]}"
334                         else
335                                 option_string="$option_string"$'\nTRUE\n'"${optional_gtk3_array[$i]}"$'\n'"${optional_gtk3_array[$i+1]}"
336                         fi
337                 fi
338         done
339 fi
340
341 # Get the optional loaders not yet installed
342 ((i=0))
343 gdk-pixbuf-query-loaders | grep WebP >/dev/null
344 if [[ $? == 1 ]]
345 then
346         if [ -z "$loaders_string" ]
347         then
348                 loaders_string=$'nFALSE\n'"${optional_loaders_array[$i]}"$'\n'"${optional_loaders_array[$i+1]}"
349         else
350                 loaders_string="$loaders_string"$'\nFALSE\n'"${optional_loaders_array[$i]}"$'\n'"${optional_loaders_array[$i+1]}"
351         fi
352 fi
353
354 ((i=i+2))
355 gdk-pixbuf-query-loaders | grep psd >/dev/null
356 if [[ $? == 1 ]]
357 then
358         if [ -z "$loaders_string" ]
359         then
360                 loaders_string=$'FALSE\n'"${optional_loaders_array[$i]}"$'\n'"${optional_loaders_array[$i+1]}"
361         else
362                 loaders_string="$loaders_string"$'\nFALSE\n'"${optional_loaders_array[$i]}"$'\n'"${optional_loaders_array[$i+1]}"
363         fi
364 fi
365
366 ((i=i+2))
367 gdk-pixbuf-query-loaders | grep xcf >/dev/null
368 if [[ $? == 1 ]]
369 then
370         if [ -z "$loaders_string" ]
371         then
372                 loaders_string=$'FALSE\n'"${optional_loaders_array[$i]}"$'\n'"${optional_loaders_array[$i+1]}"
373         else
374                 loaders_string="$loaders_string"$'\nFALSE\n'"${optional_loaders_array[$i]}"$'\n'"${optional_loaders_array[$i+1]}"
375         fi
376 fi
377
378 kill $zen_pid 2>/dev/null
379
380 # Ask the user which options to install
381 if [ -n "$option_string" ]
382 then
383         options=$(echo "$option_string" | zenity --title="$title" --width=370 --height=400 --list --checklist --text 'Select which library files to install:' --column='Select' --column='Library files' --column='Library' --hide-column=3 --print-column=3 2>/dev/null)
384
385         if [[ $? == 1 ]]
386         then
387                 exit
388         fi
389 fi
390
391 # Ask the user which extra loaders to install
392 if [ -n "$loaders_string" ]
393 then
394         extra_loaders=$(echo "$loaders_string" | zenity --title="$title" --width=370 --height=400 --list --checklist --text 'These loaders are not part of the main repository,\nbut are known to work to some extent.' --column='Select' --column='Library files' --column='Library' --hide-column=3 --print-column=3 2>/dev/null)
395
396         if [[ $? == 1 ]]
397         then
398                 exit
399         fi
400 fi
401
402 install_essential $gtk_version
403 install_options
404 install_extra_loaders
405
406 if [[ $mode == "install" ]]
407 then
408         ret=$(git clone git://www.geeqie.org/geeqie.git)
409 else
410         git checkout master
411         ret=$(git pull)
412 fi
413
414 if [[ $? != 0 ]]
415 then
416         echo "$ret"
417         exit
418 fi
419
420 if [[ $mode == "install" ]]
421 then
422         cd geeqie
423 else
424         sudo make uninstall
425         sudo make maintainer-clean
426 fi
427
428 if [[ "$COMMIT" ]]
429 then
430         git checkout "$COMMIT"
431 fi
432 if [[ "TAG" ]]
433 then
434         git checkout "$TAG"
435 fi
436
437 if [[ $gtk_version == "GTK3"* ]]
438 then
439         ./autogen.sh
440 else
441         ./autogen.sh --disable-gtk3
442 fi
443
444 make -j
445 sudo make install
446
447 exit
448
449