Fix spelling
[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.bz2 ]; 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 -xjf ${PGM_NAME}_${ARCH}-*.tar.bz2; 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         LIBWINE=$(
414                 LD_DEBUG=files wine `pwd`/${BUNDLE_DIR}/lib/ardour-vst-scanner.exe.so 2>&1 \
415                                                  | grep -e "calling init:.*libwine" \
416                                                  | sed 's/^.*calling init: //' \
417                                                  | uniq \
418                         )
419         if ! test -f "$LIBWINE"; then
420                 echo ""
421                 echo "!!! ERROR !!! - 'libwine.so*' was not found."
422                 echo ""
423                 read -p "Press ENTER to exit installer:" BLAH
424                 exit 1
425         fi
426         echo "Using: $LIBWINE"
427   # this replaces/overwrites the bundled libwine
428         cp -L "$LIBWINE" `pwd`/${BUNDLE_DIR}/lib/libwine.so.1
429 fi
430
431 #################################################
432 # Check if system libs are OK (libc, etc)
433 #################################################
434
435 echo ""
436 echo "Checking system libs to see if they are compatible with ${PGM_NAME}."
437 echo ""
438
439 LIB_ERROR="F"
440 LD_PATH=`pwd`/${BUNDLE_DIR}/lib
441
442 # check the main App
443 LDD_RESULT=$(LD_LIBRARY_PATH=${LD_PATH} ldd ${BUNDLE_DIR}/bin/${PGM_NAME_LOWER}-* 2>&1 > /dev/null | grep -v "no version information")
444
445 if [ -n "$LDD_RESULT" ];
446 then
447         echo "$LDD_RESULT"
448         LIB_ERROR="T"
449 fi
450         
451 # check the libs
452 LIB_FILES=$(find ${BUNDLE_DIR}/lib -name "*.so")
453
454 for path in $LIB_FILES
455 do
456         LDD_RESULT=$(LD_LIBRARY_PATH=${LD_PATH} ldd $path 2>&1 > /dev/null | grep -v "no version information")
457         if [ -n "$LDD_RESULT" ];
458         then
459                 echo "$LDD_RESULT"
460                 LIB_ERROR="T"
461         fi
462 done
463
464 if test "T" = $LIB_ERROR;
465 then
466         echo ""
467         echo "!!! ERROR !!! - Missing library detected!"
468         echo "This system does not have the correct libs to run ${PGM_NAME}."
469         echo "Installation will not complete. Please use a compatible distro."
470         echo ""
471         read -p "Press ENTER to exit installer:" BLAH
472         exit 1
473 fi
474
475 ################################
476 # Setup derived variables
477 ################################
478 PGM_VERSION=$(echo ${BUNDLE_DIR} | cut -d- -f2)
479 PGM_BUILDTYPE=$(echo ${BUNDLE_DIR} | cut -d- -f3)
480
481 if [ -z ${PGM_BUILDTYPE} ];
482 then
483         PGM_FULL_NAME="${PGM_NAME}-${PGM_VERSION}"
484         ICON_NAME="${PGM_VENDOR}-${PGM_NAME}_${PGM_VERSION}"                    #no dash between name and version since dash seperates vendor from program
485         MENU_FILE="${PGM_VENDOR}-${PGM_NAME}_${PGM_VERSION}.desktop"    #no dash between name and version since dash seperates vendor from program
486         DESKTOP_LINK_FILE="${PGM_NAME}_${PGM_VERSION}.desktop"
487 else
488         PGM_FULL_NAME="${PGM_NAME}-${PGM_VERSION}-${PGM_BUILDTYPE}"
489         ICON_NAME="${PGM_VENDOR}-${PGM_NAME}_${PGM_VERSION}_${PGM_BUILDTYPE}"                   #no dash between name and version since dash seperates vendor from program
490         MENU_FILE="${PGM_VENDOR}-${PGM_NAME}_${PGM_VERSION}_${PGM_BUILDTYPE}.desktop"   #no dash between name and version since dash seperates vendor from program
491         DESKTOP_LINK_FILE="${PGM_NAME}_${PGM_VERSION}_${PGM_BUILDTYPE}.desktop"
492 fi
493
494 PGM_EXEC_PATH="${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/bin/${PGM_EXEC_FILE}"
495 ICON_PATH="${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/share/icons"
496 MENU_FILE_PATH="${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/share"
497
498 ################################
499 # Install bundle and Menu/Link
500 ################################
501
502 # uninstall any older versions
503 UNINSTALLERS=$(find ${INSTALL_DEST_BASE} -maxdepth 1 -type f -name "${PGM_NAME}*.uninstall.sh")
504 if [ ! -z "$UNINSTALLERS" ];
505 then
506         for i in $UNINSTALLERS; do
507                 echo ""
508                 echo "Found existing ${PGM_NAME} installation."
509                 
510                 ANSWER=$(VaildateYesNoQuestion "Do you want to run the uninstaller ${i} ?")
511
512                 if test "y" = $ANSWER;
513                 then
514                         echo ""
515                         echo "Running uninstaller $i"
516                         
517                         ${i}
518                         ${SUPER} rm -f ${i}
519                 fi
520         done
521 fi
522
523
524 # install 
525
526 echo ""
527 echo "Installing ${PGM_NAME} ${PGM_VERSION} in ${INSTALL_DEST_BASE}"
528 echo ""
529
530 # Copy the new version in the install directory
531 ${SUPER} mkdir ${INSTALL_DEST_BASE}/${PGM_FULL_NAME} 
532 ${SUPER} cp -Rf ${BUNDLE_DIR}/* ${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/
533
534 # write the desktop/menu file
535 echo "[Desktop Entry]" > /tmp/${MENU_FILE}
536 echo "Encoding=UTF-8" >> /tmp/${MENU_FILE}
537 echo "Version=1.0" >> /tmp/${MENU_FILE}
538 echo "Type=Application" >> /tmp/${MENU_FILE}
539 echo "Terminal=false" >> /tmp/${MENU_FILE}
540 echo "Exec=${PGM_EXEC_PATH}" >> /tmp/${MENU_FILE}
541 if [ -z ${PGM_BUILDTYPE} ];
542 then
543         echo "Name=${PGM_NAME}-${PGM_VERSION}" >> /tmp/${MENU_FILE}
544 else
545         echo "Name=${PGM_NAME}-${PGM_VERSION}-${PGM_BUILDTYPE}" >> /tmp/${MENU_FILE}
546 fi
547 echo "Icon=${ICON_NAME}" >> /tmp/${MENU_FILE}
548 echo "Comment=Digital Audio Workstation" >> /tmp/${MENU_FILE}
549 echo "Categories=AudioVideo;AudioEditing;Audio;Recorder;" >> /tmp/${MENU_FILE}
550
551 chmod ugo+rx /tmp/${MENU_FILE}
552 ${SUPER} mv /tmp/${MENU_FILE} ${MENU_FILE_PATH}/.
553
554 # install the Menu, Link, and Icon(s)
555 if [ "T" = ${HAS_XDG} ];
556 then
557         echo "Adding ${PGM_NAME} to the applications menu"
558         ${SUPER} xdg-icon-resource install --context apps --size 16 ${ICON_PATH}/${PGM_NAME_LOWER}_icon_16px.png ${ICON_NAME}
559         ${SUPER} xdg-icon-resource install --context apps --size 22 ${ICON_PATH}/${PGM_NAME_LOWER}_icon_22px.png ${ICON_NAME}
560         ${SUPER} xdg-icon-resource install --context apps --size 32 ${ICON_PATH}/${PGM_NAME_LOWER}_icon_32px.png ${ICON_NAME}
561         ${SUPER} xdg-icon-resource install --context apps --size 48 ${ICON_PATH}/${PGM_NAME_LOWER}_icon_48px.png ${ICON_NAME}
562         ${SUPER} xdg-icon-resource install --context apps --size 256 ${ICON_PATH}/${PGM_NAME_LOWER}_icon_256px.png ${ICON_NAME}
563
564         if [ -e ${ICON_PATH}/${PGM_NAME_LOWER}_icon.svg -a -d /usr/share/icons/hicolor/scalable/apps ]; 
565         then
566                 ${SUPER} cp -f ${ICON_PATH}/${PGM_NAME_LOWER}_icon.svg  /usr/share/icons/hicolor/scalable/apps/${ICON_NAME}.svg
567         fi
568
569         ${SUPER} xdg-desktop-menu install ${MENU_FILE_PATH}/${MENU_FILE}
570         ${SUPER} xdg-desktop-menu forceupdate --mode system                     # Some systems need an extra kick
571         
572         echo ""
573         echo "Creating a desktop link for ${PGM_NAME} in ${USER_DESKTOP_DIR}"
574         cp ${MENU_FILE_PATH}/${MENU_FILE} ${USER_DESKTOP_DIR}/${DESKTOP_LINK_FILE}
575         chmod ugo+rwx ${USER_DESKTOP_DIR}/${DESKTOP_LINK_FILE}
576 else
577         echo ""
578         echo "Creating a desktop link for ${PGM_NAME} in ${USER_DESKTOP_DIR}"
579         cp ${MENU_FILE_PATH}/${MENU_FILE} ${USER_DESKTOP_DIR}/${DESKTOP_LINK_FILE}
580         chmod ugo+rwx ${USER_DESKTOP_DIR}/${DESKTOP_LINK_FILE}
581 fi
582
583 echo ""
584 echo "Copying uninstall script to ${INSTALL_DEST_BASE}"
585 echo ""
586
587 ${SUPER} cp -f ${BUNDLE_DIR}/bin/*.uninstall.sh ${INSTALL_DEST_BASE}/.
588
589 # Create link to the program in user bin
590
591 echo ""
592 echo "Creating link ${PGM_NAME}${MAJOR_VERSION} in ${USER_BIN_DIR}"
593 echo ""
594
595 if [ -d "${USER_BIN_DIR}" ]; then
596         if [ -e "${USER_BIN_DIR}/${PGM_NAME}${MAJOR_VERSION}" ]; then
597                 ${SUPER} rm -f ${USER_BIN_DIR}/${PGM_NAME}${MAJOR_VERSION}
598         fi
599
600         cd "${USER_BIN_DIR}"
601         ${SUPER} ln -sf ${PGM_EXEC_PATH} ${PGM_NAME}${MAJOR_VERSION}
602         cd "${PKG_PATH}"
603         
604 else
605         echo "Can not create link because ${USER_BIN_DIR} does not exist"
606 fi
607
608 ###########################
609 # Check Jack and qjackctl
610 ###########################
611
612 echo ""
613 echo "Checking to see if Jack is installed"
614 echo ""
615
616 JACK_INSTALLED="f"
617
618 if which jackd > /dev/null; then
619         JACK_INSTALLED="t"
620         echo "Jack already present"
621 elif which jackdbus > /dev/null; then
622         echo ""
623         echo "jackdbus was found but not jackd. Jack version compatibility check cannot be performed."
624         echo ""
625         JACK_INSTALLED="i"
626 else
627         echo ""
628         echo "The program Jack is missing from this system. Jack is a required component of $PGM_NAME."
629         echo ""
630
631         ANSWER=$(VaildateYesNoQuestion "Install jack using system software repository?")
632
633         if test "y" = $ANSWER;
634         then
635                 echo "Attempting to install Jack"
636                 SystemInstall "jackd"
637                 
638                 if [ $? -ne 0 ];
639                 then
640                         echo ""
641                         read -p "Press ENTER to continue:" BLAH
642                 else
643                         JACK_INSTALLED="t"
644                 fi
645         fi
646 fi
647
648 # Check to see if Jack is new enough to operate correctly.
649
650 if [ "t" = ${JACK_INSTALLED} ];
651 then
652         JACK_VERSION_OK="f"
653         JACK_VER_STRING=$(jackd --version | grep -e "jackd.*protocol")
654         JACK_NAME=$(echo $JACK_VER_STRING | awk '{print $1}')
655         JACK_VERSION=$(echo $JACK_VER_STRING | awk '{print $3}')
656         JACK_VERSION_MAJOR=$(echo $JACK_VERSION | awk 'BEGIN{FS="."}{print $1}')
657         JACK_VERSION_MIDDLE=$(echo $JACK_VERSION | awk 'BEGIN{FS="."}{print $2}')
658         JACK_VERSION_MINOR=$(echo $JACK_VERSION | awk 'BEGIN{FS="."}{print $3}')
659
660         if [ "jackd" = ${JACK_NAME} ];
661         then
662                 if [ ${JACK_VERSION_MAJOR} -eq 0 ];
663                 then
664                         if [ ${JACK_VERSION_MIDDLE} -eq 121 ];
665                         then
666                                 if [ ${JACK_VERSION_MINOR} -ge 3 ];
667                                 then
668                                         JACK_VERSION_OK="t"
669                                 fi
670                         elif [ ${JACK_VERSION_MIDDLE} -gt 121 ];
671                         then
672                                 JACK_VERSION_OK="t"
673                         fi
674                 elif [ ${JACK_VERSION_MAJOR} -gt 0 ];
675                 then
676                         JACK_VERSION_OK="t"
677                 fi
678         elif [ "jackdmp" = ${JACK_NAME} ];
679         then
680                 if [ ${JACK_VERSION_MAJOR} -eq 1 ];
681                 then
682                         if [ ${JACK_VERSION_MIDDLE} -eq 9 ];
683                         then
684                                 if [ ${JACK_VERSION_MINOR} -ge 8 ];
685                                 then
686                                         JACK_VERSION_OK="t"
687                                 fi
688                         elif [ ${JACK_VERSION_MIDDLE} -gt 9 ];
689                         then
690                                 JACK_VERSION_OK="t"
691                         fi
692                 elif [ ${JACK_VERSION_MAJOR} -gt 1 ];
693                 then
694                         JACK_VERSION_OK="t"
695                 fi
696         fi
697
698         if [ "t" = ${JACK_VERSION_OK} ];
699         then
700                 echo ""
701                 echo "Jack Version Check OK (${JACK_VER_STRING})"
702                 echo ""
703         else
704                 echo ""
705                 echo "!!! WARNING !!! - The version of Jack on this system is too old!"
706                 echo "Using an old version of Jack is not recommended. Please update"
707                 echo "Jack for best results."
708                 echo ""
709                 echo "System Jack version:"
710                 echo "   ${JACK_VER_STRING}"
711                 echo ""
712                 echo "Recommended minimum versions:"
713                 echo "   Jack1 - 0.121.3"
714                 echo "   Jack2 - 1.9.8"
715                 echo ""
716                 read -p "Press ENTER to continue:" BLAH
717         fi
718 fi
719
720 if ! which qjackctl > /dev/null;
721 then
722         echo ""
723         echo "The program QjackCtl is missing from this system."
724         echo "QjackCtl is an extremely useful tool for any system that runs JACK applications like $PGM_NAME."
725         echo "We recommend that you install it."
726         echo ""
727
728         ANSWER=$(VaildateYesNoQuestion "Install QjackCtl using system software repository?")
729
730         if test "y" = $ANSWER;
731         then
732                 echo "Attempting to install QjackCtl"
733                 SystemInstall "qjackctl"
734
735                 if [ $? -ne 0 ];
736                 then
737                         echo ""
738                         read -p "Press ENTER to continue:" BLAH
739                 fi
740         fi
741 fi
742
743
744 ########################
745 # Run Sanity Check
746 ########################
747
748 USER_GROUP_ADJUSTED="f"
749
750 if ! ${NORM_USER} "${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/bin/sanityCheck -a > /dev/null";
751 then
752         echo ""
753         echo "System failed the quick sanity check... Looking for the cause"
754
755         if ! ${NORM_USER} "${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/bin/sanityCheck -rt > /dev/null";
756         then
757                 echo ""
758                 echo "System does not allow realtime for the current user... Looking for a solution"            
759                 
760                 if ${NORM_USER} "${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/bin/sanityCheck -hasaudiogroup > /dev/null";
761                 then
762                         if ${NORM_USER} "${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/bin/sanityCheck -memberaudiogroup > /dev/null 2>&1";
763                         then
764                                 ## This is an odd case. We have an audio group and are a member.
765                                 echo ""
766                                 echo "!!! WARNING !!! - The current user can not execute realtime processes."
767                                 echo "This will adversely affect audio latency."
768                                 echo "This system has an audio group and the user is a member. If jack was"
769                                 echo "just installed, a simple log out/in may fix this."
770                                 echo ""
771                                 echo "For best results, please correct this on your system."
772                                 echo "(Hint: check /etc/security/limits.conf or /etc/security/limits.d/)" 
773                                 echo ""
774                                 read -p "Press ENTER to continue:" BLAH
775                         else
776                                 # Not a member of an audio group. Try to fix it.
777                                 
778                                 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" ";
779                                 then
780                                         # add user to audio group
781                                         echo ""
782                                         echo "Adding user ${USER_NAME} to the audio group."
783                                         echo "This should allow you to run realtime tasks. Please re-login for this change to take affect."
784                                         echo ""
785                                         read -p "Press ENTER to continue:" BLAH
786
787                                         if ${SUPER} usermod -a -G audio ${USER_NAME};
788                                         then
789                                                 USER_GROUP_ADJUSTED="t"
790                                         else
791                                                 echo ""
792                                                 echo "!!! ERROR !!! - Not able to add user to the audio group (usermod failed)!"
793                                                 echo ""
794                                                 echo "Please add yourself to the audio group and re-login"
795                                                 echo ""
796                                                 read -p "Press ENTER to continue:" BLAH
797                                         fi
798
799                                 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" ";
800                                 then
801                                         # add user to jackuser group
802                                         echo ""
803                                         echo "Adding user ${USER_NAME} to the jackuser group."
804                                         echo "This should allow you to run realtime tasks. Please re-login for this change to take affect."
805                                         echo ""
806                                         read -p "Press ENTER to continue:" BLAH
807
808                                         if ${SUPER} usermod -a -G jackuser ${USER_NAME};
809                                         then
810                                                 USER_GROUP_ADJUSTED="t"
811                                         else
812                                                 echo ""
813                                                 echo "!!! ERROR !!! - Not able to add user to the jackuser group."
814                                                 echo ""
815                                                 echo "Please add yourself to the audio group and re-login"
816                                                 echo ""
817                                                 read -p "Press ENTER to continue:" BLAH
818                                         fi
819                                         
820
821                                 fi
822                         fi
823                 else
824                         # No audio group found on this system!
825                         echo ""
826                         echo "!!! WARNING !!! - The system does not seem to have an audio group (audio or jackuser)."
827                         echo ""
828                         echo "We will not attempt to fix this. Please configure your system to allow"
829                         echo "non-root users to execute realtime tasks."
830                         echo ""
831                         read -p "Press ENTER to continue:" BLAH
832                 fi
833         fi
834
835         if ! ${NORM_USER} "${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/bin/sanityCheck -freqscaling > /dev/null";
836         then
837                 echo ""
838                 echo "!!! WARNING !!! - Your system seems to use frequency scaling."
839                 echo "This can have a serious impact on audio latency."
840                 echo "For best results turn it off, e.g. by choosing the 'performance' governor."
841                 echo ""
842                 read -p "Press ENTER to continue:" BLAH
843         fi
844
845         if [ "f" = $USER_GROUP_ADJUSTED ];
846         then
847                 if ! ${NORM_USER} "${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/bin/sanityCheck -memlock > /dev/null";
848                 then
849                         echo ""
850                         echo "!!! WARNING !!! - You are not allowed to lock memory."
851                         echo ""
852                         echo "We will not attempt to fix this. Please configure your system to allow"
853                         echo "non-root users to execute lock memory."
854                         echo ""
855                         read -p "Press ENTER to continue:" BLAH
856                 fi
857         fi
858 fi
859
860
861 ########################
862 # Install Complete
863 ########################
864
865 echo ""
866 echo "Cleaning up"
867 rm -rf ${BUNDLE_DIR}/
868
869 echo ""
870 echo "!!! Install Complete !!!"
871
872 if [ "t" = $USER_GROUP_ADJUSTED ];
873 then
874         echo "You will need to logout and then login again for all changes to be complete"
875 fi
876
877 echo ""
878 read -p "Press ENTER to exit installer:" BLAH
879
880