linux installer tweak:
[ardour.git] / tools / linux_packaging / stage2.run.in
1 #!/bin/sh
2
3 ####################################
4 #
5 #       stage2.run
6 #       Ardour/Mixbus bundle installer
7 #       Todd Naugle
8 #
9 ###################################
10
11 MAJOR_VERSION="%REPLACE_MAJOR_VERSION%"
12
13 PGM_NAME="%REPLACE_PGM%"
14 PGM_VENDOR="%REPLACE_VENDOR%"
15 PGM_EXEC_FILE="%REPLACE_EXE%${MAJOR_VERSION}"
16
17 THE_SHELL="/bin/sh"
18
19 if test -z "$INSTALL_DEST_BASE"; then
20         INSTALL_DEST_BASE="/opt"
21         CALL_MKDIR=1
22 else
23         CALL_MKDIR=
24 fi
25
26 USER_BIN_DIR="/usr/local/bin"
27
28 PGM_NAME_LOWER=$(echo $PGM_NAME | tr '[:upper:]' '[:lower:]')
29
30 USER_NAME=$(logname)
31
32 #### Global Variables ####
33 HAS_XDG="T"
34
35 ########################
36 # Function Definitions
37 ########################
38
39 VaildateYesNoQuestion ()
40 {
41         # $1 = Question Text
42         
43         local INPUT_OK="n"
44         local USER_INPUT=""
45
46         until test "y" = $INPUT_OK;
47         do
48                 echo ""
49                 read -p "$1 [y/n]: " USER_INPUT
50                 echo ""
51
52                 if [ ! -z $USER_INPUT ]; 
53                 then            
54                         if [ "Y" = $USER_INPUT -o "y" = $USER_INPUT -o "n" = $USER_INPUT -o "N" = $USER_INPUT ];
55                         then
56                                 INPUT_OK="y"
57                         fi
58                 fi
59         done
60         
61         echo $USER_INPUT | tr '[:upper:]' '[:lower:]'
62         
63 }
64
65 SystemInstall ()
66 {
67
68         # Determine which software install app to use and then install requested package
69         # $1 = Package Name
70
71         if which yum > /dev/null;
72         then
73                 ${SUPER} yum -y install $1
74                 rtrn=$?
75
76                 if [ $rtrn -ne 0 ];
77                 then
78                         echo ""
79                         echo "!!! ERROR !!! yum install failed for an unknown reason."
80                         echo "Please install package $1 after this installer completes."
81                         echo ""
82                 fi
83
84         elif which apt-get > /dev/null;
85         then
86                 ${SUPER} apt-get -y install $1
87                 rtrn=$?
88
89                 if [ $rtrn -ne 0 ];
90                 then
91                         echo ""
92                         echo "!!! ERROR !!! apt-get install failed for an unknown reason."
93                         echo "Please install package $1 after this installer completes."
94                         echo ""
95                 fi
96
97         else
98                 echo ""
99                 echo "!!! ERROR !!! - Not able to detect which software install tool to use (yum or apt-get)."
100                 echo "Please install package $1 using the system software install tool."
101                 echo ""
102                 rtrn=1
103         fi
104         
105         return $rtrn
106
107 }
108
109 ########################################################################
110 #                                 Main
111 ########################################################################
112 umask 0022
113
114 # If you double click a script, some systems don't get the PWD correct.
115 # Force it to be correct
116 PKG_PATH=$(dirname "$(readlink -f "$0")")
117 cd "${PKG_PATH}"
118
119 echo ""
120 echo "Welcome to the ${PGM_NAME} installer"
121 echo ""
122 echo "${PGM_NAME} will be installed for user ${USER_NAME} in ${INSTALL_DEST_BASE}"
123 echo ""
124 #############################
125 # Check for root privileges
126 #############################
127
128 SUPER=""
129 NORM_USER=""
130
131 if [ "$(id -u)" != "0" ]; then
132
133         if ! which sudo > /dev/null;
134         then
135                 echo ""
136                 echo "Sudo installed failed, attempting to install using su"
137                 echo "Please enter root password below"
138                 echo ""
139
140                 if ! su -s $THE_SHELL -c "./.stage2.run";
141                 then
142                         echo ""
143                         echo "!!! ERROR !!!"
144                         echo ""
145                         echo "This installer requires root privileges. It is currently not"
146                         echo "running as root AND an attempt to use su failed."
147                         echo ""
148                         echo "Please correct this by installing and configuring sudo or running"
149                         echo "the installer as root (su -s $THE_SHELL -c)."
150                         echo ""
151                         read -p "Press ENTER to exit installer:" BLAH
152                         exit 1
153                 fi
154                 exit
155         else
156                 sudo -k # make sudo forget about cached credentials
157         fi
158
159         if ! sudo date;
160         then
161                 echo ""
162                 echo "Attempting to install using su"
163                 echo "Please enter root password below"
164                 echo ""
165
166                 if ! su -s $THE_SHELL -c "./.stage2.run";
167                 then
168                         echo ""
169                         echo "!!! ERROR !!!"
170                         echo ""
171                         echo "This installer requires root privileges. It is currently not"
172                         echo "running as root AND an attempt to use both sudo and su failed."
173                         echo ""
174                         echo "Please correct this by installing and configuring sudo or running"
175                         echo "the installer as root (su -s $THE_SHELL -c)."
176                         echo ""
177                         read -p "Press ENTER to exit installer:" BLAH
178                         exit 1
179                 fi
180                 exit
181         fi
182         SUPER="sudo"
183         
184         # The quoting reqired for the su sanityCheck method does not work when used without
185         # su. Using sh -c in the normal case gets around that, but is a bit of a hack.
186         NORM_USER="sh -c"
187 else
188         NORM_USER="su -l $USER_NAME -s $THE_SHELL -c" 
189 fi
190
191 ###############################
192 # Check for install destination
193 ###############################
194
195 if test -n "$CALL_MKDIR"; then
196         ${SUPER} mkdir -p "$INSTALL_DEST_BASE"
197 fi
198
199 if [ ! -d ${INSTALL_DEST_BASE} ];
200 then
201         echo ""
202         echo "!!! ERROR !!! - Installation location ${INSTALL_DEST_BASE} does not exist!"
203         echo "Installation will not complete."
204         echo ""
205         read -p "Press ENTER to exit installer:" BLAH
206         exit 1
207 fi
208
209
210 ############################
211 # Determine processor type
212 ############################
213
214 case `uname -m` in
215         i[3456789]86|x86|i86pc)
216                 echo "Architecture is x86"
217                 ARCH='x86'
218                 ;;
219         x86_64|amd64|AMD64)
220                 echo "Architecture is x86_64"
221                 ARCH='x86_64'
222                 ;;
223         *)
224                 echo ""
225                 echo "!!! ERROR !!! - Unknown architecture `uname -m`"
226                 echo ""
227                 read -p "Press ENTER to exit installer:" BLAH
228                 exit 1
229                 ;;
230 esac
231
232 ####################
233 # Check disk space
234 ####################
235
236 # We have to check the current folder and the INSTALL_DEST_BASE just
237 # in case they are on different devices
238 echo "Checking for required disk space"
239
240 if [ ! -e .${PGM_NAME}_${ARCH}-*.size ]; then
241         echo ""
242         echo "!!! ERROR !!! Can't locate .size file for ${ARCH} bundle."
243         echo "This package is broken or does not support ${ARCH}."
244         echo ""
245         read -p "Press ENTER to exit installer:" BLAH
246         exit 1
247 else
248         REQUIRED_BYTES=$(cat .${PGM_NAME}_${ARCH}-*.size)
249
250         #Installer needs 2x the space since the bundle is unpacked locally and then copied
251         REQUIRED_BYTES=$(($REQUIRED_BYTES + $REQUIRED_BYTES))
252
253         #Check space in current folder
254         FREE_BYTES=$(df -P -B 1 "${PKG_PATH}" | grep / | awk '{print $4}')
255
256         if [ ${FREE_BYTES} -le ${REQUIRED_BYTES} ] ; then
257                 echo ""
258                 echo "!!! ERROR !!! - Insufficient disk space in ${PKG_PATH}"
259                 echo "Install requires ${REQUIRED_BYTES} bytes and"
260                 echo "there is only ${FREE_BYTES} bytes of free space"
261                 echo ""
262                 read -p "Press ENTER to exit installer:" BLAH
263                 exit 1
264         fi
265
266         #Check space in INSTALL_DEST_BASE
267         FREE_BYTES=$(df -P -B 1 ${INSTALL_DEST_BASE} | grep / | awk '{print $4}')
268
269         if [ ${FREE_BYTES} -le ${REQUIRED_BYTES} ] ; then
270                 echo ""
271                 echo "!!! ERROR !!! - Insufficient disk space in ${INSTALL_DEST_BASE}"
272                 echo "Install requires ${REQUIRED_BYTES} bytes and"
273                 echo "there is only ${FREE_BYTES} bytes of free space"
274                 echo ""
275                 read -p "Press ENTER to exit installer:" BLAH
276                 exit 1
277         fi
278 fi
279
280 #############################
281 # Determine C11 stdlibc++ ABI
282 #############################
283
284 if %REPLACE_GCC5%; then
285         # Ardour was compiled with gcc5, warn on gcc4 systems
286         if ! ${NORM_USER} "${PKG_PATH}/.gcc-glibmm-abi-check --gcc5 > /dev/null"; then
287                 echo ""
288                 echo "WARNING: GCC4/5 libstdc++ ABI Mismatch"
289                 echo ""
290                 echo "Ardour was compiled with gcc5, your system uses an older version of the"
291                 echo "standard c++ library. Plugins on your system may not load or plugin-UIs"
292                 echo "may cause crashes."
293                 echo ""
294                 ANSWER=$(VaildateYesNoQuestion "Continue anyway?")
295                 if test "n" = $ANSWER; then
296                         exit 1
297                 fi
298         fi
299 else
300         # Ardour was compiled with gcc4, warn on gcc5 systems
301         if ! ${NORM_USER} "${PKG_PATH}/.gcc-glibmm-abi-check --gcc4 > /dev/null"; then
302                 echo ""
303                 echo "WARNING: GCC4/5 libstdc++ ABI Mismatch"
304                 echo ""
305                 echo "Ardour was compiled with gcc4, your system uses a newer version of the"
306                 echo "standard c++ library. Plugins on your system may not load or plugin-UIs"
307                 echo "may cause crashes."
308                 echo ""
309                 ANSWER=$(VaildateYesNoQuestion "Continue anyway?")
310                 if test "n" = $ANSWER; then
311                         exit 1
312                 fi
313         fi
314 fi
315
316 #####################
317 # Unpack the bundle
318 #####################
319
320 FILESYSTEM_TYPE=$(df -P -T "${PKG_PATH}" | grep / | awk '{print $2}')
321 echo "Bundle is on ${FILESYSTEM_TYPE} filesystem"
322
323 # untar the correct bundle for us to install
324 echo "Unpacking bundle for $ARCH"
325
326 if [ ! -e ${PGM_NAME}_${ARCH}-*.tar.bz2 ]; then
327         echo ""
328         echo "!!! ERROR !!! Can't locate ${ARCH} bundle file."
329         echo ""
330         read -p "Press ENTER to exit installer:" BLAH
331         exit 1
332 fi
333
334 if ! tar -xjf ${PGM_NAME}_${ARCH}-*.tar.bz2; then
335         echo ""
336         echo "!!! ERROR !!! Can't unpack ${ARCH} bundle file."
337         echo ""
338         read -p "Press ENTER to exit installer:" BLAH
339         exit 1
340 else
341         echo "Bundle unpacked"
342 fi
343
344 BUNDLE_DIR=$(basename `find -maxdepth 1 -type d -name "${PGM_NAME}_${ARCH}-*"`)
345
346
347 #######################
348 # Check for xdg utils
349 #######################
350
351 #load the file that contains the translated names of the users directories
352 if [ -e /home/${USER_NAME}/.config/user-dirs.dirs ]; then
353         . /home/${USER_NAME}/.config/user-dirs.dirs
354 fi
355
356 if [ "$(id -u)" != "0" ]; then
357         USER_DESKTOP_DIR=${XDG_DESKTOP_DIR:-$HOME/Desktop}
358 else
359         #running as root with su makes this more difficult
360         DESKTOP_FOLDER=$(echo ${XDG_DESKTOP_DIR:-$HOME/Desktop} | awk -F/ '{print $NF}')
361         USER_DESKTOP_DIR="/home/${USER_NAME}/${DESKTOP_FOLDER}"
362 fi
363
364 XDG_MENU_VER=$(xdg-desktop-menu --version 2> /dev/null)
365 if [ -z "$XDG_MENU_VER" ];
366 then
367         echo "System does not have xdg-desktop-menu installed"
368         HAS_XDG="F"
369 fi
370
371 XDG_ICON_VER=$(xdg-icon-resource --version 2> /dev/null)
372 if [ -z "$XDG_ICON_VER" ];
373 then
374         echo "System does not have xdg-icon-resource installed"
375         HAS_XDG="F"
376 fi
377
378 #################################################
379 # Check if system libs are OK (libc, etc)
380 #################################################
381
382 echo ""
383 echo "Checking system libs to see if they are compatible with ${PGM_NAME}."
384 echo ""
385
386 LIB_ERROR="F"
387 LD_PATH=`pwd`/${BUNDLE_DIR}/lib
388
389 # check the main App
390 LDD_RESULT=$(LD_LIBRARY_PATH=${LD_PATH} ldd ${BUNDLE_DIR}/bin/${PGM_NAME_LOWER}-* 2>&1 > /dev/null | grep -v "no version information")
391
392 if [ -n "$LDD_RESULT" ];
393 then
394         echo "$LDD_RESULT"
395         LIB_ERROR="T"
396 fi
397         
398 # check the libs
399 LIB_FILES=$(find ${BUNDLE_DIR}/lib -name "*.so")
400
401 for path in $LIB_FILES
402 do
403         LDD_RESULT=$(LD_LIBRARY_PATH=${LD_PATH} ldd $path 2>&1 > /dev/null | grep -v "no version information")
404         if [ -n "$LDD_RESULT" ];
405         then
406                 echo "$LDD_RESULT"
407                 LIB_ERROR="T"
408         fi
409 done
410
411 if test "T" = $LIB_ERROR;
412 then
413         echo ""
414         echo "!!! ERROR !!! - Missing library detected!"
415         echo "This system does not have the correct libs to run ${PGM_NAME}."
416         echo "Installation will not complete. Please use a compatible distro."
417         echo ""
418         read -p "Press ENTER to exit installer:" BLAH
419         exit 1
420 fi
421
422 ################################
423 # Setup derived variables
424 ################################
425 PGM_VERSION=$(echo ${BUNDLE_DIR} | cut -d- -f2)
426 PGM_BUILDTYPE=$(echo ${BUNDLE_DIR} | cut -d- -f3)
427
428 if [ -z ${PGM_BUILDTYPE} ];
429 then
430         PGM_FULL_NAME="${PGM_NAME}-${PGM_VERSION}"
431         ICON_NAME="${PGM_VENDOR}-${PGM_NAME}_${PGM_VERSION}"                    #no dash between name and version since dash seperates vendor from program
432         MENU_FILE="${PGM_VENDOR}-${PGM_NAME}_${PGM_VERSION}.desktop"    #no dash between name and version since dash seperates vendor from program
433         DESKTOP_LINK_FILE="${PGM_NAME}_${PGM_VERSION}.desktop"
434 else
435         PGM_FULL_NAME="${PGM_NAME}-${PGM_VERSION}-${PGM_BUILDTYPE}"
436         ICON_NAME="${PGM_VENDOR}-${PGM_NAME}_${PGM_VERSION}_${PGM_BUILDTYPE}"                   #no dash between name and version since dash seperates vendor from program
437         MENU_FILE="${PGM_VENDOR}-${PGM_NAME}_${PGM_VERSION}_${PGM_BUILDTYPE}.desktop"   #no dash between name and version since dash seperates vendor from program
438         DESKTOP_LINK_FILE="${PGM_NAME}_${PGM_VERSION}_${PGM_BUILDTYPE}.desktop"
439 fi
440
441 PGM_EXEC_PATH="${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/bin/${PGM_EXEC_FILE}"
442 ICON_PATH="${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/share/icons"
443 MENU_FILE_PATH="${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/share"
444
445 ################################
446 # Install bundle and Menu/Link
447 ################################
448
449 # uninstall any older versions
450 UNINSTALLERS=$(find ${INSTALL_DEST_BASE} -maxdepth 1 -type f -name "${PGM_NAME}*.uninstall.sh")
451 if [ ! -z "$UNINSTALLERS" ];
452 then
453         for i in $UNINSTALLERS; do
454                 echo ""
455                 echo "Found existing ${PGM_NAME} installation."
456                 
457                 ANSWER=$(VaildateYesNoQuestion "Do you want to run the uninstaller ${i} ?")
458
459                 if test "y" = $ANSWER;
460                 then
461                         echo ""
462                         echo "Running uninstaller $i"
463                         
464                         ${i}
465                         ${SUPER} rm -f ${i}
466                 fi
467         done
468 fi
469
470
471 # install 
472
473 echo ""
474 echo "Installing ${PGM_NAME} ${PGM_VERSION} in ${INSTALL_DEST_BASE}"
475 echo ""
476
477 # Copy the new version in the install directory
478 ${SUPER} mkdir ${INSTALL_DEST_BASE}/${PGM_FULL_NAME} 
479 ${SUPER} cp -Rf ${BUNDLE_DIR}/* ${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/
480
481 # write the desktop/menu file
482 echo "[Desktop Entry]" > /tmp/${MENU_FILE}
483 echo "Encoding=UTF-8" >> /tmp/${MENU_FILE}
484 echo "Version=1.0" >> /tmp/${MENU_FILE}
485 echo "Type=Application" >> /tmp/${MENU_FILE}
486 echo "Terminal=false" >> /tmp/${MENU_FILE}
487 echo "Exec=${PGM_EXEC_PATH}" >> /tmp/${MENU_FILE}
488 if [ -z ${PGM_BUILDTYPE} ];
489 then
490         echo "Name=${PGM_NAME}-${PGM_VERSION}" >> /tmp/${MENU_FILE}
491 else
492         echo "Name=${PGM_NAME}-${PGM_VERSION}-${PGM_BUILDTYPE}" >> /tmp/${MENU_FILE}
493 fi
494 echo "Icon=${ICON_NAME}" >> /tmp/${MENU_FILE}
495 echo "Comment=Digital Audio Workstation" >> /tmp/${MENU_FILE}
496 echo "Categories=AudioVideo;AudioEditing;Audio;Recorder;" >> /tmp/${MENU_FILE}
497
498 chmod ugo+rx /tmp/${MENU_FILE}
499 ${SUPER} mv /tmp/${MENU_FILE} ${MENU_FILE_PATH}/.
500
501 # install the Menu, Link, and Icon(s)
502 if [ "T" = ${HAS_XDG} ];
503 then
504         echo "Adding ${PGM_NAME} to the applications menu"
505         ${SUPER} xdg-icon-resource install --context apps --size 16 ${ICON_PATH}/${PGM_NAME_LOWER}_icon_16px.png ${ICON_NAME}
506         ${SUPER} xdg-icon-resource install --context apps --size 22 ${ICON_PATH}/${PGM_NAME_LOWER}_icon_22px.png ${ICON_NAME}
507         ${SUPER} xdg-icon-resource install --context apps --size 32 ${ICON_PATH}/${PGM_NAME_LOWER}_icon_32px.png ${ICON_NAME}
508         ${SUPER} xdg-icon-resource install --context apps --size 48 ${ICON_PATH}/${PGM_NAME_LOWER}_icon_48px.png ${ICON_NAME}
509         ${SUPER} xdg-icon-resource install --context apps --size 256 ${ICON_PATH}/${PGM_NAME_LOWER}_icon_256px.png ${ICON_NAME}
510
511         if [ -e ${ICON_PATH}/${PGM_NAME_LOWER}_icon.svg -a -d /usr/share/icons/hicolor/scalable/apps ]; 
512         then
513                 ${SUPER} cp -f ${ICON_PATH}/${PGM_NAME_LOWER}_icon.svg  /usr/share/icons/hicolor/scalable/apps/${ICON_NAME}.svg
514         fi
515
516         ${SUPER} xdg-desktop-menu install ${MENU_FILE_PATH}/${MENU_FILE}
517         ${SUPER} xdg-desktop-menu forceupdate --mode system                     # Some systems need an extra kick
518         
519         echo ""
520         echo "Creating a desktop link for ${PGM_NAME} in ${USER_DESKTOP_DIR}"
521         cp ${MENU_FILE_PATH}/${MENU_FILE} ${USER_DESKTOP_DIR}/${DESKTOP_LINK_FILE}
522         chmod ugo+rwx ${USER_DESKTOP_DIR}/${DESKTOP_LINK_FILE}
523 else
524         echo ""
525         echo "Creating a desktop link for ${PGM_NAME} in ${USER_DESKTOP_DIR}"
526         cp ${MENU_FILE_PATH}/${MENU_FILE} ${USER_DESKTOP_DIR}/${DESKTOP_LINK_FILE}
527         chmod ugo+rwx ${USER_DESKTOP_DIR}/${DESKTOP_LINK_FILE}
528 fi
529
530 echo ""
531 echo "Copying uninstall script to ${INSTALL_DEST_BASE}"
532 echo ""
533
534 ${SUPER} cp -f ${BUNDLE_DIR}/bin/*.uninstall.sh ${INSTALL_DEST_BASE}/.
535
536 # Create link to the program in user bin
537
538 echo ""
539 echo "Creating link ${PGM_NAME}${MAJOR_VERSION} in ${USER_BIN_DIR}"
540 echo ""
541
542 if [ -d "${USER_BIN_DIR}" ]; then
543         if [ -e "${USER_BIN_DIR}/${PGM_NAME}${MAJOR_VERSION}" ]; then
544                 ${SUPER} rm -f ${USER_BIN_DIR}/${PGM_NAME}${MAJOR_VERSION}
545         fi
546
547         cd "${USER_BIN_DIR}"
548         ${SUPER} ln -sf ${PGM_EXEC_PATH} ${PGM_NAME}${MAJOR_VERSION}
549         cd "${PKG_PATH}"
550         
551 else
552         echo "Can not create link because ${USER_BIN_DIR} does not exist"
553 fi
554
555 ###########################
556 # Check Jack and qjackctl
557 ###########################
558
559 echo ""
560 echo "Checking to see if Jack is installed"
561 echo ""
562
563 JACK_INSTALLED="f"
564
565 if which jackd > /dev/null; then
566         JACK_INSTALLED="t"
567         echo "Jack already present"
568 elif which jackdbus > /dev/null; then
569         echo ""
570         echo "jackdbus was found but not jackd. Jack version compatibility check cannot be performed."
571         echo ""
572         JACK_INSTALLED="i"
573 else
574         echo ""
575         echo "The program Jack is missing from this system. Jack is a required component of $PGM_NAME."
576         echo ""
577
578         ANSWER=$(VaildateYesNoQuestion "Install jack using system software repository?")
579
580         if test "y" = $ANSWER;
581         then
582                 echo "Attempting to install Jack"
583                 SystemInstall "jackd"
584                 
585                 if [ $? -ne 0 ];
586                 then
587                         echo ""
588                         read -p "Press ENTER to continue:" BLAH
589                 else
590                         JACK_INSTALLED="t"
591                 fi
592         fi
593 fi
594
595 # Check to see if Jack is new enough to operate correctly.
596
597 if [ "t" = ${JACK_INSTALLED} ];
598 then
599         JACK_VERSION_OK="f"
600         JACK_VER_STRING=$(jackd --version | grep -e "jackd.*protocol")
601         JACK_NAME=$(echo $JACK_VER_STRING | awk '{print $1}')
602         JACK_VERSION=$(echo $JACK_VER_STRING | awk '{print $3}')
603         JACK_VERSION_MAJOR=$(echo $JACK_VERSION | awk 'BEGIN{FS="."}{print $1}')
604         JACK_VERSION_MIDDLE=$(echo $JACK_VERSION | awk 'BEGIN{FS="."}{print $2}')
605         JACK_VERSION_MINOR=$(echo $JACK_VERSION | awk 'BEGIN{FS="."}{print $3}')
606
607         if [ "jackd" = ${JACK_NAME} ];
608         then
609                 if [ ${JACK_VERSION_MAJOR} -eq 0 ];
610                 then
611                         if [ ${JACK_VERSION_MIDDLE} -eq 121 ];
612                         then
613                                 if [ ${JACK_VERSION_MINOR} -ge 3 ];
614                                 then
615                                         JACK_VERSION_OK="t"
616                                 fi
617                         elif [ ${JACK_VERSION_MIDDLE} -gt 121 ];
618                         then
619                                 JACK_VERSION_OK="t"
620                         fi
621                 elif [ ${JACK_VERSION_MAJOR} -gt 0 ];
622                 then
623                         JACK_VERSION_OK="t"
624                 fi
625         elif [ "jackdmp" = ${JACK_NAME} ];
626         then
627                 if [ ${JACK_VERSION_MAJOR} -eq 1 ];
628                 then
629                         if [ ${JACK_VERSION_MIDDLE} -eq 9 ];
630                         then
631                                 if [ ${JACK_VERSION_MINOR} -ge 8 ];
632                                 then
633                                         JACK_VERSION_OK="t"
634                                 fi
635                         elif [ ${JACK_VERSION_MIDDLE} -gt 9 ];
636                         then
637                                 JACK_VERSION_OK="t"
638                         fi
639                 elif [ ${JACK_VERSION_MAJOR} -gt 1 ];
640                 then
641                         JACK_VERSION_OK="t"
642                 fi
643         fi
644
645         if [ "t" = ${JACK_VERSION_OK} ];
646         then
647                 echo ""
648                 echo "Jack Version Check OK (${JACK_VER_STRING})"
649                 echo ""
650         else
651                 echo ""
652                 echo "!!! WARNING !!! - The version of Jack on this system is too old!"
653                 echo "Using an old version of Jack is not recommended. Please update"
654                 echo "Jack for best results."
655                 echo ""
656                 echo "System Jack version:"
657                 echo "   ${JACK_VER_STRING}"
658                 echo ""
659                 echo "Recommended minimum versions:"
660                 echo "   Jack1 - 0.121.3"
661                 echo "   Jack2 - 1.9.8"
662                 echo ""
663                 read -p "Press ENTER to continue:" BLAH
664         fi
665 fi
666
667 if ! which qjackctl > /dev/null;
668 then
669         echo ""
670         echo "The program QjackCtl is missing from this system."
671         echo "QjackCtl is an extremely useful tool for any system that runs JACK applications like $PGM_NAME."
672         echo "We recommend that you install it."
673         echo ""
674
675         ANSWER=$(VaildateYesNoQuestion "Install QjackCtl using system software repository?")
676
677         if test "y" = $ANSWER;
678         then
679                 echo "Attempting to install QjackCtl"
680                 SystemInstall "qjackctl"
681
682                 if [ $? -ne 0 ];
683                 then
684                         echo ""
685                         read -p "Press ENTER to continue:" BLAH
686                 fi
687         fi
688 fi
689
690
691 ########################
692 # Run Sanity Check
693 ########################
694
695 USER_GROUP_ADJUSTED="f"
696
697 if ! ${NORM_USER} "${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/bin/sanityCheck -a > /dev/null";
698 then
699         echo ""
700         echo "System failed the quick sanity check... Looking for the cause"
701
702         if ! ${NORM_USER} "${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/bin/sanityCheck -rt > /dev/null";
703         then
704                 echo ""
705                 echo "System does not allow realtime for the current user... Looking for a solution"            
706                 
707                 if ${NORM_USER} "${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/bin/sanityCheck -hasaudiogroup > /dev/null";
708                 then
709                         if ${NORM_USER} "${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/bin/sanityCheck -memberaudiogroup > /dev/null 2>&1";
710                         then
711                                 ## This is an odd case. We have an audio group and are a member.
712                                 echo ""
713                                 echo "!!! WARNING !!! - The current user can not execute realtime processes."
714                                 echo "This will adversely affect audio latency."
715                                 echo "This system has an audio group and the user is a member. If jack was"
716                                 echo "just installed, a simple log out/in may fix this."
717                                 echo ""
718                                 echo "For best results, please correct this on your system."
719                                 echo "(Hint: check /etc/security/limits.conf or /etc/security/limits.d/)" 
720                                 echo ""
721                                 read -p "Press ENTER to continue:" BLAH
722                         else
723                                 # Not a member of an audio group. Try to fix it.
724                                 
725                                 if ${NORM_USER} "${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/bin/sanityCheck -hasgroup audio > /dev/null && find /etc/security -type f -name "*.conf" | xargs grep -q "^@audio.*rtprio" ";
726                                 then
727                                         # add user to audio group
728                                         echo ""
729                                         echo "Adding user ${USER_NAME} to the audio group."
730                                         echo "This should allow you to run realtime tasks. Please re-login for this change to take affect."
731                                         echo ""
732                                         read -p "Press ENTER to continue:" BLAH
733
734                                         if ${SUPER} usermod -a -G audio ${USER_NAME};
735                                         then
736                                                 USER_GROUP_ADJUSTED="t"
737                                         else
738                                                 echo ""
739                                                 echo "!!! ERROR !!! - Not able to add user to the audio group (usermod failed)!"
740                                                 echo ""
741                                                 echo "Please add yourself to the audio group and re-login"
742                                                 echo ""
743                                                 read -p "Press ENTER to continue:" BLAH
744                                         fi
745
746                                 elif ${NORM_USER} "${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/bin/sanityCheck -hasgroup jackuser > /dev/null && find /etc/security -type f -name "*.conf" | xargs grep -q "^@jackuser.*rtprio" ";
747                                 then
748                                         # add user to jackuser group
749                                         echo ""
750                                         echo "Adding user ${USER_NAME} to the jackuser group."
751                                         echo "This should allow you to run realtime tasks. Please re-login for this change to take affect."
752                                         echo ""
753                                         read -p "Press ENTER to continue:" BLAH
754
755                                         if ${SUPER} usermod -a -G jackuser ${USER_NAME};
756                                         then
757                                                 USER_GROUP_ADJUSTED="t"
758                                         else
759                                                 echo ""
760                                                 echo "!!! ERROR !!! - Not able to add user to the jackuser group."
761                                                 echo ""
762                                                 echo "Please add yourself to the audio group and re-login"
763                                                 echo ""
764                                                 read -p "Press ENTER to continue:" BLAH
765                                         fi
766                                         
767
768                                 fi
769                         fi
770                 else
771                         # No audio group found on this system!
772                         echo ""
773                         echo "!!! WARNING !!! - The system does not seem to have an audio group (audio or jackuser)."
774                         echo ""
775                         echo "We will not attempt to fix this. Please configure your system to allow"
776                         echo "non-root users to execute realtime tasks."
777                         echo ""
778                         read -p "Press ENTER to continue:" BLAH
779                 fi
780         fi
781
782         if ! ${NORM_USER} "${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/bin/sanityCheck -freqscaling > /dev/null";
783         then
784                 echo ""
785                 echo "!!! WARNING !!! - Your system seems to use frequency scaling."
786                 echo "This can have a serious impact on audio latency."
787                 echo "For best results turn it off, e.g. by chosing the 'performance' governor."
788                 echo ""
789                 read -p "Press ENTER to continue:" BLAH
790         fi
791
792         if [ "f" = $USER_GROUP_ADJUSTED ];
793         then
794                 if ! ${NORM_USER} "${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/bin/sanityCheck -memlock > /dev/null";
795                 then
796                         echo ""
797                         echo "!!! WARNING !!! - You are not allowed to lock memory."
798                         echo ""
799                         echo "We will not attempt to fix this. Please configure your system to allow"
800                         echo "non-root users to execute lock memory."
801                         echo ""
802                         read -p "Press ENTER to continue:" BLAH
803                 fi
804         fi
805 fi
806
807
808 ########################
809 # Install Complete
810 ########################
811
812 echo ""
813 echo "Cleaning up"
814 rm -rf ${BUNDLE_DIR}/
815
816 echo ""
817 echo "!!! Install Complete !!!"
818
819 if [ "t" = $USER_GROUP_ADJUSTED ];
820 then
821         echo "You will need to logout and then login again for all changes to be complete"
822 fi
823
824 echo ""
825 read -p "Press ENTER to exit installer:" BLAH
826
827