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