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