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