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