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