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