ignore ldd warnings version during installation
[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 FILESYSTEM_TYPE=$(df -P -T "${PKG_PATH}" | grep / | awk '{print $2}')
281 echo "Bundle is on ${FILESYSTEM_TYPE} filesystem"
282
283 #####################
284 # Unpack the bundle
285 #####################
286
287 # untar the correct bundle for us to install
288 echo "Unpacking bundle for $ARCH"
289
290 if [ ! -e ${PGM_NAME}_${ARCH}-*.tar.bz2 ]; then
291         echo ""
292         echo "!!! ERROR !!! Can't locate ${ARCH} bundle file."
293         echo ""
294         read -p "Press ENTER to exit installer:" BLAH
295         exit 1
296 fi
297
298 if ! tar -xjf ${PGM_NAME}_${ARCH}-*.tar.bz2; then
299         echo ""
300         echo "!!! ERROR !!! Can't unpack ${ARCH} bundle file."
301         echo ""
302         read -p "Press ENTER to exit installer:" BLAH
303         exit 1
304 else
305         echo "Bundle unpacked"
306 fi
307
308 BUNDLE_DIR=$(basename `find -maxdepth 1 -type d -name "${PGM_NAME}_${ARCH}-*"`)
309
310
311 #######################
312 # Check for xdg utils
313 #######################
314
315 #load the file that contains the translated names of the users directories
316 if [ -e /home/${USER_NAME}/.config/user-dirs.dirs ]; then
317         . /home/${USER_NAME}/.config/user-dirs.dirs
318 fi
319
320 if [ "$(id -u)" != "0" ]; then
321         USER_DESKTOP_DIR=${XDG_DESKTOP_DIR:-$HOME/Desktop}
322 else
323         #running as root with su makes this more difficult
324         DESKTOP_FOLDER=$(echo ${XDG_DESKTOP_DIR:-$HOME/Desktop} | awk -F/ '{print $NF}')
325         USER_DESKTOP_DIR="/home/${USER_NAME}/${DESKTOP_FOLDER}"
326 fi
327
328 XDG_MENU_VER=$(xdg-desktop-menu --version 2> /dev/null)
329 if [ -z "$XDG_MENU_VER" ];
330 then
331         echo "System does not have xdg-desktop-menu installed"
332         HAS_XDG="F"
333 fi
334
335 XDG_ICON_VER=$(xdg-icon-resource --version 2> /dev/null)
336 if [ -z "$XDG_ICON_VER" ];
337 then
338         echo "System does not have xdg-icon-resource installed"
339         HAS_XDG="F"
340 fi
341
342 #################################################
343 # Check if system libs are OK (libc, etc)
344 #################################################
345
346 echo ""
347 echo "Checking system libs to see if they are compatible with ${PGM_NAME}."
348 echo ""
349
350 LIB_ERROR="F"
351 LD_PATH=`pwd`/${BUNDLE_DIR}/lib
352
353 # check the main App
354 LDD_RESULT=$(LD_LIBRARY_PATH=${LD_PATH} ldd ${BUNDLE_DIR}/bin/${PGM_NAME_LOWER}-* 2>&1 > /dev/null | grep -v "no version information")
355
356 if [ -n "$LDD_RESULT" ];
357 then
358         echo "$LDD_RESULT"
359         LIB_ERROR="T"
360 fi
361         
362 # check the libs
363 LIB_FILES=$(find ${BUNDLE_DIR}/lib -name "*.so")
364
365 for path in $LIB_FILES
366 do
367         LDD_RESULT=$(LD_LIBRARY_PATH=${LD_PATH} ldd $path 2>&1 > /dev/null | grep -v "no version information")
368         if [ -n "$LDD_RESULT" ];
369         then
370                 echo "$LDD_RESULT"
371                 LIB_ERROR="T"
372         fi
373 done
374
375 if test "T" = $LIB_ERROR;
376 then
377         echo ""
378         echo "!!! ERROR !!! - Missing library detected!"
379         echo "This system does not have the correct libs to run ${PGM_NAME}."
380         echo "Installation will not complete. Please use a compatible distro."
381         echo ""
382         read -p "Press ENTER to exit installer:" BLAH
383         exit 1
384 fi
385
386 ################################
387 # Setup derived variables
388 ################################
389 PGM_VERSION=$(echo ${BUNDLE_DIR} | cut -d- -f2)
390 PGM_BUILDTYPE=$(echo ${BUNDLE_DIR} | cut -d- -f3)
391
392 if [ -z ${PGM_BUILDTYPE} ];
393 then
394         PGM_FULL_NAME="${PGM_NAME}-${PGM_VERSION}"
395         ICON_NAME="${PGM_VENDOR}-${PGM_NAME}_${PGM_VERSION}"                    #no dash between name and version since dash seperates vendor from program
396         MENU_FILE="${PGM_VENDOR}-${PGM_NAME}_${PGM_VERSION}.desktop"    #no dash between name and version since dash seperates vendor from program
397         DESKTOP_LINK_FILE="${PGM_NAME}_${PGM_VERSION}.desktop"
398 else
399         PGM_FULL_NAME="${PGM_NAME}-${PGM_VERSION}-${PGM_BUILDTYPE}"
400         ICON_NAME="${PGM_VENDOR}-${PGM_NAME}_${PGM_VERSION}_${PGM_BUILDTYPE}"                   #no dash between name and version since dash seperates vendor from program
401         MENU_FILE="${PGM_VENDOR}-${PGM_NAME}_${PGM_VERSION}_${PGM_BUILDTYPE}.desktop"   #no dash between name and version since dash seperates vendor from program
402         DESKTOP_LINK_FILE="${PGM_NAME}_${PGM_VERSION}_${PGM_BUILDTYPE}.desktop"
403 fi
404
405 PGM_EXEC_PATH="${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/bin/${PGM_EXEC_FILE}"
406 ICON_PATH="${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/share/icons"
407 MENU_FILE_PATH="${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/share"
408
409 ################################
410 # Install bundle and Menu/Link
411 ################################
412
413 # uninstall any older versions
414 UNINSTALLERS=$(find ${INSTALL_DEST_BASE} -maxdepth 1 -type f -name "${PGM_NAME}*.uninstall.sh")
415 if [ ! -z "$UNINSTALLERS" ];
416 then
417         for i in $UNINSTALLERS; do
418                 echo ""
419                 echo "Found existing ${PGM_NAME} installation."
420                 
421                 ANSWER=$(VaildateYesNoQuestion "Do you want to run the uninstaller ${i} ?")
422
423                 if test "y" = $ANSWER;
424                 then
425                         echo ""
426                         echo "Running uninstaller $i"
427                         
428                         ${i}
429                         ${SUPER} rm -f ${i}
430                 fi
431         done
432 fi
433
434
435 # install 
436
437 echo ""
438 echo "Installing ${PGM_NAME} ${PGM_VERSION} in ${INSTALL_DEST_BASE}"
439 echo ""
440
441 # Copy the new version in the install directory
442 ${SUPER} mkdir ${INSTALL_DEST_BASE}/${PGM_FULL_NAME} 
443 ${SUPER} cp -Rf ${BUNDLE_DIR}/* ${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/
444
445 # write the desktop/menu file
446 echo "[Desktop Entry]" > /tmp/${MENU_FILE}
447 echo "Encoding=UTF-8" >> /tmp/${MENU_FILE}
448 echo "Version=1.0" >> /tmp/${MENU_FILE}
449 echo "Type=Application" >> /tmp/${MENU_FILE}
450 echo "Terminal=false" >> /tmp/${MENU_FILE}
451 echo "Exec=${PGM_EXEC_PATH}" >> /tmp/${MENU_FILE}
452 if [ -z ${PGM_BUILDTYPE} ];
453 then
454         echo "Name=${PGM_NAME}-${PGM_VERSION}" >> /tmp/${MENU_FILE}
455 else
456         echo "Name=${PGM_NAME}-${PGM_VERSION}-${PGM_BUILDTYPE}" >> /tmp/${MENU_FILE}
457 fi
458 echo "Icon=${ICON_NAME}" >> /tmp/${MENU_FILE}
459 echo "Comment=Digital Audio Workstation" >> /tmp/${MENU_FILE}
460 echo "Categories=AudioVideo;AudioEditing;Audio;Recorder;" >> /tmp/${MENU_FILE}
461
462 chmod ugo+rx /tmp/${MENU_FILE}
463 ${SUPER} mv /tmp/${MENU_FILE} ${MENU_FILE_PATH}/.
464
465 # install the Menu, Link, and Icon(s)
466 if [ "T" = ${HAS_XDG} ];
467 then
468         echo "Adding ${PGM_NAME} to the applications menu"
469         ${SUPER} xdg-icon-resource install --context apps --size 16 ${ICON_PATH}/${PGM_NAME_LOWER}_icon_16px.png ${ICON_NAME}
470         ${SUPER} xdg-icon-resource install --context apps --size 22 ${ICON_PATH}/${PGM_NAME_LOWER}_icon_22px.png ${ICON_NAME}
471         ${SUPER} xdg-icon-resource install --context apps --size 32 ${ICON_PATH}/${PGM_NAME_LOWER}_icon_32px.png ${ICON_NAME}
472         ${SUPER} xdg-icon-resource install --context apps --size 48 ${ICON_PATH}/${PGM_NAME_LOWER}_icon_48px.png ${ICON_NAME}
473         ${SUPER} xdg-icon-resource install --context apps --size 256 ${ICON_PATH}/${PGM_NAME_LOWER}_icon_256px.png ${ICON_NAME}
474
475         if [ -e ${ICON_PATH}/${PGM_NAME_LOWER}_icon.svg -a -d /usr/share/icons/hicolor/scalable/apps ]; 
476         then
477                 ${SUPER} cp -f ${ICON_PATH}/${PGM_NAME_LOWER}_icon.svg  /usr/share/icons/hicolor/scalable/apps/${ICON_NAME}.svg
478         fi
479
480         ${SUPER} xdg-desktop-menu install ${MENU_FILE_PATH}/${MENU_FILE}
481         ${SUPER} xdg-desktop-menu forceupdate --mode system                     # Some systems need an extra kick
482         
483         echo ""
484         echo "Creating a desktop link for ${PGM_NAME} in ${USER_DESKTOP_DIR}"
485         cp ${MENU_FILE_PATH}/${MENU_FILE} ${USER_DESKTOP_DIR}/${DESKTOP_LINK_FILE}
486         chmod ugo+rwx ${USER_DESKTOP_DIR}/${DESKTOP_LINK_FILE}
487 else
488         echo ""
489         echo "Creating a desktop link for ${PGM_NAME} in ${USER_DESKTOP_DIR}"
490         cp ${MENU_FILE_PATH}/${MENU_FILE} ${USER_DESKTOP_DIR}/${DESKTOP_LINK_FILE}
491         chmod ugo+rwx ${USER_DESKTOP_DIR}/${DESKTOP_LINK_FILE}
492 fi
493
494 echo ""
495 echo "Copying uninstall script to ${INSTALL_DEST_BASE}"
496 echo ""
497
498 ${SUPER} cp -f ${BUNDLE_DIR}/bin/*.uninstall.sh ${INSTALL_DEST_BASE}/.
499
500 # Create link to the program in user bin
501
502 echo ""
503 echo "Creating link ${PGM_NAME}${MAJOR_VERSION} in ${USER_BIN_DIR}"
504 echo ""
505
506 if [ -d "${USER_BIN_DIR}" ]; then
507         if [ -e "${USER_BIN_DIR}/${PGM_NAME}${MAJOR_VERSION}" ]; then
508                 ${SUPER} rm -f ${USER_BIN_DIR}/${PGM_NAME}${MAJOR_VERSION}
509         fi
510
511         cd "${USER_BIN_DIR}"
512         ${SUPER} ln -sf ${PGM_EXEC_PATH} ${PGM_NAME}${MAJOR_VERSION}
513         cd "${PKG_PATH}"
514         
515 else
516         echo "Can not create link because ${USER_BIN_DIR} does not exist"
517 fi
518
519 ###########################
520 # Check Jack and qjackctl
521 ###########################
522
523 echo ""
524 echo "Checking to see if Jack is installed"
525 echo ""
526
527 JACK_INSTALLED="f"
528
529 if which jackd > /dev/null; then
530         JACK_INSTALLED="t"
531         echo "Jack already present"
532 elif which jackdbus > /dev/null; then
533         echo ""
534         echo "jackdbus was found but not jackd. Jack version compatibility check cannot be performed."
535         echo ""
536         JACK_INSTALLED="i"
537 else
538         echo ""
539         echo "The program Jack is missing from this system. Jack is a required component of $PGM_NAME."
540         echo ""
541
542         ANSWER=$(VaildateYesNoQuestion "Install jack using system software repository?")
543
544         if test "y" = $ANSWER;
545         then
546                 echo "Attempting to install Jack"
547                 SystemInstall "jackd"
548                 
549                 if [ $? -ne 0 ];
550                 then
551                         echo ""
552                         read -p "Press ENTER to continue:" BLAH
553                 else
554                         JACK_INSTALLED="t"
555                 fi
556         fi
557 fi
558
559 # Check to see if Jack is new enough to operate correctly.
560
561 if [ "t" = ${JACK_INSTALLED} ];
562 then
563         JACK_VERSION_OK="f"
564         JACK_VER_STRING=$(jackd --version | grep -e "jackd.*protocol")
565         JACK_NAME=$(echo $JACK_VER_STRING | awk '{print $1}')
566         JACK_VERSION=$(echo $JACK_VER_STRING | awk '{print $3}')
567         JACK_VERSION_MAJOR=$(echo $JACK_VERSION | awk 'BEGIN{FS="."}{print $1}')
568         JACK_VERSION_MIDDLE=$(echo $JACK_VERSION | awk 'BEGIN{FS="."}{print $2}')
569         JACK_VERSION_MINOR=$(echo $JACK_VERSION | awk 'BEGIN{FS="."}{print $3}')
570
571         if [ "jackd" = ${JACK_NAME} ];
572         then
573                 if [ ${JACK_VERSION_MAJOR} -eq 0 ];
574                 then
575                         if [ ${JACK_VERSION_MIDDLE} -eq 121 ];
576                         then
577                                 if [ ${JACK_VERSION_MINOR} -ge 3 ];
578                                 then
579                                         JACK_VERSION_OK="t"
580                                 fi
581                         elif [ ${JACK_VERSION_MIDDLE} -gt 121 ];
582                         then
583                                 JACK_VERSION_OK="t"
584                         fi
585                 elif [ ${JACK_VERSION_MAJOR} -gt 0 ];
586                 then
587                         JACK_VERSION_OK="t"
588                 fi
589         elif [ "jackdmp" = ${JACK_NAME} ];
590         then
591                 if [ ${JACK_VERSION_MAJOR} -eq 1 ];
592                 then
593                         if [ ${JACK_VERSION_MIDDLE} -eq 9 ];
594                         then
595                                 if [ ${JACK_VERSION_MINOR} -ge 8 ];
596                                 then
597                                         JACK_VERSION_OK="t"
598                                 fi
599                         elif [ ${JACK_VERSION_MIDDLE} -gt 9 ];
600                         then
601                                 JACK_VERSION_OK="t"
602                         fi
603                 elif [ ${JACK_VERSION_MAJOR} -gt 1 ];
604                 then
605                         JACK_VERSION_OK="t"
606                 fi
607         fi
608
609         if [ "t" = ${JACK_VERSION_OK} ];
610         then
611                 echo ""
612                 echo "Jack Version Check OK (${JACK_VER_STRING})"
613                 echo ""
614         else
615                 echo ""
616                 echo "!!! WARNING !!! - The version of Jack on this system is too old!"
617                 echo "Using an old version of Jack is not recommended. Please update"
618                 echo "Jack for best results."
619                 echo ""
620                 echo "System Jack version:"
621                 echo "   ${JACK_VER_STRING}"
622                 echo ""
623                 echo "Recommended minimum versions:"
624                 echo "   Jack1 - 0.121.3"
625                 echo "   Jack2 - 1.9.8"
626                 echo ""
627                 read -p "Press ENTER to continue:" BLAH
628         fi
629 fi
630
631 if ! which qjackctl > /dev/null;
632 then
633         echo ""
634         echo "The program QjackCtl is missing from this system."
635         echo "QjackCtl is an extremely useful tool for any system that runs JACK applications like $PGM_NAME."
636         echo "We recommend that you install it."
637         echo ""
638
639         ANSWER=$(VaildateYesNoQuestion "Install QjackCtl using system software repository?")
640
641         if test "y" = $ANSWER;
642         then
643                 echo "Attempting to install QjackCtl"
644                 SystemInstall "qjackctl"
645
646                 if [ $? -ne 0 ];
647                 then
648                         echo ""
649                         read -p "Press ENTER to continue:" BLAH
650                 fi
651         fi
652 fi
653
654
655 ########################
656 # Run Sanity Check
657 ########################
658
659 USER_GROUP_ADJUSTED="f"
660
661 if ! ${NORM_USER} "${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/bin/sanityCheck -a > /dev/null";
662 then
663         echo ""
664         echo "System failed the quick sanity check... Looking for the cause"
665
666         if ! ${NORM_USER} "${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/bin/sanityCheck -rt > /dev/null";
667         then
668                 echo ""
669                 echo "System does not allow realtime for the current user... Looking for a solution"            
670                 
671                 if ${NORM_USER} "${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/bin/sanityCheck -hasaudiogroup > /dev/null";
672                 then
673                         if ${NORM_USER} "${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/bin/sanityCheck -memberaudiogroup > /dev/null 2>&1";
674                         then
675                                 ## This is an odd case. We have an audio group and are a member.
676                                 echo ""
677                                 echo "!!! WARNING !!! - The current user can not execute realtime processes."
678                                 echo "This will adversely affect audio latency."
679                                 echo "This system has an audio group and the user is a member. If jack was"
680                                 echo "just installed, a simple log out/in may fix this."
681                                 echo ""
682                                 echo "For best results, please correct this on your system."
683                                 echo "(Hint: check /etc/security/limits.conf or /etc/security/limits.d/)" 
684                                 echo ""
685                                 read -p "Press ENTER to continue:" BLAH
686                         else
687                                 # Not a member of an audio group. Try to fix it.
688                                 
689                                 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" ";
690                                 then
691                                         # add user to audio group
692                                         echo ""
693                                         echo "Adding user ${USER_NAME} to the audio group."
694                                         echo "This should allow you to run realtime tasks. Please re-login for this change to take affect."
695                                         echo ""
696                                         read -p "Press ENTER to continue:" BLAH
697
698                                         if ${SUPER} usermod -a -G audio ${USER_NAME};
699                                         then
700                                                 USER_GROUP_ADJUSTED="t"
701                                         else
702                                                 echo ""
703                                                 echo "!!! ERROR !!! - Not able to add user to the audio group (usermod failed)!"
704                                                 echo ""
705                                                 echo "Please add yourself to the audio group and re-login"
706                                                 echo ""
707                                                 read -p "Press ENTER to continue:" BLAH
708                                         fi
709
710                                 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" ";
711                                 then
712                                         # add user to jackuser group
713                                         echo ""
714                                         echo "Adding user ${USER_NAME} to the jackuser group."
715                                         echo "This should allow you to run realtime tasks. Please re-login for this change to take affect."
716                                         echo ""
717                                         read -p "Press ENTER to continue:" BLAH
718
719                                         if ${SUPER} usermod -a -G jackuser ${USER_NAME};
720                                         then
721                                                 USER_GROUP_ADJUSTED="t"
722                                         else
723                                                 echo ""
724                                                 echo "!!! ERROR !!! - Not able to add user to the jackuser group."
725                                                 echo ""
726                                                 echo "Please add yourself to the audio group and re-login"
727                                                 echo ""
728                                                 read -p "Press ENTER to continue:" BLAH
729                                         fi
730                                         
731
732                                 fi
733                         fi
734                 else
735                         # No audio group found on this system!
736                         echo ""
737                         echo "!!! WARNING !!! - The system does not seem to have an audio group (audio or jackuser)."
738                         echo ""
739                         echo "We will not attempt to fix this. Please configure your system to allow"
740                         echo "non-root users to execute realtime tasks."
741                         echo ""
742                         read -p "Press ENTER to continue:" BLAH
743                 fi
744         fi
745
746         if ! ${NORM_USER} "${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/bin/sanityCheck -freqscaling > /dev/null";
747         then
748                 echo ""
749                 echo "!!! WARNING !!! - Your system seems to use frequency scaling."
750                 echo "This can have a serious impact on audio latency."
751                 echo "For best results turn it off, e.g. by chosing the 'performance' governor."
752                 echo ""
753                 read -p "Press ENTER to continue:" BLAH
754         fi
755
756         if [ "f" = $USER_GROUP_ADJUSTED ];
757         then
758                 if ! ${NORM_USER} "${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/bin/sanityCheck -memlock > /dev/null";
759                 then
760                         echo ""
761                         echo "!!! WARNING !!! - You are not allowed to lock memory."
762                         echo ""
763                         echo "We will not attempt to fix this. Please configure your system to allow"
764                         echo "non-root users to execute lock memory."
765                         echo ""
766                         read -p "Press ENTER to continue:" BLAH
767                 fi
768         fi
769 fi
770
771
772 ########################
773 # Install Complete
774 ########################
775
776 echo ""
777 echo "Cleaning up"
778 rm -rf ${BUNDLE_DIR}/
779
780 echo ""
781 echo "!!! Install Complete !!!"
782
783 if [ "t" = $USER_GROUP_ADJUSTED ];
784 then
785         echo "You will need to logout and then login again for all changes to be complete"
786 fi
787
788 echo ""
789 read -p "Press ENTER to exit installer:" BLAH
790
791