Don't compress linux bundle, compress installer (with xz)
[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 "${PGM_NAME} 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 "${PGM_NAME} 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 if %REPLACE_WINE%; then
317         if test -z "`which wine`"; then
318                 echo ""
319                 echo "!!! ERROR !!! - 'wine' was not found."
320                 echo ""
321                 echo "This version of ${PGM_NAME} with Windows VST support requires wine."
322                 echo "https://www.winehq.org/"
323                 echo ""
324                 read -p "Press ENTER to exit installer:" BLAH
325                 exit 1
326         fi
327 fi
328
329 #####################
330 # Unpack the bundle
331 #####################
332
333 FILESYSTEM_TYPE=$(df -P -T "${PKG_PATH}" | grep / | awk '{print $2}')
334 echo "Bundle is on ${FILESYSTEM_TYPE} filesystem"
335
336 # untar the correct bundle for us to install
337 echo "Unpacking bundle for $ARCH"
338
339 if [ ! -e ${PGM_NAME}_${ARCH}-*.tar ]; then
340         echo ""
341         echo "!!! ERROR !!! Can't locate ${ARCH} bundle file."
342         echo ""
343         read -p "Press ENTER to exit installer:" BLAH
344         exit 1
345 fi
346
347 if ! tar -xf ${PGM_NAME}_${ARCH}-*.tar; then
348         echo ""
349         echo "!!! ERROR !!! Can't unpack ${ARCH} bundle file."
350         echo ""
351         read -p "Press ENTER to exit installer:" BLAH
352         exit 1
353 else
354         echo "Bundle unpacked"
355 fi
356
357 BUNDLE_DIR=$(basename `find -maxdepth 1 -type d -name "${PGM_NAME}_${ARCH}-*"`)
358
359
360 #######################
361 # Check for xdg utils
362 #######################
363
364 #load the file that contains the translated names of the users directories
365 if [ -e /home/${USER_NAME}/.config/user-dirs.dirs ]; then
366         . /home/${USER_NAME}/.config/user-dirs.dirs
367 fi
368
369 if [ "$(id -u)" != "0" ]; then
370         USER_DESKTOP_DIR=${XDG_DESKTOP_DIR:-$HOME/Desktop}
371 else
372         #running as root with su makes this more difficult
373         DESKTOP_FOLDER=$(echo ${XDG_DESKTOP_DIR:-$HOME/Desktop} | awk -F/ '{print $NF}')
374         USER_DESKTOP_DIR="/home/${USER_NAME}/${DESKTOP_FOLDER}"
375 fi
376
377 XDG_MENU_VER=$(xdg-desktop-menu --version 2> /dev/null)
378 if [ -z "$XDG_MENU_VER" ];
379 then
380         echo "System does not have xdg-desktop-menu installed"
381         HAS_XDG="F"
382 fi
383
384 XDG_ICON_VER=$(xdg-icon-resource --version 2> /dev/null)
385 if [ -z "$XDG_ICON_VER" ];
386 then
387         echo "System does not have xdg-icon-resource installed"
388         HAS_XDG="F"
389 fi
390
391 #################################################
392 # Set up libwine.so
393 #################################################
394 if %REPLACE_WINE%; then
395         echo ""
396         echo "Searching libwine.so (Windows VST support)"
397         # we need to add libwine to ardour's LD_LIBRARY_PATH
398         # libwine itself includes paths to the various system-components
399         # which may be different on each platform.
400         #
401         # There's some chicken/egg here: ardour.exe.so is linked against libwine.so
402         # at build-time. wine/wineloader assumes a windows-application (which does not use libwine
403         # directly) and does not set up the LD path to libwine itself. the application terminates
404         # (missing libs) before it even starts..
405         #
406         # wine itself does not provide means to find the location of libwine.
407         # /usr/bin/wine is usually shell-script and libwine.so can be found in
408         # various places on different distros.
409         #
410         # if this check were quick and easy.. it should be done in the startup-script, but it's not
411         # so here we go... (updating wine may require re-installing ardour)
412         #
413         # on recent Ubuntu wine does load both:
414         #   /usr/lib/i386-linux-gnu/libwine.so.1
415         # AND
416         #   /usr/lib/x86_64-linux-gnu/libwine.so.1
417         # so we need to work around this (thanks).
418         # (this hack break 64bit LinuxVST builds, but we don't do those anyway)
419
420         LIBWINE=$(
421                 LD_DEBUG=files wine `pwd`/${BUNDLE_DIR}/lib/ardour-vst-scanner.exe.so 2>&1 \
422                                                  | grep -e "calling init:.*libwine" \
423                                                  | sed 's/^.*calling init: //' \
424                                                  | grep -v x86_64-linux-gnu \
425                                                  | uniq \
426                         )
427         if ! test -f "$LIBWINE"; then
428                 echo ""
429                 echo "!!! ERROR !!! - 'libwine.so*' was not found."
430                 echo ""
431                 read -p "Press ENTER to exit installer:" BLAH
432                 exit 1
433         fi
434         echo "Using: $LIBWINE"
435   # this replaces/overwrites the bundled libwine
436         cp -L "$LIBWINE" `pwd`/${BUNDLE_DIR}/lib/libwine.so.1
437 fi
438
439 #################################################
440 # Check if system libs are OK (libc, etc)
441 #################################################
442
443 echo ""
444 echo "Checking system libs to see if they are compatible with ${PGM_NAME}."
445 echo ""
446
447 LIB_ERROR="F"
448 LD_PATH=`pwd`/${BUNDLE_DIR}/lib
449
450 # check the main App
451 LDD_RESULT=$(LD_LIBRARY_PATH=${LD_PATH} ldd ${BUNDLE_DIR}/bin/${PGM_NAME_LOWER}-* 2>&1 > /dev/null | grep -v "no version information")
452
453 if [ -n "$LDD_RESULT" ];
454 then
455         echo "$LDD_RESULT"
456         LIB_ERROR="T"
457 fi
458         
459 # check the libs
460 LIB_FILES=$(find ${BUNDLE_DIR}/lib -name "*.so")
461
462 for path in $LIB_FILES
463 do
464         LDD_RESULT=$(LD_LIBRARY_PATH=${LD_PATH} ldd $path 2>&1 > /dev/null | grep -v "no version information")
465         if [ -n "$LDD_RESULT" ];
466         then
467                 echo "$LDD_RESULT"
468                 LIB_ERROR="T"
469         fi
470 done
471
472 if test "T" = $LIB_ERROR;
473 then
474         echo ""
475         echo "!!! ERROR !!! - Missing library detected!"
476         echo "This system does not have the correct libs to run ${PGM_NAME}."
477         echo "Installation will not complete. Please use a compatible distro."
478         echo ""
479         read -p "Press ENTER to exit installer:" BLAH
480         exit 1
481 fi
482
483 ################################
484 # Setup derived variables
485 ################################
486 PGM_VERSION=$(echo ${BUNDLE_DIR} | cut -d- -f2)
487 PGM_BUILDTYPE=$(echo ${BUNDLE_DIR} | cut -d- -f3)
488
489 if [ -z ${PGM_BUILDTYPE} ];
490 then
491         PGM_FULL_NAME="${PGM_NAME}-${PGM_VERSION}"
492         ICON_NAME="${PGM_VENDOR}-${PGM_NAME}_${PGM_VERSION}"                    #no dash between name and version since dash seperates vendor from program
493         MENU_FILE="${PGM_VENDOR}-${PGM_NAME}_${PGM_VERSION}.desktop"    #no dash between name and version since dash seperates vendor from program
494         DESKTOP_LINK_FILE="${PGM_NAME}_${PGM_VERSION}.desktop"
495 else
496         PGM_FULL_NAME="${PGM_NAME}-${PGM_VERSION}-${PGM_BUILDTYPE}"
497         ICON_NAME="${PGM_VENDOR}-${PGM_NAME}_${PGM_VERSION}_${PGM_BUILDTYPE}"                   #no dash between name and version since dash seperates vendor from program
498         MENU_FILE="${PGM_VENDOR}-${PGM_NAME}_${PGM_VERSION}_${PGM_BUILDTYPE}.desktop"   #no dash between name and version since dash seperates vendor from program
499         DESKTOP_LINK_FILE="${PGM_NAME}_${PGM_VERSION}_${PGM_BUILDTYPE}.desktop"
500 fi
501
502 PGM_EXEC_PATH="${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/bin/${PGM_EXEC_FILE}"
503 ICON_PATH="${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/share/resources"
504 MENU_FILE_PATH="${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/share"
505
506 ################################
507 # Install bundle and Menu/Link
508 ################################
509
510 # uninstall any older versions
511 UNINSTALLERS=$(find ${INSTALL_DEST_BASE} -maxdepth 1 -type f -name "${PGM_NAME}-*.uninstall.sh")
512 if [ ! -z "$UNINSTALLERS" ];
513 then
514         for i in $UNINSTALLERS; do
515                 echo ""
516                 echo "Found existing ${PGM_NAME} installation."
517                 
518                 ANSWER=$(VaildateYesNoQuestion "Do you want to run the uninstaller ${i} ?")
519
520                 if test "y" = $ANSWER;
521                 then
522                         echo ""
523                         echo "Running uninstaller $i"
524                         
525                         ${i}
526                         ${SUPER} rm -f ${i}
527                 fi
528         done
529 fi
530
531
532 # install 
533
534 echo ""
535 echo "Installing ${PGM_NAME} ${PGM_VERSION} in ${INSTALL_DEST_BASE}"
536 echo ""
537
538 # Copy the new version in the install directory
539 ${SUPER} mkdir ${INSTALL_DEST_BASE}/${PGM_FULL_NAME} 
540 ${SUPER} cp -Rf ${BUNDLE_DIR}/* ${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/
541
542 # write the desktop/menu file
543 echo "[Desktop Entry]" > /tmp/${MENU_FILE}
544 echo "Encoding=UTF-8" >> /tmp/${MENU_FILE}
545 echo "Version=1.0" >> /tmp/${MENU_FILE}
546 echo "Type=Application" >> /tmp/${MENU_FILE}
547 echo "Terminal=false" >> /tmp/${MENU_FILE}
548 echo "Exec=${PGM_EXEC_PATH}" >> /tmp/${MENU_FILE}
549 if [ -z ${PGM_BUILDTYPE} ];
550 then
551         echo "Name=${PGM_NAME}-${PGM_VERSION}" >> /tmp/${MENU_FILE}
552 else
553         echo "Name=${PGM_NAME}-${PGM_VERSION}-${PGM_BUILDTYPE}" >> /tmp/${MENU_FILE}
554 fi
555 echo "Icon=${ICON_NAME}" >> /tmp/${MENU_FILE}
556 echo "Comment=Digital Audio Workstation" >> /tmp/${MENU_FILE}
557 echo "Categories=AudioVideo;AudioEditing;Audio;Recorder;" >> /tmp/${MENU_FILE}
558
559 chmod ugo+rx /tmp/${MENU_FILE}
560 ${SUPER} mv /tmp/${MENU_FILE} ${MENU_FILE_PATH}/.
561
562 # install the Menu, Link, and Icon(s)
563 if [ "T" = ${HAS_XDG} ];
564 then
565         echo "Adding ${PGM_NAME} to the applications menu"
566         ${SUPER} xdg-icon-resource install --context apps --size 16 ${ICON_PATH}/${PGM_NAME}-icon_16px.png ${ICON_NAME}
567         ${SUPER} xdg-icon-resource install --context apps --size 22 ${ICON_PATH}/${PGM_NAME}-icon_22px.png ${ICON_NAME}
568         ${SUPER} xdg-icon-resource install --context apps --size 32 ${ICON_PATH}/${PGM_NAME}-icon_32px.png ${ICON_NAME}
569         ${SUPER} xdg-icon-resource install --context apps --size 48 ${ICON_PATH}/${PGM_NAME}-icon_48px.png ${ICON_NAME}
570         ${SUPER} xdg-icon-resource install --context apps --size 256 ${ICON_PATH}/${PGM_NAME}-icon_256px.png ${ICON_NAME}
571
572         if [ -e ${ICON_PATH}/${PGM_NAME}_icon.svg -a -d /usr/share/icons/hicolor/scalable/apps ];
573         then
574                 ${SUPER} cp -f ${ICON_PATH}/${PGM_NAME}_icon.svg  /usr/share/icons/hicolor/scalable/apps/${ICON_NAME}.svg
575         fi
576
577         ${SUPER} xdg-desktop-menu install ${MENU_FILE_PATH}/${MENU_FILE}
578         ${SUPER} xdg-desktop-menu forceupdate --mode system                     # Some systems need an extra kick
579         
580         echo ""
581         echo "Creating a desktop link for ${PGM_NAME} in ${USER_DESKTOP_DIR}"
582         cp ${MENU_FILE_PATH}/${MENU_FILE} ${USER_DESKTOP_DIR}/${DESKTOP_LINK_FILE}
583         chmod ugo+rwx ${USER_DESKTOP_DIR}/${DESKTOP_LINK_FILE}
584 else
585         echo ""
586         echo "Creating a desktop link for ${PGM_NAME} in ${USER_DESKTOP_DIR}"
587         cp ${MENU_FILE_PATH}/${MENU_FILE} ${USER_DESKTOP_DIR}/${DESKTOP_LINK_FILE}
588         chmod ugo+rwx ${USER_DESKTOP_DIR}/${DESKTOP_LINK_FILE}
589 fi
590
591 echo ""
592 echo "Copying uninstall script to ${INSTALL_DEST_BASE}"
593 echo ""
594
595 ${SUPER} cp -f ${BUNDLE_DIR}/bin/*.uninstall.sh ${INSTALL_DEST_BASE}/.
596
597 # Create link to the program in user bin
598
599 echo ""
600 echo "Creating link ${PGM_NAME}${MAJOR_VERSION} in ${USER_BIN_DIR}"
601 echo ""
602
603 if [ -d "${USER_BIN_DIR}" ]; then
604         if [ -e "${USER_BIN_DIR}/${PGM_NAME}${MAJOR_VERSION}" ]; then
605                 ${SUPER} rm -f ${USER_BIN_DIR}/${PGM_NAME}${MAJOR_VERSION}
606         fi
607
608         cd "${USER_BIN_DIR}"
609         ${SUPER} ln -sf ${PGM_EXEC_PATH} ${PGM_NAME}${MAJOR_VERSION}
610         cd "${PKG_PATH}"
611         
612 else
613         echo "Can not create link because ${USER_BIN_DIR} does not exist"
614 fi
615
616 ###########################
617 # Check Jack and qjackctl
618 ###########################
619
620 echo ""
621 echo "Checking to see if Jack is installed"
622 echo ""
623
624 JACK_INSTALLED="f"
625
626 if which jackd > /dev/null; then
627         JACK_INSTALLED="t"
628         echo "Jack already present"
629 elif which jackdbus > /dev/null; then
630         echo ""
631         echo "jackdbus was found but not jackd. Jack version compatibility check cannot be performed."
632         echo ""
633         JACK_INSTALLED="i"
634 else
635         echo ""
636         echo "The program Jack is missing from this system. Jack is a required component of $PGM_NAME."
637         echo ""
638
639         ANSWER=$(VaildateYesNoQuestion "Install jack using system software repository?")
640
641         if test "y" = $ANSWER;
642         then
643                 echo "Attempting to install Jack"
644                 SystemInstall "jackd"
645                 
646                 if [ $? -ne 0 ];
647                 then
648                         echo ""
649                         read -p "Press ENTER to continue:" BLAH
650                 else
651                         JACK_INSTALLED="t"
652                 fi
653         fi
654 fi
655
656 # Check to see if Jack is new enough to operate correctly.
657
658 if [ "t" = ${JACK_INSTALLED} ];
659 then
660         JACK_VERSION_OK="f"
661         JACK_VER_STRING=$(jackd --version | grep -e "jackd.*protocol")
662         JACK_NAME=$(echo $JACK_VER_STRING | awk '{print $1}')
663         JACK_VERSION=$(echo $JACK_VER_STRING | awk '{print $3}')
664         JACK_VERSION_MAJOR=$(echo $JACK_VERSION | awk 'BEGIN{FS="."}{print $1}')
665         JACK_VERSION_MIDDLE=$(echo $JACK_VERSION | awk 'BEGIN{FS="."}{print $2}')
666         JACK_VERSION_MINOR=$(echo $JACK_VERSION | awk 'BEGIN{FS="."}{print $3}')
667
668         if [ "jackd" = ${JACK_NAME} ];
669         then
670                 if [ ${JACK_VERSION_MAJOR} -eq 0 ];
671                 then
672                         if [ ${JACK_VERSION_MIDDLE} -eq 121 ];
673                         then
674                                 if [ ${JACK_VERSION_MINOR} -ge 3 ];
675                                 then
676                                         JACK_VERSION_OK="t"
677                                 fi
678                         elif [ ${JACK_VERSION_MIDDLE} -gt 121 ];
679                         then
680                                 JACK_VERSION_OK="t"
681                         fi
682                 elif [ ${JACK_VERSION_MAJOR} -gt 0 ];
683                 then
684                         JACK_VERSION_OK="t"
685                 fi
686         elif [ "jackdmp" = ${JACK_NAME} ];
687         then
688                 if [ ${JACK_VERSION_MAJOR} -eq 1 ];
689                 then
690                         if [ ${JACK_VERSION_MIDDLE} -eq 9 ];
691                         then
692                                 if [ ${JACK_VERSION_MINOR} -ge 8 ];
693                                 then
694                                         JACK_VERSION_OK="t"
695                                 fi
696                         elif [ ${JACK_VERSION_MIDDLE} -gt 9 ];
697                         then
698                                 JACK_VERSION_OK="t"
699                         fi
700                 elif [ ${JACK_VERSION_MAJOR} -gt 1 ];
701                 then
702                         JACK_VERSION_OK="t"
703                 fi
704         fi
705
706         if [ "t" = ${JACK_VERSION_OK} ];
707         then
708                 echo ""
709                 echo "Jack Version Check OK (${JACK_VER_STRING})"
710                 echo ""
711         else
712                 echo ""
713                 echo "!!! WARNING !!! - The version of Jack on this system is too old!"
714                 echo "Using an old version of Jack is not recommended. Please update"
715                 echo "Jack for best results."
716                 echo ""
717                 echo "System Jack version:"
718                 echo "   ${JACK_VER_STRING}"
719                 echo ""
720                 echo "Recommended minimum versions:"
721                 echo "   Jack1 - 0.121.3"
722                 echo "   Jack2 - 1.9.8"
723                 echo ""
724                 read -p "Press ENTER to continue:" BLAH
725         fi
726 fi
727
728 if ! which qjackctl > /dev/null;
729 then
730         echo ""
731         echo "The program QjackCtl is missing from this system."
732         echo "QjackCtl is an extremely useful tool for any system that runs JACK applications like $PGM_NAME."
733         echo "We recommend that you install it."
734         echo ""
735
736         ANSWER=$(VaildateYesNoQuestion "Install QjackCtl using system software repository?")
737
738         if test "y" = $ANSWER;
739         then
740                 echo "Attempting to install QjackCtl"
741                 SystemInstall "qjackctl"
742
743                 if [ $? -ne 0 ];
744                 then
745                         echo ""
746                         read -p "Press ENTER to continue:" BLAH
747                 fi
748         fi
749 fi
750
751
752 ########################
753 # Run Sanity Check
754 ########################
755
756 USER_GROUP_ADJUSTED="f"
757
758 if ! ${NORM_USER} "${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/bin/sanityCheck -a > /dev/null";
759 then
760         echo ""
761         echo "System failed the quick sanity check... Looking for the cause"
762
763         if ! ${NORM_USER} "${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/bin/sanityCheck -rt > /dev/null";
764         then
765                 echo ""
766                 echo "System does not allow realtime for the current user... Looking for a solution"            
767                 
768                 if ${NORM_USER} "${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/bin/sanityCheck -hasaudiogroup > /dev/null";
769                 then
770                         if ${NORM_USER} "${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/bin/sanityCheck -memberaudiogroup > /dev/null 2>&1";
771                         then
772                                 ## This is an odd case. We have an audio group and are a member.
773                                 echo ""
774                                 echo "!!! WARNING !!! - The current user can not execute realtime processes."
775                                 echo "This will adversely affect audio latency."
776                                 echo "This system has an audio group and the user is a member. If jack was"
777                                 echo "just installed, a simple log out/in may fix this."
778                                 echo ""
779                                 echo "For best results, please correct this on your system."
780                                 echo "(Hint: check /etc/security/limits.conf or /etc/security/limits.d/)" 
781                                 echo ""
782                                 read -p "Press ENTER to continue:" BLAH
783                         else
784                                 # Not a member of an audio group. Try to fix it.
785                                 
786                                 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" ";
787                                 then
788                                         # add user to audio group
789                                         echo ""
790                                         echo "Adding user ${USER_NAME} to the audio group."
791                                         echo "This should allow you to run realtime tasks. Please re-login for this change to take affect."
792                                         echo ""
793                                         read -p "Press ENTER to continue:" BLAH
794
795                                         if ${SUPER} usermod -a -G audio ${USER_NAME};
796                                         then
797                                                 USER_GROUP_ADJUSTED="t"
798                                         else
799                                                 echo ""
800                                                 echo "!!! ERROR !!! - Not able to add user to the audio group (usermod failed)!"
801                                                 echo ""
802                                                 echo "Please add yourself to the audio group and re-login"
803                                                 echo ""
804                                                 read -p "Press ENTER to continue:" BLAH
805                                         fi
806
807                                 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" ";
808                                 then
809                                         # add user to jackuser group
810                                         echo ""
811                                         echo "Adding user ${USER_NAME} to the jackuser group."
812                                         echo "This should allow you to run realtime tasks. Please re-login for this change to take affect."
813                                         echo ""
814                                         read -p "Press ENTER to continue:" BLAH
815
816                                         if ${SUPER} usermod -a -G jackuser ${USER_NAME};
817                                         then
818                                                 USER_GROUP_ADJUSTED="t"
819                                         else
820                                                 echo ""
821                                                 echo "!!! ERROR !!! - Not able to add user to the jackuser group."
822                                                 echo ""
823                                                 echo "Please add yourself to the audio group and re-login"
824                                                 echo ""
825                                                 read -p "Press ENTER to continue:" BLAH
826                                         fi
827                                         
828
829                                 fi
830                         fi
831                 else
832                         # No audio group found on this system!
833                         echo ""
834                         echo "!!! WARNING !!! - The system does not seem to have an audio group (audio or jackuser)."
835                         echo ""
836                         echo "We will not attempt to fix this. Please configure your system to allow"
837                         echo "non-root users to execute realtime tasks."
838                         echo ""
839                         read -p "Press ENTER to continue:" BLAH
840                 fi
841         fi
842
843         if ! ${NORM_USER} "${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/bin/sanityCheck -freqscaling > /dev/null";
844         then
845                 echo ""
846                 echo "!!! WARNING !!! - Your system seems to use frequency scaling."
847                 echo "This can have a serious impact on audio latency."
848                 echo "For best results turn it off, e.g. by choosing the 'performance' governor."
849                 echo ""
850                 read -p "Press ENTER to continue:" BLAH
851         fi
852
853         if [ "f" = $USER_GROUP_ADJUSTED ];
854         then
855                 if ! ${NORM_USER} "${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/bin/sanityCheck -memlock > /dev/null";
856                 then
857                         echo ""
858                         echo "!!! WARNING !!! - You are not allowed to lock memory."
859                         echo ""
860                         echo "We will not attempt to fix this. Please configure your system to allow"
861                         echo "non-root users to execute lock memory."
862                         echo ""
863                         read -p "Press ENTER to continue:" BLAH
864                 fi
865         fi
866 fi
867
868
869 ########################
870 # Install Complete
871 ########################
872
873 echo ""
874 echo "Cleaning up"
875 rm -rf ${BUNDLE_DIR}/
876
877 echo ""
878 echo "!!! Install Complete !!!"
879
880 if [ "t" = $USER_GROUP_ADJUSTED ];
881 then
882         echo "You will need to logout and then login again for all changes to be complete"
883 fi
884
885 echo ""
886 read -p "Press ENTER to exit installer:" BLAH
887
888