Revised script for compiling on Debian system
[geeqie.git] / web / geeqie-install-debian.sh
1 #!/bin/bash
2 version="2018-08-02"
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=ID Checkout and compile commit ID
15 -t --tag=TAG Checkout and compile TAG (e.g. v1.4 or v1.3)
16 -b --back=N Checkout commit -N (e.g. "-b 1" for last-but-one commit)
17 '
18
19 # Essential for compiling
20 essential_array=(
21 "git"
22 "build-essential"
23 "autoconf"
24 "libglib2.0-0"
25 "intltool"
26 )
27
28 # Optional for both GTK2 and GTK3
29 optional_array=(
30 "LCMS (for color management)"
31 "liblcms2-dev"
32 "exiv2 (for exif handling)"
33 "libgexiv2-dev"
34 "lua (for --remote commands)"
35 "liblua5.1-0-dev"
36 "libffmpegthumbnailer (for mpeg thumbnails)"
37 "libffmpegthumbnailer-dev"
38 "libtiff (for tiff support)"
39 "libtiff-dev"
40 "libjpeg (for jpeg support"
41 "libjpeg-dev"
42 "librsvg2 (for viewing .svg images"
43 "librsvg2-common"
44 "libwmf (for viewing .wmf images)"
45 "libwmf0.2-7-gtk"
46 "exiftran (for image rotation)"
47 "exiftran"
48 "imagemagick (for image rotation)"
49 "imagemagick"
50 "ufraw (for RAW file handling)"
51 "ufraw"
52 "markdown (for generating README help file)"
53 "markdown"
54 )
55
56 # Optional for GTK3 only
57 optional_gtk3_array=(
58 "libchamplain gtk (for GPS maps)"
59 "libchamplain-gtk-0.12-dev"
60 "libchamplain (for GPS maps)"
61 "libchamplain-0.12-dev"
62 "libpoppler (for pdf file preview)"
63 "libpoppler-glib-dev"
64 )
65
66 # Optional pixbuf loaders
67 optional_loaders_array=(
68 ".webp WebP images"
69 "webp"
70 ".psd Photoshop images"
71 "psd"
72 ".xcf Gimp files"
73 "xcf"
74 )
75
76 ####################################################################
77 # Get System Info
78 # Derived from: https://github.com/coto/server-easy-install (GPL)
79 ####################################################################
80 lowercase()
81 {
82         echo "$1" | sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/"
83 }
84
85 systemProfile()
86 {
87         OS=`lowercase \`uname\``
88         KERNEL=`uname -r`
89         MACH=`uname -m`
90
91         if [ "${OS}" == "windowsnt" ]
92         then
93                 OS=windows
94         elif [ "${OS}" == "darwin" ]
95         then
96                 OS=mac
97         else
98                 OS=`uname`
99                 if [ "${OS}" = "SunOS" ]
100                 then
101                         OS=Solaris
102                         ARCH=`uname -p`
103                         OSSTR="${OS} ${REV}(${ARCH} `uname -v`)"
104                 elif [ "${OS}" = "AIX" ]
105                 then
106                         OSSTR="${OS} `oslevel` (`oslevel -r`)"
107                 elif [ "${OS}" = "Linux" ]
108                 then
109                         if [ -f /etc/redhat-release ]
110                         then
111                                 DistroBasedOn='RedHat'
112                                 DIST=`cat /etc/redhat-release |sed s/\ release.*//`
113                                 PSUEDONAME=`cat /etc/redhat-release | sed s/.*\(// | sed s/\)//`
114                                 REV=`cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//`
115                         elif [ -f /etc/SuSE-release ]
116                         then
117                                 DistroBasedOn='SuSe'
118                                 PSUEDONAME=`cat /etc/SuSE-release | tr "\n" ' '| sed s/VERSION.*//`
119                                 REV=`cat /etc/SuSE-release | tr "\n" ' ' | sed s/.*=\ //`
120                         elif [ -f /etc/mandrake-release ]
121                         then
122                                 DistroBasedOn='Mandrake'
123                                 PSUEDONAME=`cat /etc/mandrake-release | sed s/.*\(// | sed s/\)//`
124                                 REV=`cat /etc/mandrake-release | sed s/.*release\ // | sed s/\ .*//`
125                         elif [ -f /etc/debian_version ]
126                         then
127                                 DistroBasedOn='Debian'
128                                 if [ -f /etc/lsb-release ]
129                                 then
130                                         DIST=`cat /etc/lsb-release | grep '^DISTRIB_ID' | awk -F=  '{ print $2 }'`
131                                         PSUEDONAME=`cat /etc/lsb-release | grep '^DISTRIB_CODENAME' | awk -F=  '{ print $2 }'`
132                                         REV=`cat /etc/lsb-release | grep '^DISTRIB_RELEASE' | awk -F=  '{ print $2 }'`
133                                 fi
134                         fi
135                         if [ -f /etc/UnitedLinux-release ]
136                         then
137                                 DIST="${DIST}[`cat /etc/UnitedLinux-release | tr "\n" ' ' | sed s/VERSION.*//`]"
138                         fi
139                         OS=`lowercase $OS`
140                         DistroBasedOn=`lowercase $DistroBasedOn`
141                         readonly OS
142                         readonly DIST
143                         readonly DistroBasedOn
144                         readonly PSUEDONAME
145                         readonly REV
146                         readonly KERNEL
147                         readonly MACH
148                 fi
149         fi
150 }
151
152 install_essential()
153 {
154 arraylength=${#essential_array[@]}
155 for (( i=0; i<${arraylength}; i=i+1 ));
156 do
157         package_query ${essential_array[$i]}
158         if [ $? != 0 ]
159         then
160                 package_install ${essential_array[$i]}
161         fi
162 done
163
164 if [[ $1 == "GTK3" ]]
165 then
166         package_query "libgtk-3-dev"
167         if [ $? != 0 ]
168         then
169                 package_install libgtk-3-dev
170         fi
171 else
172         package_query "libgtk2.0-dev"
173         if [ $? != 0 ]
174         then
175                 package_install libgtk2.0-dev
176         fi
177 fi
178 }
179
180 install_options()
181 {
182 if [ -n "$options" ]
183 then
184         OLDIFS=$IFS
185         IFS='|'
186         set $options
187         while [ $# -gt 0 ];
188         do
189                 package_install $1
190                 shift
191         done
192         IFS=$OLDIFS
193 fi
194 }
195
196 install_webp()
197 {
198 rm -rf webp-pixbuf-loader-master
199 package_install libglib2.0-dev libgdk-pixbuf2.0-dev libwebp-dev python-minimal
200 wget https://github.com/aruiz/webp-pixbuf-loader/archive/master.zip
201 unzip master.zip
202 cd webp-pixbuf-loader-master
203 ./waf configure
204 ./waf build
205 sudo ./waf install
206 sudo gdk-pixbuf-query-loaders --update-cache
207 cd -
208 rm -rf webp-pixbuf-loader-master
209 rm master.zip
210 }
211
212 install_psd()
213 {
214 rm -rf gdk-pixbuf-psd
215 git clone https://github.com/and-rom/gdk-pixbuf-psd.git
216 cd gdk-pixbuf-psd
217 ./autogen.sh
218 make
219 sudo make install
220 sudo gdk-pixbuf-query-loaders --update-cache
221 cd -
222 rm -rf gdk-pixbuf-psd
223 }
224
225 install_xcf()
226 {
227 rm -rf xcf-pixbuf-loader
228 package_install libbz2-dev
229 git clone https://github.com/StephaneDelcroix/xcf-pixbuf-loader.git
230 cd xcf-pixbuf-loader
231 ./autogen.sh
232 make
233
234 # There must be a better way...
235 loader_locn=$(gdk-pixbuf-query-loaders | grep "LoaderDir"  | tr -d '#[:space:]')
236
237 OLDIFS=$IFS
238 IFS='='
239 set $loader_locn
240 OLDIFS=$IFS
241
242 if [ -d $2 ]
243 then
244         sudo cp .libs/libioxcf.so $2
245         sudo gdk-pixbuf-query-loaders --update-cache
246 fi
247 cd -
248 rm -rf  xcf-pixbuf-loader
249 }
250
251 install_extra_loaders()
252 {
253 if [ -n "$extra_loaders" ]
254 then
255         OLDIFS=$IFS
256         IFS='|'
257         set $extra_loaders
258         while [ $# -gt 0 ];
259         do
260                 case $1 in
261                 "webp" )
262                         install_webp
263                 ;;
264                 "psd" )
265                         install_psd
266                 ;;
267                 "xcf" )
268                         install_xcf
269                 ;;
270                 esac
271
272                 shift
273         done
274         IFS=$OLDIFS
275 fi
276 return
277 }
278
279 uninstall()
280 {
281 current_dir=$(basename $PWD)
282 if [[ $current_dir == "geeqie" ]]
283 then
284         sudo make uninstall
285         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
286
287         if [[ $? == 1 ]]
288         then
289                 cd ..
290                 sudo rm -rf geeqie
291         fi
292 else
293         zenity --title="Uninstall Geeqie" --width=370 --text="This is not a geeqie installation folder!\n\n$PWD" --warning  2>/dev/null
294 fi
295 exit
296 }
297
298 package_query()
299 {
300 if [[ $DistroBasedOn == "debian" ]]
301 then
302         res=$(dpkg-query --show --showformat='${Status}' $1  2>&1)
303         if [[ "$res" == "install ok installed"* ]]
304         then
305                 status=0
306         else
307                 status=1
308         fi
309 fi
310 return $status
311 }
312
313 package_install()
314 {
315 if [[ $DistroBasedOn == "debian" ]]
316 then
317         sudo apt-get --assume-yes install $@
318 fi
319 }
320
321 # Entry point
322
323 # Check system type
324 systemProfile
325 if [[ $DistroBasedOn != "debian" ]]
326 then
327         zenity --error --title="Install Geeqie and dependencies" --width=370 --text="Unknown operating system:\n
328 Operating System: $OS
329 Distribution: $DIST
330 Psuedoname: $PSUEDONAME
331 Revision: $REV
332 DistroBasedOn: $DistroBasedOn
333 Kernel: $KERNEL
334 Machine: $MACH" 2>/dev/null
335
336         exit
337 fi
338
339 # Parse the comand line
340 OPTS=$(getopt -o vhc:t:b: --long version,help,commit:,tag:,back: -- "$@")
341 eval set -- "$OPTS"
342
343 while true;
344 do
345         case "$1" in
346         -v | --version )
347                 echo "$version"
348                 exit
349                 ;;
350         -h | --help )
351                 echo "$description"
352                 exit
353                 ;;
354         -c | --commit )
355                 COMMIT="$2"
356                 shift
357                 shift
358                 ;;
359         -t | --tag )
360                 TAG="$2"
361                 shift;
362                 shift
363                 ;;
364         -b | --back )
365                 BACK="$2"
366                 shift;
367                 shift
368                 ;;
369         * ) break
370                 ;;
371         esac
372 done
373
374 # If a Geeqie folder already exists here, warn the user
375 if [ -d "geeqie" ]
376 then
377         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
378
379         exit
380 fi
381
382 # If it looks like a Geeqie download folder, assume an update
383 if [ -d ".git" ] && [ -d "src" ] && [ -f "geeqie.1" ]
384 then
385         mode="update"
386 else
387         # If it looks like something else is already installed here, warn the user
388         if [ -d ".git" ] || [ -d "src" ]
389         then
390                 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
391
392                 exit
393         else
394                 mode="install"
395         fi
396 fi
397
398 # Use GTK3 as default
399 gk2_installed=FALSE
400 gtk3_installed=TRUE
401
402 if [[ $mode == "install" ]]
403 then
404         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."
405
406         title="Install Geeqie and dependencies"
407         install_option=TRUE
408 else
409         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."
410
411         title="Update Geeqie and re-install"
412         install_option=FALSE
413
414         # When updating, use previous installation as default
415         if [[ -f config.log ]]
416         then
417                 grep gtk-2.0 config.log >/dev/null
418                 if [[ $? != 0 ]]
419                 then
420                         gtk2_installed=FALSE
421                         gtk3_installed=TRUE
422                 else
423                         gtk2_installed=TRUE
424                         gtk3_installed=FALSE
425                 fi
426         fi
427 fi
428
429 # Ask whether to install GTK2 or GTK3 or uninstall
430
431 gtk_version=$(zenity --title="$title" --width=370 --text="$message" --list --radiolist --column "" --column "" "$gtk3_installed" "GTK3 (required for GPS maps and pdf preview)" "$gtk2_installed" "GTK2" FALSE "Uninstall" --cancel-label="Cancel" --ok-label="OK" --hide-header 2>/dev/null)
432
433 if [[ $? == 1 ]]
434 then
435         exit
436 fi
437
438 if [[ $gtk_version == "Uninstall" ]]
439 then
440         uninstall
441         exit
442 fi
443
444 sleep 100 | zenity --title="$title" --text="Checking for installed files" --width=370 --progress --pulsate 2>/dev/null &
445 zen_pid=$!
446
447 # Get the standard options that are not yet installed
448 arraylength=${#optional_array[@]}
449 for (( i=0; i<${arraylength}; i=i+2 ));
450 do
451         package_query ${optional_array[$i+1]}
452         if [ $? != 0 ]
453         then
454                 if [ -z "$option_string" ]
455                 then
456                         option_string="$install_option"$'\n'"${optional_array[$i]}"$'\n'"${optional_array[$i+1]}"
457                 else
458                         option_string="$option_string"$'\n'"$install_option"$'\n'"${optional_array[$i]}"$'\n'"${optional_array[$i+1]}"
459                 fi
460         fi
461 done
462
463 # If GTK3 required, get the GTK3 options not yet installed
464 if [[ "$gtk_version" == "GTK3"* ]]
465 then
466         arraylength=${#optional_gtk3_array[@]}
467         for (( i=0; i<${arraylength}; i=i+2 ));
468         do
469                 package_query ${optional_gtk3_array[$i+1]}
470                 if [ $? != 0 ]
471                 then
472                         if [ -z "$option_string" ]
473                         then
474                                 option_string="$install_option"$'\n'"${optional_gtk3_array[$i]}"$'\n'"${optional_gtk3_array[$i+1]}"
475                         else
476                                 option_string="$option_string"$'\n'"$install_option"$'\n'"${optional_gtk3_array[$i]}"$'\n'"${optional_gtk3_array[$i+1]}"
477                         fi
478                 fi
479         done
480 fi
481
482 # Get the optional loaders not yet installed
483 ((i=0))
484 gdk-pixbuf-query-loaders | grep WebP >/dev/null
485 if [[ $? == 1 ]]
486 then
487         if [ -z "$loaders_string" ]
488         then
489                 loaders_string=$'FALSE\n'"${optional_loaders_array[$i]}"$'\n'"${optional_loaders_array[$i+1]}"
490         else
491                 loaders_string="$loaders_string"$'\nFALSE\n'"${optional_loaders_array[$i]}"$'\n'"${optional_loaders_array[$i+1]}"
492
493         fi
494 fi
495
496 ((i=i+2))
497 gdk-pixbuf-query-loaders | grep psd >/dev/null
498 if [[ $? == 1 ]]
499 then
500         if [ -z "$loaders_string" ]
501         then
502                 loaders_string=$'FALSE\n'"${optional_loaders_array[$i]}"$'\n'"${optional_loaders_array[$i+1]}"
503         else
504                 loaders_string="$loaders_string"$'\nFALSE\n'"${optional_loaders_array[$i]}"$'\n'"${optional_loaders_array[$i+1]}"
505         fi
506 fi
507
508 ((i=i+2))
509 gdk-pixbuf-query-loaders | grep xcf >/dev/null
510 if [[ $? == 1 ]]
511 then
512         if [ -z "$loaders_string" ]
513         then
514                 loaders_string=$'FALSE\n'"${optional_loaders_array[$i]}"$'\n'"${optional_loaders_array[$i+1]}"
515         else
516                 loaders_string="$loaders_string"$'\nFALSE\n'"${optional_loaders_array[$i]}"$'\n'"${optional_loaders_array[$i+1]}"
517         fi
518 fi
519
520 kill $zen_pid 2>/dev/null
521
522 # Ask the user which options to install
523 if [ -n "$option_string" ]
524 then
525         options=$(echo "$option_string" | zenity --title="$title" --width=400 --height=500 --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)
526
527         if [[ $? == 1 ]]
528         then
529                 exit
530         fi
531 fi
532
533 # Ask the user which extra loaders to install
534 if [ -n "$loaders_string" ]
535 then
536         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)
537
538         if [[ $? == 1 ]]
539         then
540                 exit
541         fi
542 fi
543
544 install_essential $gtk_version
545 install_options
546 install_extra_loaders
547
548 if [[ $mode == "install" ]]
549 then
550         ret=$(git clone git://www.geeqie.org/geeqie.git  2>&1 >/dev/null)
551 else
552         git checkout master
553         if [[ $? != 0 ]]
554         then
555                 zenity --title="$title" --width=370 --height=400 --error --text="Git checkout master error"  2>/dev/null
556                 exit
557         fi
558         ret=$(git pull 2>&1 >/dev/null)
559 fi
560
561 if [[ $? != 0 ]]
562 then
563         zenity --title="$title" --width=370 --height=400 --error --text="Git error:\n\n $ret" 2>/dev/null
564         exit
565 fi
566
567 if [[ $mode == "install" ]]
568 then
569         cd geeqie
570 else
571         sudo make uninstall
572         sudo make maintainer-clean
573 fi
574
575 if [[ "$BACK" ]]
576 then
577         ret=$(git checkout master~"$BACK" 2>&1 >/dev/null)
578         if [[ $1 != 0 ]]
579         then
580                 zenity --title="$title" --width=370 --height=400 --error --text="Git error:\n\n $ret" 2>/dev/null
581                 exit
582         fi
583 elif [[ "$COMMIT" ]]
584 then
585         ret=$(git checkout "$COMMIT" 2>&1 >/dev/null)
586         if [[ $1 != 0 ]]
587         then
588                 zenity --title="$title" --width=370 --height=400 --error --text="Git error:\n\n $ret" 2>/dev/null
589                 exit
590         fi
591 elif [[ "$TAG" ]]
592 then
593         ret=$(git checkout "$TAG" 2>&1 >/dev/null)
594         if [[ $1 != 0 ]]
595         then
596                 zenity --title="$title" --width=370 --height=400 --error --text="Git error:\n\n $ret" 2>/dev/null
597                 exit
598         fi
599 fi
600
601 if [[ $gtk_version == "GTK3"* ]]
602 then
603         ./autogen.sh
604 else
605         ./autogen.sh --disable-gtk3
606 fi
607
608 make -j
609 sudo make install
610
611 exit