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