From 5cf8aaf7a15c6ae52d88948bd7adb8be4e9ea935 Mon Sep 17 00:00:00 2001 From: jo Date: Mon, 16 Aug 2021 13:20:27 +0200 Subject: [PATCH 1/8] Add global Makefile for project management --- Makefile | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..ef15c9b57 --- /dev/null +++ b/Makefile @@ -0,0 +1,16 @@ +.PHONY: setup + +SHELL = bash + +all: setup + +setup: + command -v pre-commit > /dev/null && pre-commit install + +# https://google.github.io/styleguide/shellguide.html +shell-format: + shfmt -f . | xargs shfmt -i 2 -ci -sr -kp -w + +shell-check: + shfmt -f . | xargs shfmt -i 2 -ci -sr -kp -d + shfmt -f . | xargs shellcheck --color=always From 38513c3bed43b00b09b7f48a434ff178ff871f02 Mon Sep 17 00:00:00 2001 From: jo Date: Mon, 16 Aug 2021 14:04:15 +0200 Subject: [PATCH 2/8] Add shell-check job We don't want to fail on shellcheck yet. --- .github/workflows/test.yml | 21 +++++++++++++++++++++ Makefile | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 47022fa83..333517402 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,6 +25,27 @@ jobs: - uses: actions/setup-python@v2 - uses: pre-commit/action@v2.0.3 + check-shell: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + - run: | + python -m venv venv && source venv/bin/activate + pip install gh-release-install + + sudo venv/bin/gh-release-install \ + koalaman/shellcheck \ + shellcheck-{tag}.linux.x86_64.tar.xz --extract shellcheck-{tag}/shellcheck \ + /usr/bin/shellcheck + + sudo venv/bin/gh-release-install \ + mvdan/sh \ + shfmt_{tag}_linux_amd64 \ + /usr/bin/shfmt + + - run: make shell-check + test: strategy: matrix: diff --git a/Makefile b/Makefile index ef15c9b57..fc8e65144 100644 --- a/Makefile +++ b/Makefile @@ -13,4 +13,4 @@ shell-format: shell-check: shfmt -f . | xargs shfmt -i 2 -ci -sr -kp -d - shfmt -f . | xargs shellcheck --color=always + shfmt -f . | xargs shellcheck --color=always || true From 6c2e5478088b972b50855745b8a34f297f8a45fe Mon Sep 17 00:00:00 2001 From: jo Date: Mon, 16 Aug 2021 22:59:42 +0200 Subject: [PATCH 3/8] Allow custom shellcheck severity Normal severity is normal. CI severity is set to warning, but this should be changed to style (default) once most of the scripts are iether gone or modernized. --- .github/workflows/test.yml | 2 +- Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 333517402..5f534545a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -44,7 +44,7 @@ jobs: shfmt_{tag}_linux_amd64 \ /usr/bin/shfmt - - run: make shell-check + - run: SEVERITY=warning make shell-check test: strategy: diff --git a/Makefile b/Makefile index fc8e65144..c2e69bef5 100644 --- a/Makefile +++ b/Makefile @@ -13,4 +13,4 @@ shell-format: shell-check: shfmt -f . | xargs shfmt -i 2 -ci -sr -kp -d - shfmt -f . | xargs shellcheck --color=always || true + shfmt -f . | xargs shellcheck --color=always --severity=$${SEVERITY:-style} From 8b3e09d41cc9813147ffe4c89b79df3fa7ba9eaa Mon Sep 17 00:00:00 2001 From: jo Date: Mon, 16 Aug 2021 13:45:32 +0200 Subject: [PATCH 4/8] Format shell scripts Fix flags order --- airtime_mvc/tests/runtests.sh | 7 +- build.sh | 34 +- .../liquidsoap_compile/liquidsoap-compile.sh | 58 +- dev_tools/liquidsoap_compile/run.sh | 253 ++- dev_tools/postCommitBuildTrigger.sh | 17 +- dev_tools/propel_regenerate.sh | 8 +- dev_tools/release/release.sh | 35 +- dev_tools/toggle-pypo-debug.sh | 43 +- install | 1620 +++++++++-------- installer/lxc-bootstrap | 8 +- installer/vagrant/centos.sh | 8 +- .../install/initd/libretime-celery | 429 +++-- .../install/sysvinit/libretime-analyzer | 70 +- .../airtime_analyzer/tools/ftp-upload-hook.sh | 69 +- .../tools/test-hook-script.sh | 25 +- .../install/sysvinit/libretime-liquidsoap | 70 +- .../pypo/install/sysvinit/libretime-playout | 70 +- uninstall | 95 +- utils/airtime-log | 4 +- utils/airtime-test-soundcard | 4 +- utils/airtime-test-stream | 4 +- utils/libretime-backup.sh | 20 +- utils/rabbitmq-update-pid.sh | 8 +- utils/rivendell-converter.sh | 27 +- 24 files changed, 1487 insertions(+), 1499 deletions(-) diff --git a/airtime_mvc/tests/runtests.sh b/airtime_mvc/tests/runtests.sh index 61283842d..2d0d3005d 100755 --- a/airtime_mvc/tests/runtests.sh +++ b/airtime_mvc/tests/runtests.sh @@ -14,8 +14,8 @@ rabbitmqctl list_vhosts | grep $RABBITMQ_VHOST RESULT="$?" if [ $RESULT = "0" ]; then - rabbitmqctl delete_vhost $RABBITMQ_VHOST - rabbitmqctl delete_user $RABBITMQ_USER + rabbitmqctl delete_vhost $RABBITMQ_VHOST + rabbitmqctl delete_user $RABBITMQ_USER fi rabbitmqctl add_vhost $RABBITMQ_VHOST @@ -29,9 +29,8 @@ export RABBITMQ_VHOST export AIRTIME_UNIT_TEST="1" #Change the working directory to this script's directory -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" && pwd)" cd $DIR #Run the unit tests phpunit --verbose --log-junit test_results.xml - diff --git a/build.sh b/build.sh index 1f8e48784..3323a815b 100755 --- a/build.sh +++ b/build.sh @@ -3,25 +3,25 @@ composer install --no-dev --no-interaction git_build="" if [ -d .git ]; then - echo " * Building from Git" - git_build="y" + echo " * Building from Git" + git_build="y" fi if [ "${git_build}" = "y" ]; then - git_version=`git tag --points-at HEAD` - echo " * Version from tag: ${git_version}" - if [ "${git_version}" = "" ]; then - git_version=`git rev-parse --short HEAD` - echo " * Overriding empty version with sha1 commit-ish: ${git_version}" - fi - echo ${git_version} > VERSION + git_version=$(git tag --points-at HEAD) + echo " * Version from tag: ${git_version}" + if [ "${git_version}" = "" ]; then + git_version=$(git rev-parse --short HEAD) + echo " * Overriding empty version with sha1 commit-ish: ${git_version}" + fi + echo ${git_version} > VERSION else - # if no file was in tarball we create one letting the user know - # if you run in to this you should grab an enriched tarball built - # by travis. It already contains the VERSION file and also bundles - # all the PHP you vendors files making the install much faster on - # your part. - if [ ! -f VERSION ]; then - echo "could not detect version for VERSION file" > VERSION - fi + # if no file was in tarball we create one letting the user know + # if you run in to this you should grab an enriched tarball built + # by travis. It already contains the VERSION file and also bundles + # all the PHP you vendors files making the install much faster on + # your part. + if [ ! -f VERSION ]; then + echo "could not detect version for VERSION file" > VERSION + fi fi diff --git a/dev_tools/liquidsoap_compile/liquidsoap-compile.sh b/dev_tools/liquidsoap_compile/liquidsoap-compile.sh index 67b394352..60085831e 100755 --- a/dev_tools/liquidsoap_compile/liquidsoap-compile.sh +++ b/dev_tools/liquidsoap_compile/liquidsoap-compile.sh @@ -1,8 +1,8 @@ #!/bin/bash -e apt-get install -y --force-yes lsb-release sudo -dist=`lsb_release -is` -code=`lsb_release -cs` -cpu=`getconf LONG_BIT` +dist=$(lsb_release -is) +code=$(lsb_release -cs) +cpu=$(getconf LONG_BIT) cpuvalue= #enable apt.sourcefabric.org source @@ -11,41 +11,39 @@ grep -E "deb http://apt.sourcefabric.org $code main" /etc/apt/sources.list returncode=$? set -e if [ "$returncode" -ne "0" ]; then - echo "deb http://apt.sourcefabric.org $code main" >> /etc/apt/sources.list + echo "deb http://apt.sourcefabric.org $code main" >> /etc/apt/sources.list fi apt-get update apt-get -y --force-yes install sourcefabric-keyring apt-get update - - if [ "$dist" = "Ubuntu" ]; then - set +e - grep -E "deb http://ca.archive.ubuntu.com/ubuntu/ $code multiverse" /etc/apt/sources.list - returncode=$? - set -e - if [ "$returncode" -ne "0" ]; then - echo "deb http://ca.archive.ubuntu.com/ubuntu/ $code multiverse" >> /etc/apt/sources.list - echo "deb http://ca.archive.ubuntu.com/ubuntu/ $code universe" >> /etc/apt/sources.list - fi + set +e + grep -E "deb http://ca.archive.ubuntu.com/ubuntu/ $code multiverse" /etc/apt/sources.list + returncode=$? + set -e + if [ "$returncode" -ne "0" ]; then + echo "deb http://ca.archive.ubuntu.com/ubuntu/ $code multiverse" >> /etc/apt/sources.list + echo "deb http://ca.archive.ubuntu.com/ubuntu/ $code universe" >> /etc/apt/sources.list + fi fi #enable squeeze backports to get lame packages if [ "$dist" = "Debian" -a "$code" = "squeeze" ]; then - set +e - grep -E "deb http://backports.debian.org/debian-backports squeeze-backports main" /etc/apt/sources.list - returncode=$? - set -e - if [ "$returncode" -ne "0" ]; then - echo "deb http://backports.debian.org/debian-backports squeeze-backports main" >> /etc/apt/sources.list - fi + set +e + grep -E "deb http://backports.debian.org/debian-backports squeeze-backports main" /etc/apt/sources.list + returncode=$? + set -e + if [ "$returncode" -ne "0" ]; then + echo "deb http://backports.debian.org/debian-backports squeeze-backports main" >> /etc/apt/sources.list + fi fi echo "System is $cpu bit..." if [ "$cpu" = "64" ]; then - cpuvalue="amd64" + cpuvalue="amd64" else - cpuvalue="i386" + cpuvalue="i386" fi apt-get update @@ -62,14 +60,14 @@ apt-get -y --force-yes install libopus0 libopus-dev libopus-dbg libopus-doc #obsoleted code end apt-get -y --force-yes install git-core ocaml-findlib libao-ocaml-dev \ -libportaudio-ocaml-dev libmad-ocaml-dev libtaglib-ocaml-dev libalsa-ocaml-dev \ -libvorbis-ocaml-dev libladspa-ocaml-dev libxmlplaylist-ocaml-dev libflac-dev \ -libxml-dom-perl libxml-dom-xpath-perl patch autoconf libmp3lame-dev \ -libcamomile-ocaml-dev libcamlimages-ocaml-dev libtool libpulse-dev camlidl \ -libfaad-dev libpcre-ocaml-dev libfftw3-3 dialog + libportaudio-ocaml-dev libmad-ocaml-dev libtaglib-ocaml-dev libalsa-ocaml-dev \ + libvorbis-ocaml-dev libladspa-ocaml-dev libxmlplaylist-ocaml-dev libflac-dev \ + libxml-dom-perl libxml-dom-xpath-perl patch autoconf libmp3lame-dev \ + libcamomile-ocaml-dev libcamlimages-ocaml-dev libtool libpulse-dev camlidl \ + libfaad-dev libpcre-ocaml-dev libfftw3-3 dialog if [ "$code" != "lucid" ]; then - apt-get -y --force-yes install libvo-aacenc-dev + apt-get -y --force-yes install libvo-aacenc-dev fi #dpkg -i libopus-dbg_1.0.1~$code~sfo-1_$cpuvalue.deb libopus-dev_1.0.1~$code~sfo-1_$cpuvalue.deb libopus0_1.0.1~$code~sfo-1_$cpuvalue.deb aacplusenc_0.17.5-0.0medibuntu1_$cpuvalue.deb @@ -111,7 +109,7 @@ sed -i "s/#ocaml-opus/ocaml-opus/g" PACKAGES #sed -i "s/#ocaml-aacplus/ocaml-aacplus/g" PACKAGES #sed -i "s/#ocaml-shine/ocaml-shine/g" PACKAGES if [ "$code" != "lucid" ]; then - sed -i "s/#ocaml-voaacenc/ocaml-voaacenc/g" PACKAGES + sed -i "s/#ocaml-voaacenc/ocaml-voaacenc/g" PACKAGES fi chown -R tmp /liquidsoap-full diff --git a/dev_tools/liquidsoap_compile/run.sh b/dev_tools/liquidsoap_compile/run.sh index 12ddbb1d9..285ca1d84 100755 --- a/dev_tools/liquidsoap_compile/run.sh +++ b/dev_tools/liquidsoap_compile/run.sh @@ -5,88 +5,88 @@ exec 2>&1 ROOT_UID="0" #Check if run as root -if [ "$UID" -ne "$ROOT_UID" ] ; then - echo "You must have 'sudo' right to do that!" - exit 1 +if [ "$UID" -ne "$ROOT_UID" ]; then + echo "You must have 'sudo' right to do that!" + exit 1 fi rm -rf ./liquidsoap-compile_logs mkdir -p ./liquidsoap-compile_logs -showhelp () { - echo "Usage: run.sh [options] [parameters] +showhelp() { + echo "Usage: run.sh [options] [parameters] -c all|ubuntu_lucid_32 Compile liquidsoap on all platforms or specified platform. -b all|ubuntu_lucid_32 Build shroot environments for all platforms or specified platform. -u username Local username will be used as sudo user of chroot env. Must be assigned before -b options" - exit 0 + exit 0 } -build_env () { - if [ $sudo_user = "-1" ];then - echo "Please use -u to assign sudo username before build environments." - exit 1 - fi +build_env() { + if [ $sudo_user = "-1" ]; then + echo "Please use -u to assign sudo username before build environments." + exit 1 + fi - echo "build_env $1" - #exec > >(tee ./liquidsoap_compile_logs/build_env_$1.log) - os=`echo $1 | awk '/(debian)/'` - cpu=`echo $1 | awk '/(64)/'` - dist=`echo $1 | awk -F "_" '{print $2}'` + echo "build_env $1" + #exec > >(tee ./liquidsoap_compile_logs/build_env_$1.log) + os=$(echo $1 | awk '/(debian)/') + cpu=$(echo $1 | awk '/(64)/') + dist=$(echo $1 | awk -F "_" '{print $2}') - rm -f /etc/schroot/chroot.d/$1.conf - if cat /etc/passwd | awk -F:'{print $1}' | grep "tmp" >/dev/null 2>&1;then - echo "User tmp exists." + rm -f /etc/schroot/chroot.d/$1.conf + if cat /etc/passwd | awk -F:'{print $1}' | grep "tmp" > /dev/null 2>&1; then + echo "User tmp exists." + else + useradd tmp + echo "User tmp is created." + fi + + apt-get update + apt-get --force-yes -y install debootstrap dchroot + echo [$1] > /etc/schroot/chroot.d/$1.conf + echo description=$1 >> /etc/schroot/chroot.d/$1.conf + echo directory=/srv/chroot/$1 >> /etc/schroot/chroot.d/$1.conf + echo type=directory >> /etc/schroot/chroot.d/$1.conf + echo users=$sudo_user,tmp >> /etc/schroot/chroot.d/$1.conf + echo root-users=$sudo_user >> /etc/schroot/chroot.d/$1.conf + rm -rf /srv/chroot/$1 + mkdir -p /srv/chroot/$1 + + #cp liquidsoap_compile.sh /srv/chroot/$1/ + if [ "$os" = "" ]; then + if [ "$cpu" = "" ]; then + echo "debootstrap --variant=buildd --arch=i386 $dist /srv/chroot/$1 http://archive.ubuntu.com/ubuntu/" + debootstrap --variant=buildd --arch=i386 $dist /srv/chroot/$1 http://archive.ubuntu.com/ubuntu/ else - useradd tmp - echo "User tmp is created." + echo "debootstrap --variant=buildd --arch=amd64 $dist /srv/chroot/$1 http://archive.ubuntu.com/ubuntu/" + debootstrap --variant=buildd --arch=amd64 $dist /srv/chroot/$1 http://archive.ubuntu.com/ubuntu/ fi - - apt-get update - apt-get --force-yes -y install debootstrap dchroot - echo [$1] > /etc/schroot/chroot.d/$1.conf - echo description=$1 >> /etc/schroot/chroot.d/$1.conf - echo directory=/srv/chroot/$1 >> /etc/schroot/chroot.d/$1.conf - echo type=directory >> /etc/schroot/chroot.d/$1.conf - echo users=$sudo_user,tmp >> /etc/schroot/chroot.d/$1.conf - echo root-users=$sudo_user >> /etc/schroot/chroot.d/$1.conf - rm -rf /srv/chroot/$1 - mkdir -p /srv/chroot/$1 - - #cp liquidsoap_compile.sh /srv/chroot/$1/ - if [ "$os" = "" ];then - if [ "$cpu" = "" ];then - echo "debootstrap --variant=buildd --arch=i386 $dist /srv/chroot/$1 http://archive.ubuntu.com/ubuntu/" - debootstrap --variant=buildd --arch=i386 $dist /srv/chroot/$1 http://archive.ubuntu.com/ubuntu/ - else - echo "debootstrap --variant=buildd --arch=amd64 $dist /srv/chroot/$1 http://archive.ubuntu.com/ubuntu/" - debootstrap --variant=buildd --arch=amd64 $dist /srv/chroot/$1 http://archive.ubuntu.com/ubuntu/ - fi + else + if [ "$cpu" = "" ]; then + echo "debootstrap --variant=buildd --arch=i386 $dist /srv/chroot/$1 http://ftp.debian.com/debian/" + debootstrap --variant=buildd --arch=i386 $dist /srv/chroot/$1 http://ftp.debian.com/debian/ else - if [ "$cpu" = "" ];then - echo "debootstrap --variant=buildd --arch=i386 $dist /srv/chroot/$1 http://ftp.debian.com/debian/" - debootstrap --variant=buildd --arch=i386 $dist /srv/chroot/$1 http://ftp.debian.com/debian/ - else - echo "debootstrap --variant=buildd --arch=amd64 $dist /srv/chroot/$1 http://ftp.debian.com/debian/" - debootstrap --variant=buildd --arch=amd64 $dist /srv/chroot/$1 http://ftp.debian.com/debian/ - fi + echo "debootstrap --variant=buildd --arch=amd64 $dist /srv/chroot/$1 http://ftp.debian.com/debian/" + debootstrap --variant=buildd --arch=amd64 $dist /srv/chroot/$1 http://ftp.debian.com/debian/ fi + fi } -compile_liq () { - echo "complie_liq $1" - #exec > >(tee ./liquidsoap_compile_logs/compile_liq_$1.log) - binfilename=`echo $1 | sed -e 's/ubuntu/liquidsoap/g' -e 's/debian/liquidsoap/g' -e 's/32/i386/g' -e 's/64/amd64/g'` - rm -f /srv/chroot/$1/liquidsoap-compile.sh - rm -f /srv/chroot/$1/liquidsoap - cp liquidsoap-compile.sh /srv/chroot/$1/ - schroot -c $1 -u root -d / -- /liquidsoap-compile.sh - cp /srv/chroot/$1/liquidsoap ./$binfilename - if [ $? = 0 ];then - echo "$binfilename is generated successfully" - else - mv ./liquidsoap-compile_logs/compile_liq_$1.log ./liquidsoap-compile_logs/fail_to_compile_liq_$1.log - fi +compile_liq() { + echo "complie_liq $1" + #exec > >(tee ./liquidsoap_compile_logs/compile_liq_$1.log) + binfilename=$(echo $1 | sed -e 's/ubuntu/liquidsoap/g' -e 's/debian/liquidsoap/g' -e 's/32/i386/g' -e 's/64/amd64/g') + rm -f /srv/chroot/$1/liquidsoap-compile.sh + rm -f /srv/chroot/$1/liquidsoap + cp liquidsoap-compile.sh /srv/chroot/$1/ + schroot -c $1 -u root -d / -- /liquidsoap-compile.sh + cp /srv/chroot/$1/liquidsoap ./$binfilename + if [ $? = 0 ]; then + echo "$binfilename is generated successfully" + else + mv ./liquidsoap-compile_logs/compile_liq_$1.log ./liquidsoap-compile_logs/fail_to_compile_liq_$1.log + fi } os_versions=("ubuntu_lucid_32" "ubuntu_lucid_64" "ubuntu_precise_32" "ubuntu_precise_64" "ubuntu_quantal_32" "ubuntu_quantal_64" "ubuntu_raring_32" "ubuntu_raring_64" "debian_squeeze_32" "debian_squeeze_64" "debian_wheezy_32" "debian_wheezy_64") @@ -96,74 +96,67 @@ flag= os= sudo_user="-1" -if [ x$1 = x ];then - showhelp +if [ x$1 = x ]; then + showhelp fi -while getopts b:c:u: arg -do - case $arg in - b) - if [ "$OPTARG" = "all" ];then - echo "Building all platforms on server..." - for i in $(seq 0 $(($num -1))); - do - build_env ${os_versions[$i]} | tee ./liquidsoap-compile_logs/build_env_${os_versions[$i]}.log - done - else - flag=1 - for i in $(seq 0 $(($num -1))); - do - if [ "$OPTARG" = ${os_versions[$i]} ];then - echo "Building platform: $OPTARG ..." - build_env ${os_versions[$i]} | tee ./liquidsoap-compile_logs/build_env_${os_versions[$i]}.log - flag=0 - fi - done - if [ $flag = 1 ];then - echo "Unsupported Platform from:" - for j in "${os_versions[@]}" - do - echo $j - done - exit 1 - fi - fi - ;; - c) - if [ "$OPTARG" = "all" ];then - echo "Compiling liquidsoap for all platforms on server..." - for i in $(seq 0 $(($num -1))) - do - compile_liq ${os_versions[$i]} | tee ./liquidsoap-compile_logs/compile_liq_${os_versions[$i]}.log - done +while getopts b:c:u: arg; do + case $arg in + b) + if [ "$OPTARG" = "all" ]; then + echo "Building all platforms on server..." + for i in $(seq 0 $(($num - 1))); do + build_env ${os_versions[$i]} | tee ./liquidsoap-compile_logs/build_env_${os_versions[$i]}.log + done + else + flag=1 + for i in $(seq 0 $(($num - 1))); do + if [ "$OPTARG" = ${os_versions[$i]} ]; then + echo "Building platform: $OPTARG ..." + build_env ${os_versions[$i]} | tee ./liquidsoap-compile_logs/build_env_${os_versions[$i]}.log + flag=0 + fi + done + if [ $flag = 1 ]; then + echo "Unsupported Platform from:" + for j in "${os_versions[@]}"; do + echo $j + done + exit 1 + fi + fi + ;; + c) + if [ "$OPTARG" = "all" ]; then + echo "Compiling liquidsoap for all platforms on server..." + for i in $(seq 0 $(($num - 1))); do + compile_liq ${os_versions[$i]} | tee ./liquidsoap-compile_logs/compile_liq_${os_versions[$i]}.log + done - else - flag=1 - for i in $(seq 0 $(($num -1))); - do - if [ "$OPTARG" = ${os_versions[$i]} ];then - echo "Compiling liquidsoap for platform: $OPTARG ..." - compile_liq ${os_versions[$i]} | tee ./liquidsoap-compile_logs/compile_liq_${os_versions[$i]}.log - flag=0 - fi - done - if [ $flag = 1 ];then - echo "Unsupported Platform from:" - for k in "${os_versions[@]}" - do - echo $k - done - exit 1 - fi - fi - ;; - u) - sudo_user="$OPTARG" - echo "sudo_user is set as $sudo_user." - ;; - ?) - showhelp - ;; - esac + else + flag=1 + for i in $(seq 0 $(($num - 1))); do + if [ "$OPTARG" = ${os_versions[$i]} ]; then + echo "Compiling liquidsoap for platform: $OPTARG ..." + compile_liq ${os_versions[$i]} | tee ./liquidsoap-compile_logs/compile_liq_${os_versions[$i]}.log + flag=0 + fi + done + if [ $flag = 1 ]; then + echo "Unsupported Platform from:" + for k in "${os_versions[@]}"; do + echo $k + done + exit 1 + fi + fi + ;; + u) + sudo_user="$OPTARG" + echo "sudo_user is set as $sudo_user." + ;; + ?) + showhelp + ;; + esac done diff --git a/dev_tools/postCommitBuildTrigger.sh b/dev_tools/postCommitBuildTrigger.sh index 9bb411c3d..80e667126 100755 --- a/dev_tools/postCommitBuildTrigger.sh +++ b/dev_tools/postCommitBuildTrigger.sh @@ -10,16 +10,15 @@ baseurl="$1/updateAndBuild.action?buildKey=" # Moves to the 2nd param (first is URL) shift # Loop for each build key -while (( "$#" )); do +while (("$#")); do - # - # Invoke the trigger - # - remoteCall=$baseurl$1 - echo "Detected last directory that was committed ... triggering $remoteCall" - /usr/bin/wget --timeout=10 -t1 $remoteCall -O /dev/null - shift + # + # Invoke the trigger + # + remoteCall=$baseurl$1 + echo "Detected last directory that was committed ... triggering $remoteCall" + /usr/bin/wget --timeout=10 -t1 $remoteCall -O /dev/null + shift done - exit 0 diff --git a/dev_tools/propel_regenerate.sh b/dev_tools/propel_regenerate.sh index 1ecb7b53e..1d5addec2 100755 --- a/dev_tools/propel_regenerate.sh +++ b/dev_tools/propel_regenerate.sh @@ -1,11 +1,11 @@ #!/bin/bash -e # Absolute path to this script -SCRIPT=`readlink -f $0` +SCRIPT=$(readlink -f $0) # Absolute directory this script is in -SCRIPTPATH=`dirname $SCRIPT` +SCRIPTPATH=$(dirname $SCRIPT) cd $SCRIPTPATH/../airtime_mvc/ -path=`pwd` +path=$(pwd) cd build -sed -i s#"project\.home =.*$"#"project.home = $path"#g build.properties +sed -i s:"project\.home =.*$":"project.home = $path":g build.properties ../../vendor/propel/propel1/generator/bin/propel-gen diff --git a/dev_tools/release/release.sh b/dev_tools/release/release.sh index 1f25f9147..21029611f 100755 --- a/dev_tools/release/release.sh +++ b/dev_tools/release/release.sh @@ -13,14 +13,14 @@ #creates tarballs with a "1.8.2-RC" suffix if [ $# == 0 ]; then - echo "Zero arguments" - exit + echo "Zero arguments" + exit elif [ $# == 1 ]; then - suffix=$1 - version=$1 + suffix=$1 + version=$1 else - suffix=$1-$2 - version=$1 + suffix=$1-$2 + version=$1 fi dir=$(dirname $(readlink -f $0)) @@ -64,19 +64,18 @@ pushd /tmp/ find libretime-${suffix} -type f -exec dos2unix {} \; echo -n "Creating tarball..." tar -czf $target_file \ - --owner=root --group=root \ - --exclude-vcs \ - --exclude .zfproject.xml \ - --exclude .gitignore \ - --exclude .gitattributes \ - --exclude .travis.yml \ - --exclude travis \ - --exclude dev_tools \ - --exclude vendor/phing \ - --exclude vendor/simplepie/simplepie/tests \ - libretime-${suffix} + --owner=root --group=root \ + --exclude-vcs \ + --exclude .zfproject.xml \ + --exclude .gitignore \ + --exclude .gitattributes \ + --exclude .travis.yml \ + --exclude travis \ + --exclude dev_tools \ + --exclude vendor/phing \ + --exclude vendor/simplepie/simplepie/tests \ + libretime-${suffix} echo " Done" popd - echo "Output file available at $target_file" diff --git a/dev_tools/toggle-pypo-debug.sh b/dev_tools/toggle-pypo-debug.sh index b10c6b47e..4734b542b 100755 --- a/dev_tools/toggle-pypo-debug.sh +++ b/dev_tools/toggle-pypo-debug.sh @@ -1,38 +1,37 @@ #!/bin/bash if [[ $EUID -ne 0 ]]; then - echo "This script must be run as root." 1>&2 - exit 1 + echo "This script must be run as root." 1>&2 + exit 1 fi -usage () { - echo "Use --enable or --disable flag. Enable is to set up environment" - echo "for specified user. --disable is to reset it back to pypo user" +usage() { + echo "Use --enable or --disable flag. Enable is to set up environment" + echo "for specified user. --disable is to reset it back to pypo user" } if [ "$1" = "--enable" ]; then - /etc/init.d/airtime-playout stop - /etc/init.d/airtime-playout start-liquidsoap + /etc/init.d/airtime-playout stop + /etc/init.d/airtime-playout start-liquidsoap - user=$2 + user=$2 - echo "Changing ownership to user $1" - chmod -R a+rw /var/log/airtime/pypo - chmod a+r /etc/airtime/airtime.conf - chown -Rv $user:$user /var/tmp/airtime/pypo/ - chmod -v a+r /etc/airtime/api_client.cfg + echo "Changing ownership to user $1" + chmod -R a+rw /var/log/airtime/pypo + chmod a+r /etc/airtime/airtime.conf + chown -Rv $user:$user /var/tmp/airtime/pypo/ + chmod -v a+r /etc/airtime/api_client.cfg elif [ "$1" = "--disable" ]; then - user="pypo" + user="pypo" - echo "Changing ownership to user $1" - chmod 644 /etc/airtime/airtime.conf - chown -Rv $user:$user /var/tmp/airtime/pypo/ - chmod -v a+r /etc/airtime/api_client.cfg + echo "Changing ownership to user $1" + chmod 644 /etc/airtime/airtime.conf + chown -Rv $user:$user /var/tmp/airtime/pypo/ + chmod -v a+r /etc/airtime/api_client.cfg - - /etc/init.d/airtime-playout stop-liquidsoap - /etc/init.d/airtime-playout start + /etc/init.d/airtime-playout stop-liquidsoap + /etc/init.d/airtime-playout start else - usage + usage fi diff --git a/install b/install index 56f13f875..54913f6de 100755 --- a/install +++ b/install @@ -4,14 +4,14 @@ #return with a non-zero return value. if [[ $EUID -ne 0 ]]; then - echo "Please run as root user." - exit 1 + echo "Please run as root user." + exit 1 fi -SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )" +SCRIPT_DIR="$( cd "$( dirname "$0")" && pwd)" AIRTIMEROOT=${SCRIPT_DIR} -showhelp () { +showhelp() { echo "Usage: sudo bash install [options] -h, --help, -? Display usage information @@ -57,19 +57,18 @@ showhelp () { Skips all postgres related install tasks (Useful if you configure postgresql as part of another script / docker builds) --no-rabbitmq - Skips all rabbitmq related install tasks. - " + Skips all rabbitmq related install tasks." exit 0 } -showversion () { - if [ ! -f "$SCRIPT_DIR/VERSION" ]; then - echo "Please initialize LibreTime by running ./build.sh" - exit 1 - fi - version=$(cat "$SCRIPT_DIR/VERSION") - echo "LibreTime Version ${version}" - exit 0 +showversion() { + if [ ! -f "$SCRIPT_DIR/VERSION" ]; then + echo "Please initialize LibreTime by running ./build.sh" + exit 1 + fi + version=$(cat "$SCRIPT_DIR/VERSION") + echo "LibreTime Version ${version}" + exit 0 } web_user="" @@ -96,38 +95,38 @@ skip_rabbitmq=0 default_value="Y" function verbose() { - if [[ ${_v} -eq 1 ]]; then - echo -e "$@" - fi + if [[ ${_v} -eq 1 ]]; then + echo -e "$@" + fi } function loud() { - if [[ ${_q} -eq 0 ]]; then - echo -e "$@" - fi + if [[ ${_q} -eq 0 ]]; then + echo -e "$@" + fi } # Evaluate commands silently if quiet. # If not quiet, output command if verbose. function loudCmd() { - if [[ ${_q} -eq 0 ]]; then - verbose "$@" - eval $@ - else - eval $@ > /dev/null - fi + if [[ ${_q} -eq 0 ]]; then + verbose "$@" + eval $@ + else + eval $@ > /dev/null + fi } function checkCommandExists() { - set +e - command=$@ - eval hash ${command} 2>/dev/null - commandFound=$? - if [[ ! ${commandFound} -eq 0 ]]; then - echo -e "Error: ${command} not found. Please ensure you have the corresponding dependency installed." - exit - fi - set -e + set +e + command=$@ + eval hash ${command} 2> /dev/null + commandFound=$? + if [[ ! ${commandFound} -eq 0 ]]; then + echo -e "Error: ${command} not found. Please ensure you have the corresponding dependency installed." + exit + fi + set -e } # Function to determine if systemd, Upstart or System V Init is the active @@ -143,27 +142,37 @@ has_systemd_init=false has_upstart_init=false has_systemv_init=false function systemInitDetect() { - verbose "\nDetecting init system type ..." - # Get the path of the command where pid=1 following any symlinks - pid_1_path=$(readlink --canonicalize -n /proc/1/exe) - # returns '(/usr)?/lib/systemd/systemd' (Debian Buster, CentOS 7) - verbose "Detected path to PID=1 process: $pid_1_path" - # Get package of PID=1 path as it identifies the init system. - # Allow this to fail, at least then the init system can be guessed from the - # PID 1 executable alone - pid_1_package=$(dpkg -S $pid_1_path 2>/dev/null || - rpm --qf '%{name}\n' -qf $pid_1_path 2>/dev/null || - echo "unknown") - verbose "Detected package name for PID=1 process: $pid_1_package" - case "${pid_1_package}:${pid_1_path}" in - *systemd*) has_systemd_init=true; verbose "Detected init system type: systemd" ;; - *upstart*) has_upstart_init=true; verbose "Detected init system type: Upstart" ;; - *sysvinit*) has_systemv_init=true; verbose "Detected init system type: System V" ;; - *) echo "ERROR: Unable to detect init system using package or path of PID=1 process!" >&2 - exit 1 - ;; - esac - return 0 + verbose "\nDetecting init system type ..." + # Get the path of the command where pid=1 following any symlinks + pid_1_path=$(readlink --canonicalize -n /proc/1/exe) + # returns '(/usr)?/lib/systemd/systemd' (Debian Buster, CentOS 7) + verbose "Detected path to PID=1 process: $pid_1_path" + # Get package of PID=1 path as it identifies the init system. + # Allow this to fail, at least then the init system can be guessed from the + # PID 1 executable alone + pid_1_package=$(dpkg -S $pid_1_path 2> /dev/null || + rpm --qf '%{name}\n' -qf $pid_1_path 2> /dev/null || + echo "unknown") + verbose "Detected package name for PID=1 process: $pid_1_package" + case "${pid_1_package}:${pid_1_path}" in + *systemd*) + has_systemd_init=true + verbose "Detected init system type: systemd" + ;; + *upstart*) + has_upstart_init=true + verbose "Detected init system type: Upstart" + ;; + *sysvinit*) + has_systemv_init=true + verbose "Detected init system type: System V" + ;; + *) + echo "ERROR: Unable to detect init system using package or path of PID=1 process!" >&2 + exit 1 + ;; + esac + return 0 } # Function to wrap installation of services for systemd, Upstart and System V @@ -174,165 +183,165 @@ function systemInitDetect() { # Usage: # systemInitInstall service-name [user] function systemInitInstall() { - local service_name="$1" - local user="$2" - local source_base_path="" - local source_path="" - local target_path="" - local alt_path="" - local source_config_path="" - local target_config_path="" - local python_source_path="${SCRIPT_DIR-$PWD}/python_apps" - verbose "\n * Installing service $service_name ..." - if $has_systemd_init; then - case "$service_name" in - libretime-analyzer) - source_path="${python_source_path}/airtime_analyzer/install/systemd/${service_name}.service" - target_path="/etc/systemd/system/${service_name}.service" - alt_path=$(echo $target_path | sed 's/libretime-/airtime_/') - ;; - libretime-celery) - source_path="${python_source_path}/airtime-celery/install/systemd/${service_name}.service" - target_path="/etc/systemd/system/${service_name}.service" - alt_path=$(echo $target_path | sed 's/libretime-/airtime-/') - ;; - libretime-liquidsoap|libretime-playout) - source_path="${python_source_path}/pypo/install/systemd/${service_name}.service" - target_path="/etc/systemd/system/${service_name}.service" - alt_path=$(echo $target_path | sed 's/libretime-/airtime-/') - ;; - libretime-api) - source_path="${SCRIPT_DIR-$PWD}/api/install/systemd/${service_name}.service" - target_path="/etc/systemd/system/${service_name}.service" - alt_path=$(echo $target_path | sed 's/libretime-/airtime-/') - ;; - esac - if [[ ! -e $source_path ]]; then - echo "$0:${FUNCNAME}(): ERROR: service \"$service_name\" with source path \"$source_path\" does not exist!" >&2 - exit 1 - fi - # Stop and disable the service if it already exists - if [[ -e $target_path ]]; then - verbose "Service $service_name already exists - stopping and disabling." - loudCmd "systemctl disable ${service_name}.service" - loudCmd "systemctl stop ${service_name}.service" - fi - local old_style_unit_exists="f" - # Migrate old style airtime unit exist if it exists - if [[ -e $alt_path && ! -L $alt_path ]]; then - local old_service=$(echo $service_name | sed 's/libretime/airtime/' | sed 's/-analyzer/_analyzer/') - verbose "Old service $old_service already exists - migrating." - loudCmd "systemctl disable ${old_service}.service" - loudCmd "systemctl stop ${old_service}.service" - loudCmd "rm $alt_path" - old_style_unit_exists="t" - fi - # If no user defined, then just copy, otherwise filter - if [[ -z $user ]]; then - loudCmd "cp $source_path $target_path" - else - sed -e "s/User=.*/User=${user}/" \ - -e "s/Group=.*/Group=${user}/" $source_path > $target_path - fi - if [[ $old_style_unit_exists == "t" ]]; then - verbose "Maintaining compatibility with old systemd unit names" - # Alias to old Airtime names - loudCmd "ln -s $source_path $alt_path" - fi - chmod 0644 $target_path - chown root:root $target_path - verbose "Service ${service_name} installed into ${target_path}" - # Enable and start the service - loudCmd "systemctl enable ${service_name}.service" - verbose "Service ${service_name} enabled and started" - elif $has_upstart_init; then - case "$service_name" in - libretime-analyzer) - source_path="${python_source_path}/airtime_analyzer/install/upstart/${service_name}.conf" - target_path="/etc/init/${service_name}.conf" - user=${user:-$web_user} - ;; - libretime-celery) - source_path="${python_source_path}/airtime-celery/install/upstart/${service_name}.conf" - target_path="/etc/init/${service_name}.conf" - user="" - ;; - libretime-liquidsoap|libretime-playout) - source_path="${python_source_path}/pypo/install/upstart/${service_name}.conf.template" - target_path="/etc/init/${service_name}.conf" - user=${user:-$web_user} - ;; - esac - if [[ ! -e $source_path ]]; then - echo "$0:${FUNCNAME}(): ERROR: service \"$service_name\" with source path \"$source_path\" does not exist!" >&2 - exit 1 - fi - # Stop the service if it already exists - if [[ -e $target_path ]]; then - verbose "Service $service_name already exists - stopping." - loudCmd "service ${service_name} stop" - fi - # If no user defined, then just copy, otherwise filter - if [[ -z $user ]]; then - loudCmd "cp $source_path $target_path" - else - sed -e "s/WEB_USER/${user}/g" \ - -e "/^set[gu]id/{s/www-data/${user}/}" $source_path > $target_path - fi - chmod 0644 $target_path - chown root:root $target_path - verbose "Service ${service_name} installed into ${target_path}" - loudCmd "initctl check-config $service_name" - elif $has_systemv_init; then - case "$service_name" in - libretime-analyzer) - source_path="${python_source_path}/airtime_analyzer/install/sysvinit/${service_name}" - target_path="/etc/init.d/${service_name}" - user=${user:-$web_user} - ;; - libretime-celery) - source_path="${python_source_path}/airtime-celery/install/sysvinit/${service_name}" - target_path="/etc/init.d/${service_name}" - source_config_path="${python_source_path}/${service_name}/install/conf/${service_name}" - target_config_path="/etc/default/${service_name}" - user="" - ;; - libretime-liquidsoap|libretime-playout) - source_path="${python_source_path}/pypo/install/sysvinit/${service_name}" - target_path="/etc/init.d/${service_name}" - user=${user:-$web_user} - ;; - esac - if [[ ! -e $source_path ]]; then - echo "$0:${FUNCNAME}(): ERROR: service \"$service_name\" with source path \"$source_path\" does not exist!" >&2 - exit 1 - fi - # Stop the service if it already exists - if [[ -e $target_path ]]; then - verbose "Service $service_name already exists - stopping." - loudCmd "invoke-rc.d $service_name stop" - fi - # If no user defined, then just copy, otherwise filter - if [[ -z $user ]]; then - loudCmd "cp $source_path $target_path" - [[ -n $source_config_path ]] && - loudCmd "cp $source_config_path $target_config_path" - else - sed -e "/^USERID/{s/www-data/${user}/}" \ - -e "/^GROUPID/{s/www-data/${user}/}" $source_path > $target_path - fi - chmod 0644 $target_path - chown root:root $target_path - if [[ -n $target_config_path ]]; then - chmod 0644 $target_config_path - chown root:root $target_config_path - fi - verbose "Service ${service_name} installed into ${target_path}" - # Create symlinks for the appropriate runlevels - loudCmd "update-rc.d $service_name defaults" - verbose "Service ${service_name} enabled" + local service_name="$1" + local user="$2" + local source_base_path="" + local source_path="" + local target_path="" + local alt_path="" + local source_config_path="" + local target_config_path="" + local python_source_path="${SCRIPT_DIR-$PWD}/python_apps" + verbose "\n * Installing service $service_name ..." + if $has_systemd_init; then + case "$service_name" in + libretime-analyzer) + source_path="${python_source_path}/airtime_analyzer/install/systemd/${service_name}.service" + target_path="/etc/systemd/system/${service_name}.service" + alt_path=$(echo $target_path | sed 's/libretime-/airtime_/') + ;; + libretime-celery) + source_path="${python_source_path}/airtime-celery/install/systemd/${service_name}.service" + target_path="/etc/systemd/system/${service_name}.service" + alt_path=$(echo $target_path | sed 's/libretime-/airtime-/') + ;; + libretime-liquidsoap | libretime-playout) + source_path="${python_source_path}/pypo/install/systemd/${service_name}.service" + target_path="/etc/systemd/system/${service_name}.service" + alt_path=$(echo $target_path | sed 's/libretime-/airtime-/') + ;; + libretime-api) + source_path="${SCRIPT_DIR-$PWD}/api/install/systemd/${service_name}.service" + target_path="/etc/systemd/system/${service_name}.service" + alt_path=$(echo $target_path | sed 's/libretime-/airtime-/') + ;; + esac + if [[ ! -e $source_path ]]; then + echo "$0:${FUNCNAME}(): ERROR: service \"$service_name\" with source path \"$source_path\" does not exist!" >&2 + exit 1 fi - return 0 + # Stop and disable the service if it already exists + if [[ -e $target_path ]]; then + verbose "Service $service_name already exists - stopping and disabling." + loudCmd "systemctl disable ${service_name}.service" + loudCmd "systemctl stop ${service_name}.service" + fi + local old_style_unit_exists="f" + # Migrate old style airtime unit exist if it exists + if [[ -e $alt_path && ! -L $alt_path ]]; then + local old_service=$(echo $service_name | sed 's/libretime/airtime/' | sed 's/-analyzer/_analyzer/') + verbose "Old service $old_service already exists - migrating." + loudCmd "systemctl disable ${old_service}.service" + loudCmd "systemctl stop ${old_service}.service" + loudCmd "rm $alt_path" + old_style_unit_exists="t" + fi + # If no user defined, then just copy, otherwise filter + if [[ -z $user ]]; then + loudCmd "cp $source_path $target_path" + else + sed -e "s/User=.*/User=${user}/" \ + -e "s/Group=.*/Group=${user}/" $source_path > $target_path + fi + if [[ $old_style_unit_exists == "t" ]]; then + verbose "Maintaining compatibility with old systemd unit names" + # Alias to old Airtime names + loudCmd "ln -s $source_path $alt_path" + fi + chmod 0644 $target_path + chown root:root $target_path + verbose "Service ${service_name} installed into ${target_path}" + # Enable and start the service + loudCmd "systemctl enable ${service_name}.service" + verbose "Service ${service_name} enabled and started" + elif $has_upstart_init; then + case "$service_name" in + libretime-analyzer) + source_path="${python_source_path}/airtime_analyzer/install/upstart/${service_name}.conf" + target_path="/etc/init/${service_name}.conf" + user=${user:-$web_user} + ;; + libretime-celery) + source_path="${python_source_path}/airtime-celery/install/upstart/${service_name}.conf" + target_path="/etc/init/${service_name}.conf" + user="" + ;; + libretime-liquidsoap | libretime-playout) + source_path="${python_source_path}/pypo/install/upstart/${service_name}.conf.template" + target_path="/etc/init/${service_name}.conf" + user=${user:-$web_user} + ;; + esac + if [[ ! -e $source_path ]]; then + echo "$0:${FUNCNAME}(): ERROR: service \"$service_name\" with source path \"$source_path\" does not exist!" >&2 + exit 1 + fi + # Stop the service if it already exists + if [[ -e $target_path ]]; then + verbose "Service $service_name already exists - stopping." + loudCmd "service ${service_name} stop" + fi + # If no user defined, then just copy, otherwise filter + if [[ -z $user ]]; then + loudCmd "cp $source_path $target_path" + else + sed -e "s/WEB_USER/${user}/g" \ + -e "/^set[gu]id/{s/www-data/${user}/}" $source_path > $target_path + fi + chmod 0644 $target_path + chown root:root $target_path + verbose "Service ${service_name} installed into ${target_path}" + loudCmd "initctl check-config $service_name" + elif $has_systemv_init; then + case "$service_name" in + libretime-analyzer) + source_path="${python_source_path}/airtime_analyzer/install/sysvinit/${service_name}" + target_path="/etc/init.d/${service_name}" + user=${user:-$web_user} + ;; + libretime-celery) + source_path="${python_source_path}/airtime-celery/install/sysvinit/${service_name}" + target_path="/etc/init.d/${service_name}" + source_config_path="${python_source_path}/${service_name}/install/conf/${service_name}" + target_config_path="/etc/default/${service_name}" + user="" + ;; + libretime-liquidsoap | libretime-playout) + source_path="${python_source_path}/pypo/install/sysvinit/${service_name}" + target_path="/etc/init.d/${service_name}" + user=${user:-$web_user} + ;; + esac + if [[ ! -e $source_path ]]; then + echo "$0:${FUNCNAME}(): ERROR: service \"$service_name\" with source path \"$source_path\" does not exist!" >&2 + exit 1 + fi + # Stop the service if it already exists + if [[ -e $target_path ]]; then + verbose "Service $service_name already exists - stopping." + loudCmd "invoke-rc.d $service_name stop" + fi + # If no user defined, then just copy, otherwise filter + if [[ -z $user ]]; then + loudCmd "cp $source_path $target_path" + [[ -n $source_config_path ]] && + loudCmd "cp $source_config_path $target_config_path" + else + sed -e "/^USERID/{s/www-data/${user}/}" \ + -e "/^GROUPID/{s/www-data/${user}/}" $source_path > $target_path + fi + chmod 0644 $target_path + chown root:root $target_path + if [[ -n $target_config_path ]]; then + chmod 0644 $target_config_path + chown root:root $target_config_path + fi + verbose "Service ${service_name} installed into ${target_path}" + # Create symlinks for the appropriate runlevels + loudCmd "update-rc.d $service_name defaults" + verbose "Service ${service_name} enabled" + fi + return 0 } # Function to wrap different systemd vs. Upstart init commands depending @@ -342,235 +351,240 @@ function systemInitInstall() { # Where _command_ is one of: start, stop, status, reload, restart # enable, disable and either daemon-reload or reload-configuration. function systemInitCommand() { - local command=$1; shift - case "$command" in - start|stop|status|reload|restart) - if $has_systemd_init; then - loudCmd "systemctl $command $@" - elif $has_upstart_init; then - for svc_name in $@; do - loudCmd "service $svc_name $command" - done - elif $has_systemv_init; then - for svc_name in $@; do - loudCmd "invoke-rc.d $svc_name $command" - done - fi - ;; - enable|disable) # TODO: REMOVE - $has_systemd_init && - loudCmd "systemctl $command $1.service" - if $has_systemv_init; then - if [[ "$command" = "enable" ]] - then loudCmd "update-rc.d $1 defaults" - else loudCmd "update-rc.d $1 enable" - fi - fi - ;; - daemon-reload|reload-configuration) - $has_systemd_init && - loudCmd "systemctl daemon-reload" - $has_upstart_init && - loudCmd "initctl reload-configuration" - ;; - *) echo -e "$0:${FUNCNAME}(): ERROR: command \"$command\" is not supported!" >&2 - exit 1 - ;; - esac - return 0 + local command=$1 + shift + case "$command" in + start | stop | status | reload | restart) + if $has_systemd_init; then + loudCmd "systemctl $command $@" + elif $has_upstart_init; then + for svc_name in $@; do + loudCmd "service $svc_name $command" + done + elif $has_systemv_init; then + for svc_name in $@; do + loudCmd "invoke-rc.d $svc_name $command" + done + fi + ;; + enable | disable) # TODO: REMOVE + $has_systemd_init && + loudCmd "systemctl $command $1.service" + if $has_systemv_init; then + if [[ "$command" = "enable" ]]; then + loudCmd "update-rc.d $1 defaults" + else + loudCmd "update-rc.d $1 enable" + fi + fi + ;; + daemon-reload | reload-configuration) + $has_systemd_init && + loudCmd "systemctl daemon-reload" + $has_upstart_init && + loudCmd "initctl reload-configuration" + ;; + *) + echo -e "$0:${FUNCNAME}(): ERROR: command \"$command\" is not supported!" >&2 + exit 1 + ;; + esac + return 0 } while :; do - case "$1" in - --help) + case "$1" in + --help) + showhelp + ;; + --version) + showversion + ;; + --verbose) + _v=1 + ;; + --quiet | --silent) + _q=1 + ;; + --force) + _i=0 + ;; + --distribution) + if [ "$2" ]; then + dist=$2 + shift 2 + continue + else + echo 'ERROR: Must specify a non-empty "--distribution DISTRIBUTION" argument.' >&2 + exit 1 + fi + ;; + --distribution=?*) + dist=${1#*=} # Delete everything up to "=" and assign the remainder. + ;; + --distribution=) + echo 'ERROR: Must specify a non-empty "--distribution DISTRIBUTION" argument.' >&2 + exit 1 + ;; + --release) + if [ "$2" ]; then + code=$2 + shift 2 + continue + else + echo 'ERROR: Must specify a non-empty "--release RELEASE" argument.' >&2 + exit 1 + fi + ;; + --release=?*) + code=${1#*=} # Delete everything up to "=" and assign the remainder. + ;; + --release=) + echo 'ERROR: Must specify a non-empty "--release RELEASE" argument.' >&2 + exit 1 + ;; + --ignore-dependencies) + ignore_dependencies="t" + ;; + --apache) + apache="t" + ;; + --icecast) + icecast="t" + ;; + --postgres) + postgres="t" + ;; + --in-place) + in_place="t" + ;; + --web-user) + if [ "$2" ]; then + web_user=$2 + shift 2 + continue + else + echo 'ERROR: Must specify a non-empty "--web-user WEB_USER" argument.' >&2 + exit 1 + fi + ;; + --web-user=?*) + web_user=${1#*=} # Delete everything up to "=" and assign the remainder. + ;; + --web-user=) + echo 'ERROR: Must specify a non-empty "--web-user=WEB_USER" argument.' >&2 + exit 1 + ;; + --web-root) + if [ "$2" ]; then + web_root=$(readlink -f $2) + shift 2 + continue + else + echo 'ERROR: Must specify a non-empty "--web-root WEB_ROOT" argument.' >&2 + exit 1 + fi + ;; + --web-root=?*) + web_root=${1#*=} # Delete everything up to "=" and assign the remainder. + ;; + --web-root=) + echo 'ERROR: Must specify a non-empty "--web-root=WEB_ROOT" argument.' >&2 + exit 1 + ;; + --web-port) + echo 'ERROR: Please specify a port number.' >&2 + exit 1 + ;; + --web-port=) + echo 'ERROR: Please specify a port number.' >&2 + exit 1 + ;; + --web-port=?*) + web_port=${1#*=} + ;; + --selinux) + selinux="t" + ;; + --no-postgres) + skip_postgres=1 + ;; + --no-rabbitmq) + skip_rabbitmq=1 + ;; + --) + shift + break + ;; + -?*) + for ((i = 1; i < ${#1}; i++)); do + case "${1:$i:1}" in + h | \?) showhelp ;; - --version) + V) showversion ;; - --verbose) + v) _v=1 ;; - --quiet|--silent) + q) _q=1 ;; - --force) + f) _i=0 ;; - --distribution) - if [ "$2" ]; then - dist=$2 - shift 2 - continue - else - echo 'ERROR: Must specify a non-empty "--distribution DISTRIBUTION" argument.' >&2 - exit 1 - fi - ;; - --distribution=?*) - dist=${1#*=} # Delete everything up to "=" and assign the remainder. - ;; - --distribution=) - echo 'ERROR: Must specify a non-empty "--distribution DISTRIBUTION" argument.' >&2 - exit 1 - ;; - --release) - if [ "$2" ]; then - code=$2 - shift 2 - continue - else - echo 'ERROR: Must specify a non-empty "--release RELEASE" argument.' >&2 - exit 1 - fi - ;; - --release=?*) - code=${1#*=} # Delete everything up to "=" and assign the remainder. - ;; - --release=) - echo 'ERROR: Must specify a non-empty "--release RELEASE" argument.' >&2 - exit 1 - ;; - --ignore-dependencies) + d) ignore_dependencies="t" ;; - --apache) + a) apache="t" ;; - --icecast) + i) icecast="t" ;; - --postgres) + p) postgres="t" ;; - --in-place) + I) in_place="t" ;; - --web-user) + w) if [ "$2" ]; then - web_user=$2 - shift 2 - continue + web_user=$2 + continue else - echo 'ERROR: Must specify a non-empty "--web-user WEB_USER" argument.' >&2 - exit 1 + echo 'ERROR: Must specify a non-empty "-w WEB_USER" argument.' >&2 + exit 1 fi ;; - --web-user=?*) - web_user=${1#*=} # Delete everything up to "=" and assign the remainder. - ;; - --web-user=) - echo 'ERROR: Must specify a non-empty "--web-user=WEB_USER" argument.' >&2 - exit 1 - ;; - --web-root) + r) if [ "$2" ]; then - web_root=$(readlink -f $2) - shift 2 - continue + web_root=$(readlink -f $2) + continue else - echo 'ERROR: Must specify a non-empty "--web-root WEB_ROOT" argument.' >&2 - exit 1 + echo 'ERROR: Must specify a non-empty "-d WEB_ROOT" argument.' >&2 + exit 1 fi ;; - --web-root=?*) - web_root=${1#*=} # Delete everything up to "=" and assign the remainder. - ;; - --web-root=) - echo 'ERROR: Must specify a non-empty "--web-root=WEB_ROOT" argument.' >&2 + *) + echo "$0: error - unrecognized option '${1:$i:1}'" >&2 + echo "Try 'install --help' for more information." exit 1 ;; - --web-port) - echo 'ERROR: Please specify a port number.' >&2 - exit 1 - ;; - --web-port=) - echo 'ERROR: Please specify a port number.' >&2 - exit 1 - ;; - --web-port=?*) - web_port=${1#*=} - ;; - --selinux) - selinux="t" - ;; - --no-postgres) - skip_postgres=1 - ;; - --no-rabbitmq) - skip_rabbitmq=1 - ;; - --) - shift - break - ;; - -?*) - for ((i = 1; i < ${#1}; i++)); do - case "${1:$i:1}" in - h|\?) - showhelp - ;; - V) - showversion - ;; - v) - _v=1 - ;; - q) - _q=1 - ;; - f) - _i=0 - ;; - d) - ignore_dependencies="t" - ;; - a) - apache="t" - ;; - i) - icecast="t" - ;; - p) - postgres="t" - ;; - I) - in_place="t" - ;; - w) - if [ "$2" ]; then - web_user=$2 - continue - else - echo 'ERROR: Must specify a non-empty "-w WEB_USER" argument.' >&2 - exit 1 - fi - ;; - r) - if [ "$2" ]; then - web_root=$(readlink -f $2) - continue - else - echo 'ERROR: Must specify a non-empty "-d WEB_ROOT" argument.' >&2 - exit 1 - fi - ;; - *) - echo "$0: error - unrecognized option '${1:$i:1}'" >&2; - echo "Try 'install --help' for more information." - exit 1 - esac - done - ;; - *) - break - esac - shift + esac + done + ;; + *) + break + ;; + esac + shift done if [ -z web_root -a ! -d web_root ]; then - echo "$web_root doesn't exist!" - exit 1 + echo "$web_root doesn't exist!" + exit 1 fi echo -e "\n.____ ._____. ___________.__ " echo "| | |__\_ |_________ ___\__ ___/|__| _____ ____ " @@ -581,42 +595,49 @@ echo -e " \/ \/ \/ \/ \/\n" echo -e "Detecting distribution and release ..." if [ -e /etc/os-release ]; then - # Access $ID, $VERSION_ID and $PRETTY_NAME - source /etc/os-release - echo "Detected distribution id: $ID" - echo "Detected distribution release id: $VERSION_ID" - echo "Detected distribution description: $PRETTY_NAME" + # Access $ID, $VERSION_ID and $PRETTY_NAME + source /etc/os-release + echo "Detected distribution id: $ID" + echo "Detected distribution release id: $VERSION_ID" + echo "Detected distribution description: $PRETTY_NAME" else - ID=unknown - VERSION_ID=unknown - PRETTY_NAME="Unknown distribution and release" - echo "WARNING: /etc/os-release configuration not found. Unable to detect distribution." >&2 - if [ -z "$dist" -o -z "$code" ]; then - echo "ERROR: One or both of --distribution and --release options were not specified." >&2 - echo "This is an unsupported distribution and/or version!" >&2 - exit 1 - fi + ID=unknown + VERSION_ID=unknown + PRETTY_NAME="Unknown distribution and release" + echo "WARNING: /etc/os-release configuration not found. Unable to detect distribution." >&2 + if [ -z "$dist" -o -z "$code" ]; then + echo "ERROR: One or both of --distribution and --release options were not specified." >&2 + echo "This is an unsupported distribution and/or version!" >&2 + exit 1 + fi fi # Validate --distribution parameter has a sane value for this OS. if [ -n "$dist" ]; then - dist=${dist,,} - verbose "Checking --distribution \"$dist\" to ensure it has a sane value." - # If $ID detected above does not match parameter, then do some checking - if [ "$dist" != "$ID" ]; then - verbose "Detected distribution \"$ID\" does not match specified one of \"$dist\". Checking ..." - case "$dist" in - centos|rhel) pkg_installer=/usr/bin/yum; verbose "Detected yum package installer" ;; - debian|ubuntu) pkg_installer=/usr/bin/apt-get; verbose "Detected apt-get package installer" ;; - *) echo "ERROR: the value \"$dist\" specified for --distribution is unsupported." >&2 - exit 1 - ;; - esac - if [ ! -x "$pkg_installer" ]; then - echo "ERROR: The value \"$dist\" specified for --distribution does not appear compatible!" >&2 - exit 1 - fi + dist=${dist,,} + verbose "Checking --distribution \"$dist\" to ensure it has a sane value." + # If $ID detected above does not match parameter, then do some checking + if [ "$dist" != "$ID" ]; then + verbose "Detected distribution \"$ID\" does not match specified one of \"$dist\". Checking ..." + case "$dist" in + centos | rhel) + pkg_installer=/usr/bin/yum + verbose "Detected yum package installer" + ;; + debian | ubuntu) + pkg_installer=/usr/bin/apt-get + verbose "Detected apt-get package installer" + ;; + *) + echo "ERROR: the value \"$dist\" specified for --distribution is unsupported." >&2 + exit 1 + ;; + esac + if [ ! -x "$pkg_installer" ]; then + echo "ERROR: The value \"$dist\" specified for --distribution does not appear compatible!" >&2 + exit 1 fi + fi fi # Validate the distribution and release is a supported one; set boolean flags. @@ -633,55 +654,55 @@ code="${code:-$VERSION_ID}" code="${code,,}" verbose "Validating dist-code: ${dist}-${code}" case "${dist}-${code}" in - ubuntu-18.04) - code="bionic" - is_ubuntu_dist=true - is_ubuntu_bionic=true - ;; - ubuntu-16.04|ubuntu-xenial|ubuntu-xenial_docker_minimal) - echo -e "ERROR: Ubuntu Xenial is archived and does not receive any security or other updates since 2021-04-01." >&2 - echo -e "The LibreTime installer dropped support for installing LibreTime on Xenial in 3.0.0-alpha.10." >&2 - exit 1 - ;; - debian-9|debian-stretch) - echo -e "ERROR: Debian Stretch is archived and does not receive any security or other updates since 2020-06-06." >&2 - echo -e "The LibreTime installer dropped support for installing LibreTime on Stretch in 3.0.0-alpha.10." >&2 - exit 1 - ;; - debian-10|debian-buster) - code="buster" - is_debian_dist=true - is_debian_buster=true - ;; - #Fix for Raspbian 9 (stretch) - raspbian-9|9) - echo -e "ERROR: Raspbian Stretch is archived and does not receive any security or other updates since 2020-06-06." >&2 - echo -e "The LibreTime installer dropped support for installing LibreTime on Stretch in 3.0.0-alpha.10." >&2 - exit 1 - ;; - #End of fix - #Fix for Raspbian 10 (buster) - raspbian-10|10) - code="buster" - dist="debian" - is_debian_dist=true - is_debian_buster=true - ;; - #End of fix + ubuntu-18.04) + code="bionic" + is_ubuntu_dist=true + is_ubuntu_bionic=true + ;; + ubuntu-16.04 | ubuntu-xenial | ubuntu-xenial_docker_minimal) + echo -e "ERROR: Ubuntu Xenial is archived and does not receive any security or other updates since 2021-04-01." >&2 + echo -e "The LibreTime installer dropped support for installing LibreTime on Xenial in 3.0.0-alpha.10." >&2 + exit 1 + ;; + debian-9 | debian-stretch) + echo -e "ERROR: Debian Stretch is archived and does not receive any security or other updates since 2020-06-06." >&2 + echo -e "The LibreTime installer dropped support for installing LibreTime on Stretch in 3.0.0-alpha.10." >&2 + exit 1 + ;; + debian-10 | debian-buster) + code="buster" + is_debian_dist=true + is_debian_buster=true + ;; + #Fix for Raspbian 9 (stretch) + raspbian-9 | 9) + echo -e "ERROR: Raspbian Stretch is archived and does not receive any security or other updates since 2020-06-06." >&2 + echo -e "The LibreTime installer dropped support for installing LibreTime on Stretch in 3.0.0-alpha.10." >&2 + exit 1 + ;; + #End of fix + #Fix for Raspbian 10 (buster) + raspbian-10 | 10) + code="buster" + dist="debian" + is_debian_dist=true + is_debian_buster=true + ;; + #End of fix - debian-8|debian-jessie) - echo -e "ERROR: Debian Jessie is archived and does not receive any security or other updates since 2018-05-17." >&2 - echo -e "The LibreTime installer dropped support for installing LibreTime on Jessie in 3.0.0-alpha.8." >&2 - exit 1 - ;; - centos-8) - is_centos_dist=true - is_centos_8=true - ;; - *) - echo -e "ERROR: Distribution \"$PRETTY_NAME\" is not supported with \"${dist}-${code}\"!" >&2 - exit 1 - ;; + debian-8 | debian-jessie) + echo -e "ERROR: Debian Jessie is archived and does not receive any security or other updates since 2018-05-17." >&2 + echo -e "The LibreTime installer dropped support for installing LibreTime on Jessie in 3.0.0-alpha.8." >&2 + exit 1 + ;; + centos-8) + is_centos_dist=true + is_centos_8=true + ;; + *) + echo -e "ERROR: Distribution \"$PRETTY_NAME\" is not supported with \"${dist}-${code}\"!" >&2 + exit 1 + ;; esac verbose "Using distribution id \"$dist\", release code \"$code\"" @@ -689,256 +710,256 @@ verbose "Using distribution id \"$dist\", release code \"$code\"" systemInitDetect if $is_centos_dist; then - python_bin="python3.8" - apache_bin="httpd" - apache_service="httpd" - web_user="${web_user:-apache}" + python_bin="python3.8" + apache_bin="httpd" + apache_service="httpd" + web_user="${web_user:-apache}" else - python_bin="python3" - apache_bin="apache2ctl" - apache_service="apache2" - web_user="${web_user:-www-data}" + python_bin="python3" + apache_bin="apache2ctl" + apache_service="apache2" + web_user="${web_user:-www-data}" fi if [ "$ignore_dependencies" = "f" ]; then - set +e - loud "\n-----------------------------------------------------" - loud " * Installing External Dependencies * " - loud "-----------------------------------------------------" + set +e + loud "\n-----------------------------------------------------" + loud " * Installing External Dependencies * " + loud "-----------------------------------------------------" - if $is_ubuntu_dist; then - loudCmd "add-apt-repository -y ppa:libretime/libretime" - fi + if $is_ubuntu_dist; then + loudCmd "add-apt-repository -y ppa:libretime/libretime" + fi - if [ -x /usr/bin/apt-get ]; then - verbose "\n * Reading requirements-${dist}-${code}.apt..." - loudCmd "apt-get -q update" - package_list_file="${SCRIPT_DIR}/installer/apt/requirements-${dist}-${code}.apt" + if [ -x /usr/bin/apt-get ]; then + verbose "\n * Reading requirements-${dist}-${code}.apt..." + loudCmd "apt-get -q update" + package_list_file="${SCRIPT_DIR}/installer/apt/requirements-${dist}-${code}.apt" - if [ ! -f "$package_list_file" ]; then - echo "ERROR: package file does not exist: $package_list_file" >&2 - exit 1 - fi - - package_list="$(grep -vE '^\s*#' "$package_list_file" | tr '\n' ' ')" - loudCmd "DEBIAN_FRONTEND=noninteractive apt-get -y install $package_list" - [[ "$in_place" == "t" ]] && loudCmd "DEBIAN_FRONTEND=noninteractive apt-get -y install git" - else - echo "WARNING: installing dependencies is not supported for this distribution" >&2 + if [ ! -f "$package_list_file" ]; then + echo "ERROR: package file does not exist: $package_list_file" >&2 + exit 1 fi - set -e + + package_list="$(grep -vE '^\s*#' "$package_list_file" | tr '\n' ' ')" + loudCmd "DEBIAN_FRONTEND=noninteractive apt-get -y install $package_list" + [[ "$in_place" == "t" ]] && loudCmd "DEBIAN_FRONTEND=noninteractive apt-get -y install git" + else + echo "WARNING: installing dependencies is not supported for this distribution" >&2 + fi + set -e else - checkCommandExists "${apache_bin}" - checkCommandExists "rabbitmqctl" - checkCommandExists "psql" - if [ "$in_place" = "t" ]; then - checkCommandExists "git" - fi + checkCommandExists "${apache_bin}" + checkCommandExists "rabbitmqctl" + checkCommandExists "psql" + if [ "$in_place" = "t" ]; then + checkCommandExists "git" + fi fi # Check if composer exists and install if it doesn't set +e -eval hash "composer" 2>/dev/null +eval hash "composer" 2> /dev/null commandFound=$? set -e if [[ ! ${commandFound} -eq 0 ]]; then - curl -sS https://getcomposer.org/installer > get-composer.php - php ./get-composer.php --install-dir=/usr/local/bin --filename=composer - rm get-composer.php - PATH="${PATH}:/usr/local/bin" + curl -sS https://getcomposer.org/installer > get-composer.php + php ./get-composer.php --install-dir=/usr/local/bin --filename=composer + rm get-composer.php + PATH="${PATH}:/usr/local/bin" fi # Run composer (install PHP dependencies) and create a VERSION file loudCmd "./build.sh" if [ -f /etc/airtime/airtime.conf ]; then - # TODO use VERSION or some other way to check for updates and handle - # media-monitor case on it's own - OLD_CONF=$(grep -F "[media-monitor]" /etc/airtime/airtime.conf || true) + # TODO use VERSION or some other way to check for updates and handle + # media-monitor case on it's own + OLD_CONF=$(grep -F "[media-monitor]" /etc/airtime/airtime.conf || true) - if [ -n "${OLD_CONF}" ]; then - upgrade="t" + if [ -n "${OLD_CONF}" ]; then + upgrade="t" - set +e - verbose "Stopping airtime services..." - systemInitCommand stop airtime_analyzer airtime-celery airtime-playout airtime-liquidsoap airtime-media-monitor - verbose "...Done" + set +e + verbose "Stopping airtime services..." + systemInitCommand stop airtime_analyzer airtime-celery airtime-playout airtime-liquidsoap airtime-media-monitor + verbose "...Done" - verbose "Disabling obsolete services..." - systemInitCommand disable airtime-media-monitor - verbose "...Done" + verbose "Disabling obsolete services..." + systemInitCommand disable airtime-media-monitor + verbose "...Done" - echo "Looks like you have an old version of Airtime. Your current /etc/airtime/airtime.conf \ + echo "Looks like you have an old version of Airtime. Your current /etc/airtime/airtime.conf \ will be moved to /etc/airtime/airtime.conf.tmp" - # If we don't remove the existing python files in /usr/lib and the - # /etc/init.d startup scripts, services won't work properly - if [ -d /usr/lib/airtime/ ]; then - rm -rf /usr/lib/airtime/ - fi - - rm -f /etc/init.d/airtime* - rm -f /etc/init/airtime* - rm -f /etc/default/airtime-celery - - if [ "$apache" = "t" ]; then - # If the user selects an "in-place" install or passes in a web root, - # we need to replace the old apache airtime.conf - rm -f /etc/apache2/sites-available/airtime.conf /etc/apache2/sites-enabled/airtime.conf - fi - - if [ -d /usr/share/airtime -a web_root = /usr/share/airtime ]; then - rm -rf /usr/share/airtime - fi - - mv /etc/airtime/airtime.conf /etc/airtime/airtime.conf.tmp - set -e + # If we don't remove the existing python files in /usr/lib and the + # /etc/init.d startup scripts, services won't work properly + if [ -d /usr/lib/airtime/ ]; then + rm -rf /usr/lib/airtime/ fi + + rm -f /etc/init.d/airtime* + rm -f /etc/init/airtime* + rm -f /etc/default/airtime-celery + + if [ "$apache" = "t" ]; then + # If the user selects an "in-place" install or passes in a web root, + # we need to replace the old apache airtime.conf + rm -f /etc/apache2/sites-available/airtime.conf /etc/apache2/sites-enabled/airtime.conf + fi + + if [ -d /usr/share/airtime -a web_root = /usr/share/airtime ]; then + rm -rf /usr/share/airtime + fi + + mv /etc/airtime/airtime.conf /etc/airtime/airtime.conf.tmp + set -e + fi fi API2_APACHE_CONF=$(grep -F "ProxyPass" /etc/apache2/sites-available/airtime.conf || true) if [ -z "${API2_APACHE_CONF}" -a "$apache" = "t" ]; then - # Remove Apache configuration so that the ProxyPass configuration for API 2.0 - # is installed - rm -f /etc/apache2/sites-available/airtime.conf /etc/apache2/sites-enabled/airtime.conf + # Remove Apache configuration so that the ProxyPass configuration for API 2.0 + # is installed + rm -f /etc/apache2/sites-available/airtime.conf /etc/apache2/sites-enabled/airtime.conf fi if [ "$apache" = "f" -a ${_i} -eq 1 ]; then - echo -e "Install default Airtime apache configuration? (Y/n): \c" - read IN - IN=${IN:-$default_value} - if [ "$IN" = "y" -o "$IN" = "Y" ]; then - apache="t" - fi + echo -e "Install default Airtime apache configuration? (Y/n): \c" + read IN + IN=${IN:-$default_value} + if [ "$IN" = "y" -o "$IN" = "Y" ]; then + apache="t" + fi fi if [ "$in_place" = "t" ]; then - verbose "\n * Setting current Airtime directory as web root..." - web_root=${AIRTIMEROOT}/airtime_mvc/public + verbose "\n * Setting current Airtime directory as web root..." + web_root=${AIRTIMEROOT}/airtime_mvc/public elif [ -n "$web_root" ]; then - verbose "\n * Creating Apache web root directory..." - cp -R ${AIRTIMEROOT}/airtime_mvc ${web_root} - cp -R ${AIRTIMEROOT}/vendor ${web_root} - cp ${AIRTIMEROOT}/VERSION ${web_root} - web_root=${web_root}/airtime_mvc/public/ + verbose "\n * Creating Apache web root directory..." + cp -R ${AIRTIMEROOT}/airtime_mvc ${web_root} + cp -R ${AIRTIMEROOT}/vendor ${web_root} + cp ${AIRTIMEROOT}/VERSION ${web_root} + web_root=${web_root}/airtime_mvc/public/ else - verbose "\n * Creating default Apache web root directory /usr/share/airtime/php..." - web_root="/usr/share/airtime/php" - mkdir -p ${web_root} - cp -R ${AIRTIMEROOT}/airtime_mvc ${web_root} - cp -R ${AIRTIMEROOT}/vendor ${web_root} - cp ${AIRTIMEROOT}/VERSION ${web_root} - web_root=${web_root}/airtime_mvc/public/ + verbose "\n * Creating default Apache web root directory /usr/share/airtime/php..." + web_root="/usr/share/airtime/php" + mkdir -p ${web_root} + cp -R ${AIRTIMEROOT}/airtime_mvc ${web_root} + cp -R ${AIRTIMEROOT}/vendor ${web_root} + cp ${AIRTIMEROOT}/VERSION ${web_root} + web_root=${web_root}/airtime_mvc/public/ fi verbose "...Done" if [ "$apache" = "t" ]; then - loud "\n-----------------------------------------------------" - loud " * Configuring Apache * " - loud "-----------------------------------------------------" - # Detect Apache root folder, e.g. /etc/apache2 or /etc/httpd - eval $($apache_bin -V |awk '/HTTPD_ROOT|SERVER_CONFIG_FILE/ { print $2 }') - apache_conf="${HTTPD_ROOT}/${SERVER_CONFIG_FILE}" - verbose "Detected Apache root folder is: ${HTTPD_ROOT}" - if [[ ! -e $apache_conf ]]; then - echo -e "ERROR: Apache binary \"$apache_bin\" points to a non-existent file \"$apache_conf\"" - exit 1 - fi - verbose "Detected Apache primary .conf file is: ${apache_conf}" - if [[ -d ${HTTPD_ROOT}/sites-available ]]; then # debian & ubuntu - apache_sitedir="${HTTPD_ROOT}/sites-available/" - elif [[ -d ${HTTPD_ROOT}/conf.d ]]; then # centos - apache_sitedir="${HTTPD_ROOT}/conf.d/" - else - echo -e "ERROR: unknown location of Apache sites-available or virtual host directory!" >&2 - exit 1 - fi - verbose "Detected Apache sites configuration folder: ${apache_sitedir}" + loud "\n-----------------------------------------------------" + loud " * Configuring Apache * " + loud "-----------------------------------------------------" + # Detect Apache root folder, e.g. /etc/apache2 or /etc/httpd + eval $($apache_bin -V | awk '/HTTPD_ROOT|SERVER_CONFIG_FILE/ { print $2 }') + apache_conf="${HTTPD_ROOT}/${SERVER_CONFIG_FILE}" + verbose "Detected Apache root folder is: ${HTTPD_ROOT}" + if [[ ! -e $apache_conf ]]; then + echo -e "ERROR: Apache binary \"$apache_bin\" points to a non-existent file \"$apache_conf\"" + exit 1 + fi + verbose "Detected Apache primary .conf file is: ${apache_conf}" + if [[ -d ${HTTPD_ROOT}/sites-available ]]; then # debian & ubuntu + apache_sitedir="${HTTPD_ROOT}/sites-available/" + elif [[ -d ${HTTPD_ROOT}/conf.d ]]; then # centos + apache_sitedir="${HTTPD_ROOT}/conf.d/" + else + echo -e "ERROR: unknown location of Apache sites-available or virtual host directory!" >&2 + exit 1 + fi + verbose "Detected Apache sites configuration folder: ${apache_sitedir}" - set +e - # Parse: Server version: Apache/2.2.22 (Ubuntu) -> 2 - apache_major_version=$($apache_bin -v |awk -F'[ /.]+' 'NR == 1 { print $4 }') - set -e + set +e + # Parse: Server version: Apache/2.2.22 (Ubuntu) -> 2 + apache_major_version=$($apache_bin -v | awk -F'[ /.]+' 'NR == 1 { print $4 }') + set -e - if [[ "$apache_major_version" -ge 2 ]]; then - airtimeconfigfile="airtime.conf" - oldconfigfile="airtime-vhost.conf" - else - airtimeconfigfile="airtime" - oldconfigfile="airtime-vhost" + if [[ "$apache_major_version" -ge 2 ]]; then + airtimeconfigfile="airtime.conf" + oldconfigfile="airtime-vhost.conf" + else + airtimeconfigfile="airtime" + oldconfigfile="airtime-vhost" + fi + + # If we're upgrading (installing over an existing Airtime install) and we've been told to + # install apache, we should overwrite any existing configuration. If we don't do this, doing + # an in-place installation over an old Airtime install (which installs to /usr/share by default) + # will fail + if [ "$upgrade" = "t" -o ! -f ${apache_sitedir}${airtimeconfigfile} ]; then + verbose "\n * Creating Apache config for Airtime..." + listen_port="" + if [ "$web_port" != "80" ]; then + listen_port="Listen ${web_port}" fi - # If we're upgrading (installing over an existing Airtime install) and we've been told to - # install apache, we should overwrite any existing configuration. If we don't do this, doing - # an in-place installation over an old Airtime install (which installs to /usr/share by default) - # will fail - if [ "$upgrade" = "t" -o ! -f ${apache_sitedir}${airtimeconfigfile} ]; then - verbose "\n * Creating Apache config for Airtime..." - listen_port="" - if [ "$web_port" != "80" ]; then - listen_port="Listen ${web_port}" - fi - - apache_template_file=${SCRIPT_DIR}/installer/apache/airtime-vhost-2.4 - if [[ "$apache_major_version" -eq 1 ]]; then - # fall back to apache 1 config - apache_template_file=${SCRIPT_DIR}/installer/apache/airtime-vhost - fi - sed \ - -e "s@WEB_PORT_LISTEN@${listen_port}@g" \ - -e "s@WEB_PORT@${web_port}@g" \ - -e "s@WEB_ROOT@${web_root}@g" \ - ${apache_template_file} > ${apache_sitedir}${airtimeconfigfile} - - # The a2ensite/a2dissite utilities are not available on CentOS - if [[ -x /usr/sbin/a2ensite ]]; then - loudCmd "a2dissite 000-default" - # If Airtime was previously installed with apt, the vhost file name is different, - # so we need to specifically disable it. - if [ -f "/etc/apache2/sites-available/${oldconfigfile}" ]; then - loudCmd "a2dissite airtime-vhost" - fi - loudCmd "a2ensite airtime" - fi - else - verbose "\nApache config for Airtime already exists, skipping" + apache_template_file=${SCRIPT_DIR}/installer/apache/airtime-vhost-2.4 + if [[ "$apache_major_version" -eq 1 ]]; then + # fall back to apache 1 config + apache_template_file=${SCRIPT_DIR}/installer/apache/airtime-vhost fi + sed \ + -e "s@WEB_PORT_LISTEN@${listen_port}@g" \ + -e "s@WEB_PORT@${web_port}@g" \ + -e "s@WEB_ROOT@${web_root}@g" \ + ${apache_template_file} > ${apache_sitedir}${airtimeconfigfile} + + # The a2ensite/a2dissite utilities are not available on CentOS + if [[ -x /usr/sbin/a2ensite ]]; then + loudCmd "a2dissite 000-default" + # If Airtime was previously installed with apt, the vhost file name is different, + # so we need to specifically disable it. + if [ -f "/etc/apache2/sites-available/${oldconfigfile}" ]; then + loudCmd "a2dissite airtime-vhost" + fi + loudCmd "a2ensite airtime" + fi + else + verbose "\nApache config for Airtime already exists, skipping" + fi fi if [ "$icecast" = "f" -a ${_i} -eq 1 ]; then - echo -e "Install default Airtime Icecast configuration? (Y/n): \c" - read IN - IN=${IN:-$default_value} - if [ "$IN" = "y" -o "$IN" = "Y" ]; then - icecast="t" - fi + echo -e "Install default Airtime Icecast configuration? (Y/n): \c" + read IN + IN=${IN:-$default_value} + if [ "$IN" = "y" -o "$IN" = "Y" ]; then + icecast="t" + fi fi if [ "$icecast" = "t" ]; then - loud "\n-----------------------------------------------------" - loud " * Configuring Icecast * " - loud "-----------------------------------------------------" + loud "\n-----------------------------------------------------" + loud " * Configuring Icecast * " + loud "-----------------------------------------------------" - verbose "\n * Enabling Icecast 2..." - icecast_unit_name="icecast2" - if [ "$dist" != "centos" ]; then - sed -i 's/ENABLE=false/ENABLE=true/g' /etc/default/icecast2 - icecast_config="/etc/icecast2/icecast.xml" - else - icecast_unit_name="icecast" - icecast_config="/etc/icecast.xml" - fi - systemInitCommand enable ${icecast_unit_name} - # only update icecast password if - if [ ! -e "/etc/airtime/airtime.conf" ] && [ ! -e "/etc/airtime/airtime.conf.tmp" ]; then - icecast_pass=$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-12};) - echo $icecast_pass > /tmp/icecast_pass - loud "\n New install detected setting icecast password to random value." - xmlstarlet ed --inplace -u /icecast/authentication/source-password -v $icecast_pass $icecast_config - xmlstarlet ed --inplace -u /icecast/authentication/relay-password -v $icecast_pass $icecast_config - xmlstarlet ed --inplace -u /icecast/authentication/admin-password -v $icecast_pass $icecast_config - fi - # restart in case icecast was already started (like is the case on debian) - systemInitCommand restart ${icecast_unit_name} - verbose "...Done" + verbose "\n * Enabling Icecast 2..." + icecast_unit_name="icecast2" + if [ "$dist" != "centos" ]; then + sed -i 's/ENABLE=false/ENABLE=true/g' /etc/default/icecast2 + icecast_config="/etc/icecast2/icecast.xml" + else + icecast_unit_name="icecast" + icecast_config="/etc/icecast.xml" + fi + systemInitCommand enable ${icecast_unit_name} + # only update icecast password if + if [ ! -e "/etc/airtime/airtime.conf" ] && [ ! -e "/etc/airtime/airtime.conf.tmp" ]; then + icecast_pass=$(tr -dc _A-Z-a-z-0-9 < /dev/urandom | head -c${1:-12}) + echo $icecast_pass > /tmp/icecast_pass + loud "\n New install detected setting icecast password to random value." + xmlstarlet ed --inplace -u /icecast/authentication/source-password -v $icecast_pass $icecast_config + xmlstarlet ed --inplace -u /icecast/authentication/relay-password -v $icecast_pass $icecast_config + xmlstarlet ed --inplace -u /icecast/authentication/admin-password -v $icecast_pass $icecast_config + fi + # restart in case icecast was already started (like is the case on debian) + systemInitCommand restart ${icecast_unit_name} + verbose "...Done" fi loud "\n-----------------------------------------------------" @@ -962,16 +983,16 @@ chown -R ${web_user}:${web_user} /run/airtime verbose "...Done" if [ ! -d /var/log/airtime ]; then - loud "\n-----------------------------------------------------" - loud " * Installing Log Files * " - loud "-----------------------------------------------------" + loud "\n-----------------------------------------------------" + loud " * Installing Log Files * " + loud "-----------------------------------------------------" - verbose "\n * Creating /var/log/airtime" - loudCmd "mkdir -p /var/log/airtime" + verbose "\n * Creating /var/log/airtime" + loudCmd "mkdir -p /var/log/airtime" - verbose "\n * Copying logrotate files..." - loudCmd "cp ${AIRTIMEROOT}/airtime_mvc/build/airtime-php.logrotate /etc/logrotate.d/airtime-php" - loudCmd "cp ${AIRTIMEROOT}/python_apps/pypo/liquidsoap/airtime-liquidsoap.logrotate /etc/logrotate.d/airtime-liquidsoap" + verbose "\n * Copying logrotate files..." + loudCmd "cp ${AIRTIMEROOT}/airtime_mvc/build/airtime-php.logrotate /etc/logrotate.d/airtime-php" + loudCmd "cp ${AIRTIMEROOT}/python_apps/pypo/liquidsoap/airtime-liquidsoap.logrotate /etc/logrotate.d/airtime-liquidsoap" fi verbose "\n * Installing API client..." @@ -990,9 +1011,9 @@ verbose "\n * Installing airtime-celery..." loudCmd "$python_bin ${AIRTIMEROOT}/python_apps/airtime-celery/setup.py install --no-init-script" # Create the Celery user if $is_centos_dist; then - loudCmd "id celery 2>/dev/null || adduser --no-create-home -c 'LibreTime Celery' -r celery || true" + loudCmd "id celery 2>/dev/null || adduser --no-create-home -c 'LibreTime Celery' -r celery || true" else - loudCmd "id celery 2>/dev/null || adduser --no-create-home --gecos 'LibreTime Celery' --disabled-login --firstuid 1 --lastuid 999 celery" + loudCmd "id celery 2>/dev/null || adduser --no-create-home --gecos 'LibreTime Celery' --disabled-login --firstuid 1 --lastuid 999 celery" fi # Add celery to the www-data group loudCmd "usermod -G ${web_user} -a celery" @@ -1012,8 +1033,8 @@ loudCmd "python3 ${AIRTIMEROOT}/api/setup.py install --install-scripts=/usr/bin" systemInitInstall libretime-api $web_user mkdir -p /etc/airtime sed -e "s@WEB_USER@${web_user}@g" \ - -e "s@WEB_ROOT@${web_root}@g" \ - ${AIRTIMEROOT}/installer/uwsgi/libretime-api.ini > /etc/airtime/libretime-api.ini + -e "s@WEB_ROOT@${web_root}@g" \ + ${AIRTIMEROOT}/installer/uwsgi/libretime-api.ini > /etc/airtime/libretime-api.ini loudCmd "libretime-api collectstatic --clear --noinput" verbose "...Done" @@ -1031,117 +1052,117 @@ loud " * Configuring PHP in Apache * " loud "-----------------------------------------------------" # Test common locations for php conf directory php_conf_dirs=( - "/etc/php/7.3/apache2/conf.d" # Debian Buster - "/etc/php/7.2/apache2/conf.d" # Ubuntu Bionic - "/etc/php/7.0/apache2/conf.d" # Ubuntu Xenial - "/etc/php5/apache2/conf.d" # Debian Stretch, Debian Jessie, Ubuntu Trusty - "/etc/php.d" # CentOS 7 + "/etc/php/7.3/apache2/conf.d" # Debian Buster + "/etc/php/7.2/apache2/conf.d" # Ubuntu Bionic + "/etc/php/7.0/apache2/conf.d" # Ubuntu Xenial + "/etc/php5/apache2/conf.d" # Debian Stretch, Debian Jessie, Ubuntu Trusty + "/etc/php.d" # CentOS 7 ) for php_conf in ${php_conf_dirs[@]}; do - [[ -d $php_conf ]] && break + [[ -d $php_conf ]] && break done if [[ -d $php_conf ]]; then - libretime_phpini="${php_conf}/airtime.ini" + libretime_phpini="${php_conf}/airtime.ini" else - echo -e "ERROR: PHP Apache configuration folder does not exist or is in an unknown location!" >&2 - exit 1 + echo -e "ERROR: PHP Apache configuration folder does not exist or is in an unknown location!" >&2 + exit 1 fi verbose "Detected php conf directory at: $php_conf" if [ ! -f "${libretime_phpini}" ]; then - verbose "\n * Creating LibreTime PHP config for Apache..." - cp ${SCRIPT_DIR}/installer/php/airtime.ini ${libretime_phpini} + verbose "\n * Creating LibreTime PHP config for Apache..." + cp ${SCRIPT_DIR}/installer/php/airtime.ini ${libretime_phpini} else - verbose "\nAirtime PHP config for Apache already exists, skipping" + verbose "\nAirtime PHP config for Apache already exists, skipping" fi # Enable Apache modules if $is_debian_buster; then - loudCmd "a2enmod rewrite php7.3 proxy proxy_http" + loudCmd "a2enmod rewrite php7.3 proxy proxy_http" elif $is_ubuntu_bionic; then - loudCmd "a2enmod rewrite php7.2 proxy proxy_http" + loudCmd "a2enmod rewrite php7.2 proxy proxy_http" elif $is_centos_dist; then - verbose "TODO: enable Apache modules mod_rewrite, mod_php, mod_proxy and mod_proxy_http manually" + verbose "TODO: enable Apache modules mod_rewrite, mod_php, mod_proxy and mod_proxy_http manually" else - loudCmd "a2enmod rewrite php5 proxy proxy_http" + loudCmd "a2enmod rewrite php5 proxy proxy_http" fi if [ $skip_postgres -eq 0 ]; then - loud "\n-----------------------------------------------------" - loud " * Configuring PostgreSQL * " - loud "-----------------------------------------------------" + loud "\n-----------------------------------------------------" + loud " * Configuring PostgreSQL * " + loud "-----------------------------------------------------" - # Ensure postgres is running - It isn't after you install the postgres package on Ubuntu 15.04 - systemInitCommand start postgresql + # Ensure postgres is running - It isn't after you install the postgres package on Ubuntu 15.04 + systemInitCommand start postgresql - setupAirtimePostgresUser() { - # here-doc to execute this block as postgres user - su postgres <<'EOF' - set +e - count=$(psql -d postgres -tAc "SELECT count(*) FROM pg_roles WHERE rolname='airtime';") - if [[ $count -eq 0 ]]; then - psql -d postgres -tAc "CREATE USER airtime WITH ENCRYPTED PASSWORD 'airtime'; ALTER USER airtime CREATEDB;" - [[ $? -eq 0 ]] && - echo "Created airtime user in PostgreSQL" || - echo "$0:${FUNCNAME}(): ERROR: Can't create airtime user in PostgreSQL!" - else - echo "airtime user already exists in PostgreSQL" - fi - set -e + setupAirtimePostgresUser() { + # here-doc to execute this block as postgres user + su postgres << 'EOF' +set +e +count=$(psql -d postgres -tAc "SELECT count(*) FROM pg_roles WHERE rolname='airtime';") +if [[ $count -eq 0 ]]; then +psql -d postgres -tAc "CREATE USER airtime WITH ENCRYPTED PASSWORD 'airtime'; ALTER USER airtime CREATEDB;" +[[ $? -eq 0 ]] && +echo "Created airtime user in PostgreSQL" || +echo "$0:${FUNCNAME}(): ERROR: Can't create airtime user in PostgreSQL!" +else +echo "airtime user already exists in PostgreSQL" +fi +set -e # don't indent this! EOF - } + } - if [ "$postgres" = "t" ]; then - setupAirtimePostgresUser - elif [ ${_i} -eq 1 ]; then - echo -e "Create default airtime postgres user? (Y/n): \c" - read IN - IN=${IN:-$default_value} - if [ "$IN" = "y" -o "$IN" = "Y" ]; then - setupAirtimePostgresUser - fi + if [ "$postgres" = "t" ]; then + setupAirtimePostgresUser + elif [ ${_i} -eq 1 ]; then + echo -e "Create default airtime postgres user? (Y/n): \c" + read IN + IN=${IN:-$default_value} + if [ "$IN" = "y" -o "$IN" = "Y" ]; then + setupAirtimePostgresUser fi + fi fi if [ $skip_rabbitmq -eq 0 ]; then - loud "\n-----------------------------------------------------" - loud " * Configuring RabbitMQ * " - loud "-----------------------------------------------------" + loud "\n-----------------------------------------------------" + loud " * Configuring RabbitMQ * " + loud "-----------------------------------------------------" - RABBITMQ_VHOST=/airtime - RABBITMQ_USER=airtime - RABBITMQ_PASSWORD=airtime - EXCHANGES="airtime-pypo|pypo-fetch|airtime-analyzer|media-monitor" + RABBITMQ_VHOST=/airtime + RABBITMQ_USER=airtime + RABBITMQ_PASSWORD=airtime + EXCHANGES="airtime-pypo|pypo-fetch|airtime-analyzer|media-monitor" - # Ignore errors in this check to avoid dying when vhost isn't found - set +e - rabbitmqctl list_vhosts | grep -w "^${RABBITMQ_VHOST}$" > /dev/null - RESULT="$?" - set -e + # Ignore errors in this check to avoid dying when vhost isn't found + set +e + rabbitmqctl list_vhosts | grep -w "^${RABBITMQ_VHOST}$" > /dev/null + RESULT="$?" + set -e - # Only run these if the vhost doesn't exist - if [ "$RESULT" != "0" ]; then - verbose "\n * Creating RabbitMQ user ${RABBITMQ_USER}..." + # Only run these if the vhost doesn't exist + if [ "$RESULT" != "0" ]; then + verbose "\n * Creating RabbitMQ user ${RABBITMQ_USER}..." - rabbitmqctl add_vhost ${RABBITMQ_VHOST} - rabbitmqctl add_user ${RABBITMQ_USER} ${RABBITMQ_PASSWORD} - else - verbose "\nRabbitMQ user already exists, skipping creation" - fi + rabbitmqctl add_vhost ${RABBITMQ_VHOST} + rabbitmqctl add_user ${RABBITMQ_USER} ${RABBITMQ_PASSWORD} + else + verbose "\nRabbitMQ user already exists, skipping creation" + fi - verbose "\n * Setting RabbitMQ user permissions..." - #loudCmd "rabbitmqctl set_permissions -p ${RABBITMQ_VHOST} ${RABBITMQ_USER} \"$EXCHANGES\" \"$EXCHANGES\" \"$EXCHANGES\"" - loudCmd "rabbitmqctl set_permissions -p ${RABBITMQ_VHOST} ${RABBITMQ_USER} .\* .\* .\*" + verbose "\n * Setting RabbitMQ user permissions..." + #loudCmd "rabbitmqctl set_permissions -p ${RABBITMQ_VHOST} ${RABBITMQ_USER} \"$EXCHANGES\" \"$EXCHANGES\" \"$EXCHANGES\"" + loudCmd "rabbitmqctl set_permissions -p ${RABBITMQ_VHOST} ${RABBITMQ_USER} .\* .\* .\*" fi if [ ! -d "/etc/airtime" ]; then - loud "\n-----------------------------------------------------" - loud " * Installing Libretime * " - loud "-----------------------------------------------------" + loud "\n-----------------------------------------------------" + loud " * Installing Libretime * " + loud "-----------------------------------------------------" - verbose "\n * Creating /etc/airtime/ directory..." - mkdir /etc/airtime + verbose "\n * Creating /etc/airtime/ directory..." + mkdir /etc/airtime fi if [ "$icecast" = "t" ]; then @@ -1154,63 +1175,62 @@ fi chown -R ${web_user}:${web_user} /etc/airtime if [ ! -d "/srv/airtime" ]; then - mkdir -p /srv/airtime + mkdir -p /srv/airtime fi chown -R ${web_user}:${web_user} /srv/airtime - # We only generate the locales for Airtime if you're allowing us # to install our dependencies, so that we won't automatically do this # when this install script runs from our DEB package. if [ "$ignore_dependencies" = "f" ]; then - loud "\n-----------------------------------------------------" - loud " * Installing Locales * " - loud "-----------------------------------------------------" + loud "\n-----------------------------------------------------" + loud " * Installing Locales * " + loud "-----------------------------------------------------" - if $is_centos_dist; then - loud "\n not required on $dist" - else - set +e - verbose "\n * Generating locales" - for i in `ls ${web_root}/../locale | grep ".._.."`; do - if [ "$dist" = "debian" ]; then - grep -qi "^$i" /etc/locale.gen - if [ $? -ne 0 ]; then - verbose "$i.UTF-8 UTF-8" >> /etc/locale.gen - fi - else - loudCmd "locale-gen \"$i.utf8\"" - fi - done - set -e - fi + if $is_centos_dist; then + loud "\n not required on $dist" + else + set +e + verbose "\n * Generating locales" + for i in $(ls ${web_root}/../locale | grep ".._.."); do + if [ "$dist" = "debian" ]; then + grep -qi "^$i" /etc/locale.gen + if [ $? -ne 0 ]; then + verbose "$i.UTF-8 UTF-8" >> /etc/locale.gen + fi + else + loudCmd "locale-gen \"$i.utf8\"" + fi + done + set -e + fi - if [ "$dist" = "debian" ]; then - loudCmd "/usr/sbin/locale-gen" - fi + if [ "$dist" = "debian" ]; then + loudCmd "/usr/sbin/locale-gen" + fi fi # If the user requested it we run restorecon on files that need # tagging for selinux. if [ "$selinux" = "t" ]; then - loud "\n-----------------------------------------------------" - loud " * Restoring SELinux Tags * " - loud "-----------------------------------------------------" + loud "\n-----------------------------------------------------" + loud " * Restoring SELinux Tags * " + loud "-----------------------------------------------------" - verbose "\n * Running restorecon..." - loudCmd "restorecon -Rv /etc/airtime /srv/airtime > /dev/null 2>&1" - verbose "...Done" + verbose "\n * Running restorecon..." + loudCmd "restorecon -Rv /etc/airtime /srv/airtime > /dev/null 2>&1" + verbose "...Done" fi verbose "\n * Reloading apache..." systemInitCommand restart ${apache_service} # NOTE: ip command works on all supported platforms if $is_centos_dist; then - IP=$(ip -o -4 address show dev eth0 | grep -Po 'inet \K[\d.]+') + IP=$(ip -o -4 address show dev eth0 | grep -Po 'inet \K[\d.]+') else - # not on centos - ip_device="eth0" - IP=$(ifconfig ${ip_device} 2>/dev/null |awk -F'[ :]+' '/inet addr:/ {print $4}') + # not on centos + ip_device="eth0" + IP=$(ifconfig ${ip_device} 2> /dev/null | awk -F'[ :]+' '/inet addr:/ {print $4}') fi verbose "...Done" diff --git a/installer/lxc-bootstrap b/installer/lxc-bootstrap index 1f6fc17ad..a5fa9df90 100755 --- a/installer/lxc-bootstrap +++ b/installer/lxc-bootstrap @@ -3,8 +3,8 @@ #return with a non-zero return value. if [[ $EUID -ne 0 ]]; then - echo "Please run as root user." - exit 1 + echo "Please run as root user." + exit 1 fi dist=$1 @@ -52,9 +52,9 @@ echo "...Done" IP=$(lxc-info -i -n ${name} -H) echo -e "\n * Opening ${name} in your browser..." -if hash xdg-open 2>/dev/null; then +if hash xdg-open 2> /dev/null; then xdg-open "http://${IP}/" -elif hash gnome-open 2>/dev/null; then +elif hash gnome-open 2> /dev/null; then gnome-open "http://${IP}/" fi echo "...Done" diff --git a/installer/vagrant/centos.sh b/installer/vagrant/centos.sh index 404f596f2..d93c45c41 100755 --- a/installer/vagrant/centos.sh +++ b/installer/vagrant/centos.sh @@ -9,15 +9,15 @@ dnf config-manager --enable powertools # xiph multimedia (for icecast) curl -o /etc/yum.repos.d/multimedia:xiph.repo \ - https://download.opensuse.org/repositories/multimedia:/xiph/CentOS_8/multimedia:xiph.repo + https://download.opensuse.org/repositories/multimedia:/xiph/CentOS_8/multimedia:xiph.repo # RaBe Liquidsoap Distribution (RaBe LSD) curl -o /etc/yum.repos.d/home:radiorabe:liquidsoap.repo \ - https://download.opensuse.org/repositories/home:/radiorabe:/liquidsoap/CentOS_8/home:radiorabe:liquidsoap.repo + https://download.opensuse.org/repositories/home:/radiorabe:/liquidsoap/CentOS_8/home:radiorabe:liquidsoap.repo # RaBe Audio Packages for Enterprise Linux (RaBe APEL) curl -o /etc/yum.repos.d/home:radiorabe:audio.repo \ - https://download.opensuse.org/repositories/home:/radiorabe:/audio/CentOS_8/home:radiorabe:audio.repo + https://download.opensuse.org/repositories/home:/radiorabe:/audio/CentOS_8/home:radiorabe:audio.repo # Update all the things (just to be sure we are on latest) yum update -y @@ -58,7 +58,6 @@ su -l postgres bash -c 'createdb -O airtime airtime' echo "ALTER USER airtime WITH PASSWORD 'airtime';" | su -l postgres bash -c psql echo "GRANT ALL PRIVILEGES ON DATABASE airtime TO airtime;" | su -l postgres bash -c psql - # RabbitMQ curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.rpm.sh | sudo bash yum install -y rabbitmq-server @@ -142,7 +141,6 @@ sed -i \ -e 's/LoadModule mpm_event_module/#LoadModule mpm_event_module/' \ /etc/httpd/conf.modules.d/00-mpm.conf - # celery will not run unless we install a specific version (https://github.com/pypa/setuptools/issues/942) # this will need to be figured out later on and will get overridden by the docs installer anyhow :( pip3 install setuptools==33.1.1 diff --git a/python_apps/airtime-celery/install/initd/libretime-celery b/python_apps/airtime-celery/install/initd/libretime-celery index 55a21f939..5f2969cde 100755 --- a/python_apps/airtime-celery/install/initd/libretime-celery +++ b/python_apps/airtime-celery/install/initd/libretime-celery @@ -8,7 +8,6 @@ # # See http://docs.celeryproject.org/en/latest/tutorials/daemonizing.html#generic-init-scripts - ### BEGIN INIT INFO # Provides: celeryd # Required-Start: $network $local_fs $remote_fs @@ -31,19 +30,19 @@ VERSION=10.1 echo "celery init v${VERSION}." if [ $(id -u) -ne 0 ]; then - echo "Error: This program can only be used by the root user." - echo " Unprivileged users must use the 'celery multi' utility, " - echo " or 'celery worker --detach'." - exit 1 + echo "Error: This program can only be used by the root user." + echo " Unprivileged users must use the 'celery multi' utility, " + echo " or 'celery worker --detach'." + exit 1 fi export RMQ_CONFIG_FILE="/etc/airtime/airtime.conf" # Can be a runlevel symlink (e.g. S02celeryd) if [ -L "$0" ]; then - SCRIPT_FILE=$(readlink "$0") + SCRIPT_FILE=$(readlink "$0") else - SCRIPT_FILE="$0" + SCRIPT_FILE="$0" fi SCRIPT_NAME="$(basename "$SCRIPT_FILE")" @@ -57,53 +56,53 @@ DEFAULT_CELERYD="-m celery worker --detach" CELERY_DEFAULTS=${CELERY_DEFAULTS:-"/etc/default/${SCRIPT_NAME}"} # Make sure executable configuration script is owned by root _config_sanity() { - local path="$1" - local owner=$(ls -ld "$path" | awk '{print $3}') - local iwgrp=$(ls -ld "$path" | cut -b 6) - local iwoth=$(ls -ld "$path" | cut -b 9) - if [ "$(id -u $owner)" != "0" ]; then - echo "Error: Config script '$path' must be owned by root!" - echo - echo "Resolution:" - echo "Review the file carefully and make sure it has not been " - echo "modified with mailicious intent. When sure the " - echo "script is safe to execute with superuser privileges " - echo "you can change ownership of the script:" - echo " $ sudo chown root '$path'" - exit 1 - fi - if [ "$iwoth" != "-" ]; then # S_IWOTH - echo "Error: Config script '$path' cannot be writable by others!" - echo - echo "Resolution:" - echo "Review the file carefully and make sure it has not been " - echo "modified with malicious intent. When sure the " - echo "script is safe to execute with superuser privileges " - echo "you can change the scripts permissions:" - echo " $ sudo chmod 640 '$path'" - exit 1 - fi - if [ "$iwgrp" != "-" ]; then # S_IWGRP - echo "Error: Config script '$path' cannot be writable by group!" - echo - echo "Resolution:" - echo "Review the file carefully and make sure it has not been " - echo "modified with malicious intent. When sure the " - echo "script is safe to execute with superuser privileges " - echo "you can change the scripts permissions:" - echo " $ sudo chmod 640 '$path'" - exit 1 - fi + local path="$1" + local owner=$(ls -ld "$path" | awk '{print $3}') + local iwgrp=$(ls -ld "$path" | cut -b 6) + local iwoth=$(ls -ld "$path" | cut -b 9) + if [ "$(id -u $owner)" != "0" ]; then + echo "Error: Config script '$path' must be owned by root!" + echo + echo "Resolution:" + echo "Review the file carefully and make sure it has not been " + echo "modified with mailicious intent. When sure the " + echo "script is safe to execute with superuser privileges " + echo "you can change ownership of the script:" + echo " $ sudo chown root '$path'" + exit 1 + fi + if [ "$iwoth" != "-" ]; then # S_IWOTH + echo "Error: Config script '$path' cannot be writable by others!" + echo + echo "Resolution:" + echo "Review the file carefully and make sure it has not been " + echo "modified with malicious intent. When sure the " + echo "script is safe to execute with superuser privileges " + echo "you can change the scripts permissions:" + echo " $ sudo chmod 640 '$path'" + exit 1 + fi + if [ "$iwgrp" != "-" ]; then # S_IWGRP + echo "Error: Config script '$path' cannot be writable by group!" + echo + echo "Resolution:" + echo "Review the file carefully and make sure it has not been " + echo "modified with malicious intent. When sure the " + echo "script is safe to execute with superuser privileges " + echo "you can change the scripts permissions:" + echo " $ sudo chmod 640 '$path'" + exit 1 + fi } if [ -f "$CELERY_DEFAULTS" ]; then - _config_sanity "$CELERY_DEFAULTS" - echo "Using config script: $CELERY_DEFAULTS" - . "$CELERY_DEFAULTS" + _config_sanity "$CELERY_DEFAULTS" + echo "Using config script: $CELERY_DEFAULTS" + . "$CELERY_DEFAULTS" fi # Sets --app argument for CELERY_BIN CELERY_APP_ARG="" if [ ! -z "$CELERY_APP" ]; then - CELERY_APP_ARG="--app=$CELERY_APP" + CELERY_APP_ARG="--app=$CELERY_APP" fi CELERYD_USER=${CELERYD_USER:-$DEFAULT_USER} # Set CELERY_CREATE_DIRS to always create log/pid dirs. @@ -111,12 +110,12 @@ CELERY_CREATE_DIRS=${CELERY_CREATE_DIRS:-0} CELERY_CREATE_RUNDIR=$CELERY_CREATE_DIRS CELERY_CREATE_LOGDIR=$CELERY_CREATE_DIRS if [ -z "$CELERYD_PID_FILE" ]; then - CELERYD_PID_FILE="$DEFAULT_PID_FILE" - CELERY_CREATE_RUNDIR=1 + CELERYD_PID_FILE="$DEFAULT_PID_FILE" + CELERY_CREATE_RUNDIR=1 fi if [ -z "$CELERYD_LOG_FILE" ]; then - CELERYD_LOG_FILE="$DEFAULT_LOG_FILE" - CELERY_CREATE_LOGDIR=1 + CELERYD_LOG_FILE="$DEFAULT_LOG_FILE" + CELERY_CREATE_LOGDIR=1 fi CELERYD_LOG_LEVEL=${CELERYD_LOG_LEVEL:-${CELERYD_LOGLEVEL:-$DEFAULT_LOG_LEVEL}} CELERY_BIN=${CELERY_BIN:-"celery"} @@ -124,211 +123,211 @@ CELERYD_MULTI=${CELERYD_MULTI:-"$CELERY_BIN multi"} CELERYD_NODES=${CELERYD_NODES:-$DEFAULT_NODES} export CELERY_LOADER if [ -n "$2" ]; then - CELERYD_OPTS="$CELERYD_OPTS $2" + CELERYD_OPTS="$CELERYD_OPTS $2" fi -CELERYD_LOG_DIR=`dirname $CELERYD_LOG_FILE` -CELERYD_PID_DIR=`dirname $CELERYD_PID_FILE` +CELERYD_LOG_DIR=$(dirname $CELERYD_LOG_FILE) +CELERYD_PID_DIR=$(dirname $CELERYD_PID_FILE) # Extra start-stop-daemon options, like user/group. if [ -n "$CELERYD_CHDIR" ]; then - DAEMON_OPTS="$DAEMON_OPTS --workdir=$CELERYD_CHDIR" + DAEMON_OPTS="$DAEMON_OPTS --workdir=$CELERYD_CHDIR" fi check_dev_null() { - if [ ! -c /dev/null ]; then - echo "/dev/null is not a character device!" - exit 75 # EX_TEMPFAIL - fi + if [ ! -c /dev/null ]; then + echo "/dev/null is not a character device!" + exit 75 # EX_TEMPFAIL + fi } maybe_die() { - if [ $? -ne 0 ]; then - echo "Exiting: $* (errno $?)" - exit 77 # EX_NOPERM - fi + if [ $? -ne 0 ]; then + echo "Exiting: $* (errno $?)" + exit 77 # EX_NOPERM + fi } create_default_dir() { - if [ ! -d "$1" ]; then - echo "- Creating default directory: '$1'" - mkdir -p "$1" - maybe_die "Couldn't create directory $1" - echo "- Changing permissions of '$1' to 02755" - chmod 02755 "$1" - maybe_die "Couldn't change permissions for $1" - if [ -n "$CELERYD_USER" ]; then - echo "- Changing owner of '$1' to '$CELERYD_USER'" - chown "$CELERYD_USER" "$1" - maybe_die "Couldn't change owner of $1" - fi - if [ -n "$CELERYD_GROUP" ]; then - echo "- Changing group of '$1' to '$CELERYD_GROUP'" - chgrp "$CELERYD_GROUP" "$1" - maybe_die "Couldn't change group of $1" - fi + if [ ! -d "$1" ]; then + echo "- Creating default directory: '$1'" + mkdir -p "$1" + maybe_die "Couldn't create directory $1" + echo "- Changing permissions of '$1' to 02755" + chmod 02755 "$1" + maybe_die "Couldn't change permissions for $1" + if [ -n "$CELERYD_USER" ]; then + echo "- Changing owner of '$1' to '$CELERYD_USER'" + chown "$CELERYD_USER" "$1" + maybe_die "Couldn't change owner of $1" fi + if [ -n "$CELERYD_GROUP" ]; then + echo "- Changing group of '$1' to '$CELERYD_GROUP'" + chgrp "$CELERYD_GROUP" "$1" + maybe_die "Couldn't change group of $1" + fi + fi } check_paths() { - if [ $CELERY_CREATE_LOGDIR -eq 1 ]; then - create_default_dir "$CELERYD_LOG_DIR" - fi - if [ $CELERY_CREATE_RUNDIR -eq 1 ]; then - create_default_dir "$CELERYD_PID_DIR" - fi + if [ $CELERY_CREATE_LOGDIR -eq 1 ]; then + create_default_dir "$CELERYD_LOG_DIR" + fi + if [ $CELERY_CREATE_RUNDIR -eq 1 ]; then + create_default_dir "$CELERYD_PID_DIR" + fi } create_paths() { - create_default_dir "$CELERYD_LOG_DIR" - create_default_dir "$CELERYD_PID_DIR" + create_default_dir "$CELERYD_LOG_DIR" + create_default_dir "$CELERYD_PID_DIR" } export PATH="${PATH:+$PATH:}/usr/sbin:/sbin" -_get_pidfiles () { - # note: multi < 3.1.14 output to stderr, not stdout, hence the redirect. - ${CELERYD_MULTI} expand "${CELERYD_PID_FILE}" ${CELERYD_NODES} 2>&1 +_get_pidfiles() { + # note: multi < 3.1.14 output to stderr, not stdout, hence the redirect. + ${CELERYD_MULTI} expand "${CELERYD_PID_FILE}" ${CELERYD_NODES} 2>&1 } _get_pids() { - found_pids=0 - my_exitcode=0 - for pidfile in $(_get_pidfiles); do - local pid=`cat "$pidfile"` - local cleaned_pid=`echo "$pid" | sed -e 's/[^0-9]//g'` - if [ -z "$pid" ] || [ "$cleaned_pid" != "$pid" ]; then - echo "bad pid file ($pidfile)" - one_failed=true - my_exitcode=1 - else - found_pids=1 - echo "$pid" - fi + found_pids=0 + my_exitcode=0 + for pidfile in $(_get_pidfiles); do + local pid=$(cat "$pidfile") + local cleaned_pid=$(echo "$pid" | sed -e 's/[^0-9]//g') + if [ -z "$pid" ] || [ "$cleaned_pid" != "$pid" ]; then + echo "bad pid file ($pidfile)" + one_failed=true + my_exitcode=1 + else + found_pids=1 + echo "$pid" + fi if [ $found_pids -eq 0 ]; then - echo "${SCRIPT_NAME}: All nodes down" - exit $my_exitcode + echo "${SCRIPT_NAME}: All nodes down" + exit $my_exitcode fi - done + done } -_chuid () { - su "$CELERYD_USER" -c "$CELERYD_MULTI $*" +_chuid() { + su "$CELERYD_USER" -c "$CELERYD_MULTI $*" } -start_workers () { - if [ ! -z "$CELERYD_ULIMIT" ]; then - ulimit $CELERYD_ULIMIT - fi - _chuid $* start $CELERYD_NODES $DAEMON_OPTS \ - --pidfile="$CELERYD_PID_FILE" \ - --logfile="$CELERYD_LOG_FILE" \ - --loglevel="$CELERYD_LOG_LEVEL" \ - $CELERY_APP_ARG \ - $CELERYD_OPTS +start_workers() { + if [ ! -z "$CELERYD_ULIMIT" ]; then + ulimit $CELERYD_ULIMIT + fi + _chuid $* start $CELERYD_NODES $DAEMON_OPTS \ + --pidfile="$CELERYD_PID_FILE" \ + --logfile="$CELERYD_LOG_FILE" \ + --loglevel="$CELERYD_LOG_LEVEL" \ + $CELERY_APP_ARG \ + $CELERYD_OPTS } -dryrun () { - (C_FAKEFORK=1 start_workers --verbose) +dryrun() { + (C_FAKEFORK=1 start_workers --verbose) } -stop_workers () { - _chuid stopwait $CELERYD_NODES --pidfile="$CELERYD_PID_FILE" +stop_workers() { + _chuid stopwait $CELERYD_NODES --pidfile="$CELERYD_PID_FILE" } -restart_workers () { - _chuid restart $CELERYD_NODES $DAEMON_OPTS \ - --pidfile="$CELERYD_PID_FILE" \ - --logfile="$CELERYD_LOG_FILE" \ - --loglevel="$CELERYD_LOG_LEVEL" \ - $CELERY_APP_ARG \ - $CELERYD_OPTS +restart_workers() { + _chuid restart $CELERYD_NODES $DAEMON_OPTS \ + --pidfile="$CELERYD_PID_FILE" \ + --logfile="$CELERYD_LOG_FILE" \ + --loglevel="$CELERYD_LOG_LEVEL" \ + $CELERY_APP_ARG \ + $CELERYD_OPTS } kill_workers() { - _chuid kill $CELERYD_NODES --pidfile="$CELERYD_PID_FILE" + _chuid kill $CELERYD_NODES --pidfile="$CELERYD_PID_FILE" } -restart_workers_graceful () { - echo "WARNING: Use with caution in production" - echo "The workers will attempt to restart, but they may not be able to." - local worker_pids= - worker_pids=`_get_pids` - [ "$one_failed" ] && exit 1 - for worker_pid in $worker_pids; do - local failed= - kill -HUP $worker_pid 2> /dev/null || failed=true - if [ "$failed" ]; then - echo "${SCRIPT_NAME} worker (pid $worker_pid) could not be restarted" - one_failed=true - else - echo "${SCRIPT_NAME} worker (pid $worker_pid) received SIGHUP" - fi - done - [ "$one_failed" ] && exit 1 || exit 0 +restart_workers_graceful() { + echo "WARNING: Use with caution in production" + echo "The workers will attempt to restart, but they may not be able to." + local worker_pids= + worker_pids=$(_get_pids) + [ "$one_failed" ] && exit 1 + for worker_pid in $worker_pids; do + local failed= + kill -HUP $worker_pid 2> /dev/null || failed=true + if [ "$failed" ]; then + echo "${SCRIPT_NAME} worker (pid $worker_pid) could not be restarted" + one_failed=true + else + echo "${SCRIPT_NAME} worker (pid $worker_pid) received SIGHUP" + fi + done + [ "$one_failed" ] && exit 1 || exit 0 } -check_status () { - my_exitcode=0 - found_pids=0 - local one_failed= - for pidfile in $(_get_pidfiles); do - if [ ! -r $pidfile ]; then - echo "${SCRIPT_NAME} down: no pidfiles found" - one_failed=true - break - fi - local node=`basename "$pidfile" .pid` - local pid=`cat "$pidfile"` - local cleaned_pid=`echo "$pid" | sed -e 's/[^0-9]//g'` - if [ -z "$pid" ] || [ "$cleaned_pid" != "$pid" ]; then - echo "bad pid file ($pidfile)" - one_failed=true - else - local failed= - kill -0 $pid 2> /dev/null || failed=true - if [ "$failed" ]; then - echo "${SCRIPT_NAME} (node $node) (pid $pid) is down, but pidfile exists!" - one_failed=true - else - echo "${SCRIPT_NAME} (node $node) (pid $pid) is up..." - fi - fi - done - [ "$one_failed" ] && exit 1 || exit 0 +check_status() { + my_exitcode=0 + found_pids=0 + local one_failed= + for pidfile in $(_get_pidfiles); do + if [ ! -r $pidfile ]; then + echo "${SCRIPT_NAME} down: no pidfiles found" + one_failed=true + break + fi + local node=$(basename "$pidfile" .pid) + local pid=$(cat "$pidfile") + local cleaned_pid=$(echo "$pid" | sed -e 's/[^0-9]//g') + if [ -z "$pid" ] || [ "$cleaned_pid" != "$pid" ]; then + echo "bad pid file ($pidfile)" + one_failed=true + else + local failed= + kill -0 $pid 2> /dev/null || failed=true + if [ "$failed" ]; then + echo "${SCRIPT_NAME} (node $node) (pid $pid) is down, but pidfile exists!" + one_failed=true + else + echo "${SCRIPT_NAME} (node $node) (pid $pid) is up..." + fi + fi + done + [ "$one_failed" ] && exit 1 || exit 0 } case "$1" in - start) - check_dev_null - check_paths - start_workers + start) + check_dev_null + check_paths + start_workers ;; - stop) - check_dev_null - check_paths - stop_workers + stop) + check_dev_null + check_paths + stop_workers ;; - reload|force-reload) - echo "Use restart" + reload | force-reload) + echo "Use restart" ;; - status) - check_status + status) + check_status ;; - restart) - check_dev_null - check_paths - restart_workers + restart) + check_dev_null + check_paths + restart_workers ;; - graceful) - check_dev_null - restart_workers_graceful + graceful) + check_dev_null + restart_workers_graceful ;; - kill) - check_dev_null - kill_workers + kill) + check_dev_null + kill_workers ;; - dryrun) - check_dev_null - dryrun + dryrun) + check_dev_null + dryrun ;; - try-restart) - check_dev_null - check_paths - restart_workers + try-restart) + check_dev_null + check_paths + restart_workers ;; - create-paths) - check_dev_null - create_paths + create-paths) + check_dev_null + create_paths ;; - check-paths) - check_dev_null - check_paths + check-paths) + check_dev_null + check_paths ;; - *) - echo "Usage: /etc/init.d/${SCRIPT_NAME} {start|stop|restart|graceful|kill|dryrun|create-paths}" - exit 64 # EX_USAGE + *) + echo "Usage: /etc/init.d/${SCRIPT_NAME} {start|stop|restart|graceful|kill|dryrun|create-paths}" + exit 64 # EX_USAGE ;; esac exit 0 diff --git a/python_apps/airtime_analyzer/install/sysvinit/libretime-analyzer b/python_apps/airtime_analyzer/install/sysvinit/libretime-analyzer index 1b1c706e0..0b7493a46 100755 --- a/python_apps/airtime_analyzer/install/sysvinit/libretime-analyzer +++ b/python_apps/airtime_analyzer/install/sysvinit/libretime-analyzer @@ -30,49 +30,49 @@ PIDFILE=/var/run/$NAME.pid # and status_of_proc is working. . /lib/lsb/init-functions -start () { - start-stop-daemon --start --background --quiet --chuid $USERID:$GROUPID \ - --make-pidfile --pidfile $PIDFILE --startas $DAEMON +start() { + start-stop-daemon --start --background --quiet --chuid $USERID:$GROUPID \ + --make-pidfile --pidfile $PIDFILE --startas $DAEMON } -stop () { - # Send TERM after 5 seconds, wait at most 30 seconds. - start-stop-daemon --stop --oknodo --retry TERM/5/0/30 --quiet --pidfile $PIDFILE - rm -f $PIDFILE +stop() { + # Send TERM after 5 seconds, wait at most 30 seconds. + start-stop-daemon --stop --oknodo --retry TERM/5/0/30 --quiet --pidfile $PIDFILE + rm -f $PIDFILE } case "${1:-''}" in 'start') - # start commands here - echo -n "Starting $NAME: " - start - echo "Done." - ;; + # start commands here + echo -n "Starting $NAME: " + start + echo "Done." + ;; 'stop') - # stop commands here - echo -n "Stopping $NAME: " - stop - echo "Done." - ;; + # stop commands here + echo -n "Stopping $NAME: " + stop + echo "Done." + ;; 'restart') - # restart commands here - echo -n "Restarting $NAME: " - stop - start - echo "Done." - ;; + # restart commands here + echo -n "Restarting $NAME: " + stop + start + echo "Done." + ;; 'force-reload') - # reload commands here - echo -n "Reloading $NAME: " - stop - start - echo "Done." - ;; + # reload commands here + echo -n "Reloading $NAME: " + stop + start + echo "Done." + ;; 'status') - status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? - ;; - *) # no parameter specified - echo "Usage: $SELF start|stop|restart|status" - exit 1 - ;; + status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? + ;; + *) # no parameter specified + echo "Usage: $SELF start|stop|restart|status" + exit 1 + ;; esac diff --git a/python_apps/airtime_analyzer/tools/ftp-upload-hook.sh b/python_apps/airtime_analyzer/tools/ftp-upload-hook.sh index 44dc5159c..fb765afb8 100755 --- a/python_apps/airtime_analyzer/tools/ftp-upload-hook.sh +++ b/python_apps/airtime_analyzer/tools/ftp-upload-hook.sh @@ -1,49 +1,46 @@ #!/bin/bash -xv post_file() { - #kill process after 30 minutes (360*5=30 minutes) - max_retry=5 - retry_count=0 + #kill process after 30 minutes (360*5=30 minutes) + max_retry=5 + retry_count=0 - file_path="${1}" - # Give us write permissions on the file to prevent problems if the user - # uploads a read-only file. - chmod +w "${file_path}" + file_path="${1}" + # Give us write permissions on the file to prevent problems if the user + # uploads a read-only file. + chmod +w "${file_path}" - #We must remove commas because CURL can't upload files with commas in the name - # http://curl.haxx.se/mail/archive-2009-07/0029.html - stripped_file_path=${file_path//','/''} - mv "${file_path}" "${stripped_file_path}" - file_path="${stripped_file_path}" - filename="${file_path##*/}" + #We must remove commas because CURL can't upload files with commas in the name + # http://curl.haxx.se/mail/archive-2009-07/0029.html + stripped_file_path=${file_path//','/''} + mv "${file_path}" "${stripped_file_path}" + file_path="${stripped_file_path}" + filename="${file_path##*/}" - airtime_conf_path=/etc/airtime/airtime.conf + airtime_conf_path=/etc/airtime/airtime.conf + #instance_path will look like 1/1384, for example + http_path=$(grep base_url ${airtime_conf_path} | awk '{print $3;}') + http_port=$(grep base_port ${airtime_conf_path} | awk '{print $3;}') - #instance_path will look like 1/1384, for example - http_path=$(grep base_url ${airtime_conf_path} | awk '{print $3;}' ) - http_port=$(grep base_port ${airtime_conf_path} | awk '{print $3;}' ) + #post request url - http://bananas.airtime.pro/rest/media, for example + url=http:// + url+=$http_path + url+=: + url+=$http_port + url+=/rest/media - #post request url - http://bananas.airtime.pro/rest/media, for example - url=http:// - url+=$http_path - url+=: - url+=$http_port - url+=/rest/media + api_key=$(grep api_key ${airtime_conf_path} | awk '{print $3;}') - - api_key=$(grep api_key ${airtime_conf_path} | awk '{print $3;}' ) - - # -f is needed to make curl fail if there's an HTTP error code - # -L is needed to follow redirects! (just in case) - until curl -fL --max-time 30 $url -u $api_key":" -X POST -F "file=@${file_path}" - do - retry_count=$[$retry_count+1] - if [ $retry_count -ge $max_retry ]; then - break - fi - sleep 5 - done + # -f is needed to make curl fail if there's an HTTP error code + # -L is needed to follow redirects! (just in case) + until curl -fL --max-time 30 $url -u $api_key":" -X POST -F "file=@${file_path}"; do + retry_count=$(($retry_count + 1)) + if [ $retry_count -ge $max_retry ]; then + break + fi + sleep 5 + done } post_file "${1}" & diff --git a/python_apps/airtime_analyzer/tools/test-hook-script.sh b/python_apps/airtime_analyzer/tools/test-hook-script.sh index 475d29345..fcb925a8b 100755 --- a/python_apps/airtime_analyzer/tools/test-hook-script.sh +++ b/python_apps/airtime_analyzer/tools/test-hook-script.sh @@ -1,21 +1,20 @@ #! /bin/bash post_file() { - file_path=${1} - filename="${file_path##*/}" + file_path=${1} + filename="${file_path##*/}" - #kill process after 30 minutes (360*5=30 minutes) - max_retry=10 - retry_count=0 + #kill process after 30 minutes (360*5=30 minutes) + max_retry=10 + retry_count=0 - until curl --max-time 30 http://localhost/rest/media -u 3188BDIMPJROQP89Z0OX: -X POST -F "file=@${file_path}" -F "name=${filename}" - do - retry_count=$[$retry_count+1] - if [ $retry_count -ge $max_retry ]; then - break - fi - sleep 1 - done + until curl --max-time 30 http://localhost/rest/media -u 3188BDIMPJROQP89Z0OX: -X POST -F "file=@${file_path}" -F "name=${filename}"; do + retry_count=$(($retry_count + 1)) + if [ $retry_count -ge $max_retry ]; then + break + fi + sleep 1 + done } post_file "${1}" & diff --git a/python_apps/pypo/install/sysvinit/libretime-liquidsoap b/python_apps/pypo/install/sysvinit/libretime-liquidsoap index 34ddf2f4a..7ef1a3d62 100755 --- a/python_apps/pypo/install/sysvinit/libretime-liquidsoap +++ b/python_apps/pypo/install/sysvinit/libretime-liquidsoap @@ -30,49 +30,49 @@ PIDFILE=/var/run/$NAME.pid # and status_of_proc is working. . /lib/lsb/init-functions -start () { - start-stop-daemon --start --background --quiet --chuid $USERID:$GROUPID \ - --make-pidfile --pidfile $PIDFILE --startas $DAEMON +start() { + start-stop-daemon --start --background --quiet --chuid $USERID:$GROUPID \ + --make-pidfile --pidfile $PIDFILE --startas $DAEMON } -stop () { - # Send TERM after 5 seconds, wait at most 30 seconds. - start-stop-daemon --stop --oknodo --retry TERM/5/0/30 --quiet --pidfile $PIDFILE - rm -f $PIDFILE +stop() { + # Send TERM after 5 seconds, wait at most 30 seconds. + start-stop-daemon --stop --oknodo --retry TERM/5/0/30 --quiet --pidfile $PIDFILE + rm -f $PIDFILE } case "${1:-''}" in 'start') - # start commands here - echo -n "Starting $NAME: " - start - echo "Done." - ;; + # start commands here + echo -n "Starting $NAME: " + start + echo "Done." + ;; 'stop') - # stop commands here - echo -n "Stopping $NAME: " - stop - echo "Done." - ;; + # stop commands here + echo -n "Stopping $NAME: " + stop + echo "Done." + ;; 'restart') - # restart commands here - echo -n "Restarting $NAME: " - stop - start - echo "Done." - ;; + # restart commands here + echo -n "Restarting $NAME: " + stop + start + echo "Done." + ;; 'force-reload') - # reload commands here - echo -n "Reloading $NAME: " - stop - start - echo "Done." - ;; + # reload commands here + echo -n "Reloading $NAME: " + stop + start + echo "Done." + ;; 'status') - status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? - ;; - *) # no parameter specified - echo "Usage: $SELF start|stop|restart|status" - exit 1 - ;; + status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? + ;; + *) # no parameter specified + echo "Usage: $SELF start|stop|restart|status" + exit 1 + ;; esac diff --git a/python_apps/pypo/install/sysvinit/libretime-playout b/python_apps/pypo/install/sysvinit/libretime-playout index b5f6754fc..6326ef9ad 100755 --- a/python_apps/pypo/install/sysvinit/libretime-playout +++ b/python_apps/pypo/install/sysvinit/libretime-playout @@ -30,49 +30,49 @@ PIDFILE=/var/run/$NAME.pid # and status_of_proc is working. . /lib/lsb/init-functions -start () { - start-stop-daemon --start --background --quiet --chuid $USERID:$GROUPID \ - --make-pidfile --pidfile $PIDFILE --startas $DAEMON +start() { + start-stop-daemon --start --background --quiet --chuid $USERID:$GROUPID \ + --make-pidfile --pidfile $PIDFILE --startas $DAEMON } -stop () { - # Send TERM after 5 seconds, wait at most 30 seconds. - start-stop-daemon --stop --oknodo --retry TERM/5/0/30 --quiet --pidfile $PIDFILE - rm -f $PIDFILE +stop() { + # Send TERM after 5 seconds, wait at most 30 seconds. + start-stop-daemon --stop --oknodo --retry TERM/5/0/30 --quiet --pidfile $PIDFILE + rm -f $PIDFILE } case "${1:-''}" in 'start') - # start commands here - echo -n "Starting $NAME: " - start - echo "Done." - ;; + # start commands here + echo -n "Starting $NAME: " + start + echo "Done." + ;; 'stop') - # stop commands here - echo -n "Stopping $NAME: " - stop - echo "Done." - ;; + # stop commands here + echo -n "Stopping $NAME: " + stop + echo "Done." + ;; 'restart') - # restart commands here - echo -n "Restarting $NAME: " - stop - start - echo "Done." - ;; + # restart commands here + echo -n "Restarting $NAME: " + stop + start + echo "Done." + ;; 'force-reload') - # reload commands here - echo -n "Reloading $NAME: " - stop - start - echo "Done." - ;; + # reload commands here + echo -n "Reloading $NAME: " + stop + start + echo "Done." + ;; 'status') - status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? - ;; - *) # no parameter specified - echo "Usage: $SELF start|stop|restart|status" - exit 1 - ;; + status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? + ;; + *) # no parameter specified + echo "Usage: $SELF start|stop|restart|status" + exit 1 + ;; esac diff --git a/uninstall b/uninstall index 8255519b8..a1407fcfd 100755 --- a/uninstall +++ b/uninstall @@ -3,68 +3,61 @@ # return with a non-zero return value. if [[ $EUID -ne 0 ]]; then - echo "Please run as root user." - exit 1 + echo "Please run as root user." + exit 1 fi getStorDirFromDatabase() { - # here-doc to execute this block as postgres user - result=`su postgres <<'EOF' - set +e - echo $(psql -d airtime -tAc "SELECT directory FROM cc_music_dirs WHERE type='stor'") - set -e -# don't indent this! -EOF` - echo $result + echo $(sudo -u postgres psql -d airtime -tAc "SELECT directory FROM cc_music_dirs WHERE type='stor'") } dropLibreTimeDatabase() { - # here-doc to execute this block as postgres user - su postgres <<'EOF' - set +e - # DROP DATABASE cannot be executed from a function or multi-command string - psql -d postgres -tAc "DROP DATABASE IF EXISTS airtime_test" - psql -d postgres -tAc "DROP DATABASE IF EXISTS airtime" - psql -d postgres -tAc "DROP USER IF EXISTS airtime" - set -e + # here-doc to execute this block as postgres user + su postgres << 'EOF' +set +e +# DROP DATABASE cannot be executed from a function or multi-command string +psql -d postgres -tAc "DROP DATABASE IF EXISTS airtime_test" +psql -d postgres -tAc "DROP DATABASE IF EXISTS airtime" +psql -d postgres -tAc "DROP USER IF EXISTS airtime" +set -e # don't indent this! EOF } removeRabbitmqLibreTimeSettings() { - if [ -f /etc/airtime/airtime.conf ]; then - RMQ_VHOST=$(awk -F ' = ' '{if (! ($0 ~ /^;/) && $0 ~ /^vhost/ ) print $2}' /etc/airtime/airtime.conf) - RMQ_USER=$(awk -F ' = ' '{if (! ($0 ~ /^;/) && $0 ~ /^user/ ) print $2}' /etc/airtime/airtime.conf) - else - RMQ_VHOST=/airtime - RMQ_USER=airtime - fi + if [ -f /etc/airtime/airtime.conf ]; then + RMQ_VHOST=$(awk -F ' = ' '{if (! ($0 ~ /^;/) && $0 ~ /^vhost/ ) print $2}' /etc/airtime/airtime.conf) + RMQ_USER=$(awk -F ' = ' '{if (! ($0 ~ /^;/) && $0 ~ /^user/ ) print $2}' /etc/airtime/airtime.conf) + else + RMQ_VHOST=/airtime + RMQ_USER=airtime + fi - rabbitmqctl delete_vhost ${RMQ_VHOST} - rabbitmqctl delete_user ${RMQ_USER} + rabbitmqctl delete_vhost ${RMQ_VHOST} + rabbitmqctl delete_user ${RMQ_USER} } -SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )" +SCRIPT_DIR="$( cd "$( dirname "$0")" && pwd)" AIRTIMEROOT=${SCRIPT_DIR} STOR_DIR=$(getStorDirFromDatabase) FILES=( - "/etc/airtime" - "/var/log/airtime" - "/usr/lib/airtime" - "/usr/share/airtime" - "/etc/init/airtime*" - "/etc/systemd/system/libretime*" - "/usr/local/bin/airtime-*" - "/usr/bin/airtime*" - "/etc/apache2/sites-available/airtime*" - "/etc/apache2/sites-enabled/airtime*" - ) + "/etc/airtime" + "/var/log/airtime" + "/usr/lib/airtime" + "/usr/share/airtime" + "/etc/init/airtime*" + "/etc/systemd/system/libretime*" + "/usr/local/bin/airtime-*" + "/usr/bin/airtime*" + "/etc/apache2/sites-available/airtime*" + "/etc/apache2/sites-enabled/airtime*" +) echo -e "The following files, directories, and services will be removed:\n" for i in ${FILES[*]}; do - echo $i + echo $i done echo "pip3 airtime-playout" @@ -73,18 +66,18 @@ echo -e "\nIf your web root is not listed, you will need to manually remove it." echo -e "\nThis will *permanently* remove LibreTime and all related files from your computer. \ Any files in LibreTime directories and subdirectories will be deleted. Are you sure you want to proceed? [y/N]: \c" read IN -if [[ ! ( "$IN" = "y" || "$IN" = "Y" ) ]]; then - exit 0 +if [[ ! ("$IN" = "y" || "$IN" = "Y") ]]; then + exit 0 fi if [ -n "${STOR_DIR}" ]; then - echo -e "\nDo you want to remove your music storage directory ${STOR_DIR} and all of its subdirectories? [y/N]: \c" - read IN - if [[ ( "$IN" = "y" || "$IN" = "Y" ) ]]; then - rm -rf "${STOR_DIR}" - fi + echo -e "\nDo you want to remove your music storage directory ${STOR_DIR} and all of its subdirectories? [y/N]: \c" + read IN + if [[ ("$IN" = "y" || "$IN" = "Y") ]]; then + rm -rf "${STOR_DIR}" + fi else - echo -e "\nNo stor directory found, skipping..." + echo -e "\nNo stor directory found, skipping..." fi echo -e "\nUninstalling LibreTime..." @@ -94,14 +87,14 @@ removeRabbitmqLibreTimeSettings set -e for i in ${FILES[*]}; do - rm -rf $i + rm -rf $i done echo -e "\nDo you want to drop your current LibreTime database? [y/N]: \c" read IN if [[ "$IN" = "y" || "$IN" = "Y" ]]; then - echo -e "\nDropping LibreTime database..." - dropLibreTimeDatabase + echo -e "\nDropping LibreTime database..." + dropLibreTimeDatabase fi pip3 uninstall -y airtime-playout airtime-media-monitor airtime-analyzer diff --git a/utils/airtime-log b/utils/airtime-log index b606d9217..63f6ba4f6 100755 --- a/utils/airtime-log +++ b/utils/airtime-log @@ -1,7 +1,7 @@ #!/bin/bash # Absolute path to this script -SCRIPT=`readlink -f $0` +SCRIPT=$(readlink -f $0) # Absolute directory this script is in -SCRIPTPATH=`dirname $SCRIPT` +SCRIPTPATH=$(dirname $SCRIPT) php -q $SCRIPTPATH/airtime-log.php "$@" || exit 1 diff --git a/utils/airtime-test-soundcard b/utils/airtime-test-soundcard index 018697724..1a389c082 100755 --- a/utils/airtime-test-soundcard +++ b/utils/airtime-test-soundcard @@ -24,9 +24,9 @@ # This script send data to data collection server # # Absolute path to this script -SCRIPT=`readlink -f $0` +SCRIPT=$(readlink -f $0) # Absolute directory this script is in -SCRIPTPATH=`dirname $SCRIPT` +SCRIPTPATH=$(dirname $SCRIPT) cd $SCRIPTPATH diff --git a/utils/airtime-test-stream b/utils/airtime-test-stream index 4c49fe27c..9b3e7bf70 100755 --- a/utils/airtime-test-stream +++ b/utils/airtime-test-stream @@ -24,9 +24,9 @@ # This script send data to data collection server # # Absolute path to this script -SCRIPT=`readlink -f $0` +SCRIPT=$(readlink -f $0) # Absolute directory this script is in -SCRIPTPATH=`dirname $SCRIPT` +SCRIPTPATH=$(dirname $SCRIPT) cd $SCRIPTPATH diff --git a/utils/libretime-backup.sh b/utils/libretime-backup.sh index d8a12f556..7b1df87df 100755 --- a/utils/libretime-backup.sh +++ b/utils/libretime-backup.sh @@ -1,21 +1,19 @@ #!/bin/bash -if [ -z "$1" ] - then - ## Use config - backup_folder=~/libretime_backup/ - else - ## User arg as config - backup_folder=$1 +if [ -z "$1" ]; then + ## Use config + backup_folder=~/libretime_backup/ +else + ## User arg as config + backup_folder=$1 fi - airtime_conf_path=/etc/airtime/airtime.conf uploads_folder=/srv/airtime/stor/ -psdl_db=$(grep dbname ${airtime_conf_path} | awk '{print $3;}' ) -psql_user=$(grep dbuser ${airtime_conf_path} | awk '{print $3;}' ) -psql_password=$(grep dbpass ${airtime_conf_path} | awk '{print $3;}' ) +psdl_db=$(grep dbname ${airtime_conf_path} | awk '{print $3;}') +psql_user=$(grep dbuser ${airtime_conf_path} | awk '{print $3;}') +psql_password=$(grep dbpass ${airtime_conf_path} | awk '{print $3;}') ## Remove old backup rm -rf $backup_folder diff --git a/utils/rabbitmq-update-pid.sh b/utils/rabbitmq-update-pid.sh index 435939196..cbaaa3f12 100755 --- a/utils/rabbitmq-update-pid.sh +++ b/utils/rabbitmq-update-pid.sh @@ -4,11 +4,11 @@ pid_found="$?" if [ "$pid_found" == "0" ]; then - #PID is available in the status message - rabbitmqpid=`/etc/init.d/rabbitmq-server status | grep "\[{pid" | sed "s/.*,\(.*\)\}.*/\1/"` + #PID is available in the status message + rabbitmqpid=$(/etc/init.d/rabbitmq-server status | grep "\[{pid" | sed "s/.*,\(.*\)\}.*/\1/") else - #PID should be available from file - rabbitmqpid=`sed "s/.*,\(.*\)\}.*/\1/" /var/lib/rabbitmq/pids` + #PID should be available from file + rabbitmqpid=$(sed "s/.*,\(.*\)\}.*/\1/" /var/lib/rabbitmq/pids) fi echo "RabbitMQ PID: $rabbitmqpid" diff --git a/utils/rivendell-converter.sh b/utils/rivendell-converter.sh index e4a80fc2e..f150a4e22 100755 --- a/utils/rivendell-converter.sh +++ b/utils/rivendell-converter.sh @@ -7,10 +7,9 @@ # 1 - Rivendell store files in .wav format, airtime uses .mp3 format # 2 - WAV does not have Meta-tag support so all meta-tags need to be fetched from Rivendell database. - if [ $# -ne 2 ]; then - echo "usage: $0 " - exit + echo "usage: $0 " + exit fi #*** MySql data ***# @@ -24,23 +23,21 @@ end_dir=$2 cd "$rivendell_dir" -for file in * -do - lame "$file" +for file in *; do + lame "$file" done mv "$rivendell_dir"/*.mp3 "$end_dir" cd "$end_dir" -for file in * -do - id=`echo $file | head -c 10` - title=`mysql -u $user -p$pass -sN -e "SELECT CU.DESCRIPTION FROM CUTS CU, CART CA WHERE CA.NUMBER=CU.CART_NUMBER AND CU.CUT_NAME=\"${id}\"" $db` - artist=`mysql -u $user -p$pass -sN -e "SELECT CA.ARTIST FROM CUTS CU, CART CA WHERE CA.NUMBER=CU.CART_NUMBER AND CU.CUT_NAME=\"${id}\"" $db` - album=`mysql -u $user -p$pass -sN -e "SELECT CA.ALBUM FROM CUTS CU, CART CA WHERE CA.NUMBER=CU.CART_NUMBER AND CU.CUT_NAME=\"${id}\"" $db` - year=`mysql -u $user -p$pass -sN -e "SELECT CA.YEAR FROM CUTS CU, CART CA WHERE CA.NUMBER=CU.CART_NUMBER AND CU.CUT_NAME=\"${id}\"" $db` - id3 -t "$title" -a "$artist" -A "$album" -y "$year" $file - mv "$file" "$artist-$title.mp3" +for file in *; do + id=$(echo $file | head -c 10) + title=$(mysql -u $user -p$pass -sN -e "SELECT CU.DESCRIPTION FROM CUTS CU, CART CA WHERE CA.NUMBER=CU.CART_NUMBER AND CU.CUT_NAME=\"${id}\"" $db) + artist=$(mysql -u $user -p$pass -sN -e "SELECT CA.ARTIST FROM CUTS CU, CART CA WHERE CA.NUMBER=CU.CART_NUMBER AND CU.CUT_NAME=\"${id}\"" $db) + album=$(mysql -u $user -p$pass -sN -e "SELECT CA.ALBUM FROM CUTS CU, CART CA WHERE CA.NUMBER=CU.CART_NUMBER AND CU.CUT_NAME=\"${id}\"" $db) + year=$(mysql -u $user -p$pass -sN -e "SELECT CA.YEAR FROM CUTS CU, CART CA WHERE CA.NUMBER=CU.CART_NUMBER AND CU.CUT_NAME=\"${id}\"" $db) + id3 -t "$title" -a "$artist" -A "$album" -y "$year" $file + mv "$file" "$artist-$title.mp3" done exit From b5f302ac6110f62b7a2f0aec559f1494e4fe1fe4 Mon Sep 17 00:00:00 2001 From: jo Date: Mon, 16 Aug 2021 14:21:46 +0200 Subject: [PATCH 5/8] Enhance bash shebangs --- airtime_mvc/tests/runtests.sh | 2 +- build.sh | 2 +- dev_tools/bootstrap_development_environment.sh | 2 +- dev_tools/liquidsoap_compile/liquidsoap-compile.sh | 2 +- dev_tools/liquidsoap_compile/run.sh | 2 +- dev_tools/postCommitBuildTrigger.sh | 2 +- dev_tools/propel_regenerate.sh | 2 +- dev_tools/release/release.sh | 2 +- dev_tools/toggle-pypo-debug.sh | 2 +- install | 2 +- installer/lxc-bootstrap | 2 +- installer/vagrant/centos.sh | 2 +- installer/vagrant/debian.sh | 2 +- .../airtime_analyzer/install/sysvinit/libretime-analyzer | 2 +- python_apps/airtime_analyzer/tools/ftp-upload-hook.sh | 2 +- python_apps/pypo/install/sysvinit/libretime-liquidsoap | 2 +- python_apps/pypo/install/sysvinit/libretime-playout | 2 +- uninstall | 2 +- utils/airtime-log | 2 +- utils/airtime-test-soundcard | 2 +- utils/airtime-test-stream | 2 +- utils/libretime-backup.sh | 2 +- utils/rabbitmq-update-pid.sh | 2 +- utils/rivendell-converter.sh | 2 +- 24 files changed, 24 insertions(+), 24 deletions(-) diff --git a/airtime_mvc/tests/runtests.sh b/airtime_mvc/tests/runtests.sh index 2d0d3005d..7213ecadb 100755 --- a/airtime_mvc/tests/runtests.sh +++ b/airtime_mvc/tests/runtests.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash #Create a RabbitMQ airtime_tests user #This is necessary for tests to run diff --git a/build.sh b/build.sh index 3323a815b..457d3d6ad 100755 --- a/build.sh +++ b/build.sh @@ -1,4 +1,4 @@ -#!/bin/bash -e +#!/usr/bin/env bash -e composer install --no-dev --no-interaction git_build="" diff --git a/dev_tools/bootstrap_development_environment.sh b/dev_tools/bootstrap_development_environment.sh index 245c6d1bb..87abd88da 100755 --- a/dev_tools/bootstrap_development_environment.sh +++ b/dev_tools/bootstrap_development_environment.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Set up 3 way PO file merging, which we need for non-mainline branches cp scripts/git-merge-po /usr/local/bin diff --git a/dev_tools/liquidsoap_compile/liquidsoap-compile.sh b/dev_tools/liquidsoap_compile/liquidsoap-compile.sh index 60085831e..aedef80aa 100755 --- a/dev_tools/liquidsoap_compile/liquidsoap-compile.sh +++ b/dev_tools/liquidsoap_compile/liquidsoap-compile.sh @@ -1,4 +1,4 @@ -#!/bin/bash -e +#!/usr/bin/env bash -e apt-get install -y --force-yes lsb-release sudo dist=$(lsb_release -is) code=$(lsb_release -cs) diff --git a/dev_tools/liquidsoap_compile/run.sh b/dev_tools/liquidsoap_compile/run.sh index 285ca1d84..3a22ea54e 100755 --- a/dev_tools/liquidsoap_compile/run.sh +++ b/dev_tools/liquidsoap_compile/run.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash exec 2>&1 diff --git a/dev_tools/postCommitBuildTrigger.sh b/dev_tools/postCommitBuildTrigger.sh index 80e667126..c45d31ad4 100755 --- a/dev_tools/postCommitBuildTrigger.sh +++ b/dev_tools/postCommitBuildTrigger.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # the base url of the bamboo server baseurl="$1/updateAndBuild.action?buildKey=" diff --git a/dev_tools/propel_regenerate.sh b/dev_tools/propel_regenerate.sh index 1d5addec2..966afc08b 100755 --- a/dev_tools/propel_regenerate.sh +++ b/dev_tools/propel_regenerate.sh @@ -1,4 +1,4 @@ -#!/bin/bash -e +#!/usr/bin/env bash -e # Absolute path to this script SCRIPT=$(readlink -f $0) # Absolute directory this script is in diff --git a/dev_tools/release/release.sh b/dev_tools/release/release.sh index 21029611f..5993e0eef 100755 --- a/dev_tools/release/release.sh +++ b/dev_tools/release/release.sh @@ -1,4 +1,4 @@ -#!/bin/bash -e +#!/usr/bin/env bash -e #release.sh 1.8.2 #creates a libretime folder with a "1.8.2" suffix diff --git a/dev_tools/toggle-pypo-debug.sh b/dev_tools/toggle-pypo-debug.sh index 4734b542b..e8409bbaf 100755 --- a/dev_tools/toggle-pypo-debug.sh +++ b/dev_tools/toggle-pypo-debug.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash if [[ $EUID -ne 0 ]]; then echo "This script must be run as root." 1>&2 exit 1 diff --git a/install b/install index 54913f6de..3f4d192a5 100755 --- a/install +++ b/install @@ -1,4 +1,4 @@ -#!/bin/bash -e +#!/usr/bin/env bash -e #-e Causes bash script to exit if any of the installers #return with a non-zero return value. diff --git a/installer/lxc-bootstrap b/installer/lxc-bootstrap index a5fa9df90..79eb227e3 100755 --- a/installer/lxc-bootstrap +++ b/installer/lxc-bootstrap @@ -1,4 +1,4 @@ -#!/bin/bash -e +#!/usr/bin/env bash -e #-e Causes bash script to exit if any of the installers #return with a non-zero return value. diff --git a/installer/vagrant/centos.sh b/installer/vagrant/centos.sh index d93c45c41..3963c211c 100755 --- a/installer/vagrant/centos.sh +++ b/installer/vagrant/centos.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Additional Repos yum install -y epel-release diff --git a/installer/vagrant/debian.sh b/installer/vagrant/debian.sh index c08d0aad7..ff3ffcd63 100755 --- a/installer/vagrant/debian.sh +++ b/installer/vagrant/debian.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash DEBIAN_FRONTEND=noninteractive apt-get -y install alsa-utils usermod -a -G audio vagrant diff --git a/python_apps/airtime_analyzer/install/sysvinit/libretime-analyzer b/python_apps/airtime_analyzer/install/sysvinit/libretime-analyzer index 0b7493a46..31da8d5f7 100755 --- a/python_apps/airtime_analyzer/install/sysvinit/libretime-analyzer +++ b/python_apps/airtime_analyzer/install/sysvinit/libretime-analyzer @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash ### BEGIN INIT INFO # Provides: libretime-analyzer diff --git a/python_apps/airtime_analyzer/tools/ftp-upload-hook.sh b/python_apps/airtime_analyzer/tools/ftp-upload-hook.sh index fb765afb8..01fe1b148 100755 --- a/python_apps/airtime_analyzer/tools/ftp-upload-hook.sh +++ b/python_apps/airtime_analyzer/tools/ftp-upload-hook.sh @@ -1,4 +1,4 @@ -#!/bin/bash -xv +#!/usr/bin/env bash -xv post_file() { #kill process after 30 minutes (360*5=30 minutes) diff --git a/python_apps/pypo/install/sysvinit/libretime-liquidsoap b/python_apps/pypo/install/sysvinit/libretime-liquidsoap index 7ef1a3d62..c90142c3a 100755 --- a/python_apps/pypo/install/sysvinit/libretime-liquidsoap +++ b/python_apps/pypo/install/sysvinit/libretime-liquidsoap @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash ### BEGIN INIT INFO # Provides: airtime-liquidsoap diff --git a/python_apps/pypo/install/sysvinit/libretime-playout b/python_apps/pypo/install/sysvinit/libretime-playout index 6326ef9ad..7a0b121ed 100755 --- a/python_apps/pypo/install/sysvinit/libretime-playout +++ b/python_apps/pypo/install/sysvinit/libretime-playout @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash ### BEGIN INIT INFO # Provides: airtime-playout diff --git a/uninstall b/uninstall index a1407fcfd..4d48a89ec 100755 --- a/uninstall +++ b/uninstall @@ -1,4 +1,4 @@ -#!/bin/bash -e +#!/usr/bin/env bash -e # -e Causes bash script to exit if any of the steps # return with a non-zero return value. diff --git a/utils/airtime-log b/utils/airtime-log index 63f6ba4f6..ef7cc7928 100755 --- a/utils/airtime-log +++ b/utils/airtime-log @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Absolute path to this script SCRIPT=$(readlink -f $0) # Absolute directory this script is in diff --git a/utils/airtime-test-soundcard b/utils/airtime-test-soundcard index 1a389c082..67722cdf2 100755 --- a/utils/airtime-test-soundcard +++ b/utils/airtime-test-soundcard @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash #------------------------------------------------------------------------------- # Copyright (c) 2011 Sourcefabric O.P.S. # diff --git a/utils/airtime-test-stream b/utils/airtime-test-stream index 9b3e7bf70..8634b2dc2 100755 --- a/utils/airtime-test-stream +++ b/utils/airtime-test-stream @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash #------------------------------------------------------------------------------- # Copyright (c) 2011 Sourcefabric O.P.S. # diff --git a/utils/libretime-backup.sh b/utils/libretime-backup.sh index 7b1df87df..03f7602c1 100755 --- a/utils/libretime-backup.sh +++ b/utils/libretime-backup.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash if [ -z "$1" ]; then ## Use config diff --git a/utils/rabbitmq-update-pid.sh b/utils/rabbitmq-update-pid.sh index cbaaa3f12..b46abb060 100755 --- a/utils/rabbitmq-update-pid.sh +++ b/utils/rabbitmq-update-pid.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash /etc/init.d/rabbitmq-server status | grep "\[{pid" pid_found="$?" diff --git a/utils/rivendell-converter.sh b/utils/rivendell-converter.sh index f150a4e22..a16b26c2d 100755 --- a/utils/rivendell-converter.sh +++ b/utils/rivendell-converter.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # A bash script to convert all Rivendell's audio-library to MP3, extract meta-tags from Rivendell's # database and set appropriate tags to each MP3 file. From dc999f90061dffc662f02cd4cd86e7e5653793a2 Mon Sep 17 00:00:00 2001 From: jo Date: Mon, 16 Aug 2021 17:44:19 +0200 Subject: [PATCH 6/8] Fix shellcheck errors --- .github/scripts/install-bionic.sh | 4 +- .github/scripts/install-xenial.sh | 4 +- .github/scripts/python-pkg-install.sh | 2 +- .github/scripts/python-pkg-test.sh | 2 +- build.sh | 7 +- .../liquidsoap_compile/liquidsoap-compile.sh | 5 +- dev_tools/liquidsoap_compile/run.sh | 8 +- dev_tools/propel_regenerate.sh | 5 +- dev_tools/release/release.sh | 4 +- install | 109 +++++++++--------- installer/lxc-bootstrap | 4 +- jekyll.sh | 4 +- .../airtime_analyzer/tools/ftp-upload-hook.sh | 6 +- .../tools/test-hook-script.sh | 2 +- uninstall | 40 +++---- 15 files changed, 108 insertions(+), 98 deletions(-) mode change 100644 => 100755 jekyll.sh diff --git a/.github/scripts/install-bionic.sh b/.github/scripts/install-bionic.sh index e5eb0ed19..0078e9769 100755 --- a/.github/scripts/install-bionic.sh +++ b/.github/scripts/install-bionic.sh @@ -25,5 +25,5 @@ apt-get install -y gstreamer1.0-plugins-base \ libcairo2-dev # Making log directory for PHP tests -mkdir -p $LIBRETIME_LOG_DIR -chown runner:runner $LIBRETIME_LOG_DIR +mkdir -p "$LIBRETIME_LOG_DIR" +chown runner:runner "$LIBRETIME_LOG_DIR" diff --git a/.github/scripts/install-xenial.sh b/.github/scripts/install-xenial.sh index e5eb0ed19..0078e9769 100755 --- a/.github/scripts/install-xenial.sh +++ b/.github/scripts/install-xenial.sh @@ -25,5 +25,5 @@ apt-get install -y gstreamer1.0-plugins-base \ libcairo2-dev # Making log directory for PHP tests -mkdir -p $LIBRETIME_LOG_DIR -chown runner:runner $LIBRETIME_LOG_DIR +mkdir -p "$LIBRETIME_LOG_DIR" +chown runner:runner "$LIBRETIME_LOG_DIR" diff --git a/.github/scripts/python-pkg-install.sh b/.github/scripts/python-pkg-install.sh index 5bcade24a..e30b8ce84 100755 --- a/.github/scripts/python-pkg-install.sh +++ b/.github/scripts/python-pkg-install.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash echo "::group::Install Python apps" -for app in $(ls python_apps); do +for app in python_apps/*; do if [[ -f "python_apps/$app/requirements-dev.txt" ]]; then pip3 install -r "python_apps/$app/requirements-dev.txt" fi diff --git a/.github/scripts/python-pkg-test.sh b/.github/scripts/python-pkg-test.sh index f0add173f..96f7cf18c 100755 --- a/.github/scripts/python-pkg-test.sh +++ b/.github/scripts/python-pkg-test.sh @@ -14,7 +14,7 @@ if ! make -C python_apps/api_clients test; then fi echo "::endgroup::" -if [[ "$failed" = "true" ]]; then +if [[ $failed == "true" ]]; then echo "Python tests failed" exit 1 fi diff --git a/build.sh b/build.sh index 457d3d6ad..2fbd3fa3d 100755 --- a/build.sh +++ b/build.sh @@ -1,4 +1,7 @@ -#!/usr/bin/env bash -e +#!/usr/bin/env bash + +set -e # Exit if any of the steps fails. + composer install --no-dev --no-interaction git_build="" @@ -14,7 +17,7 @@ if [ "${git_build}" = "y" ]; then git_version=$(git rev-parse --short HEAD) echo " * Overriding empty version with sha1 commit-ish: ${git_version}" fi - echo ${git_version} > VERSION + echo "${git_version}" > VERSION else # if no file was in tarball we create one letting the user know # if you run in to this you should grab an enriched tarball built diff --git a/dev_tools/liquidsoap_compile/liquidsoap-compile.sh b/dev_tools/liquidsoap_compile/liquidsoap-compile.sh index aedef80aa..211dd7fd3 100755 --- a/dev_tools/liquidsoap_compile/liquidsoap-compile.sh +++ b/dev_tools/liquidsoap_compile/liquidsoap-compile.sh @@ -1,4 +1,7 @@ -#!/usr/bin/env bash -e +#!/usr/bin/env bash + +set -e + apt-get install -y --force-yes lsb-release sudo dist=$(lsb_release -is) code=$(lsb_release -cs) diff --git a/dev_tools/liquidsoap_compile/run.sh b/dev_tools/liquidsoap_compile/run.sh index 3a22ea54e..d5d9b944f 100755 --- a/dev_tools/liquidsoap_compile/run.sh +++ b/dev_tools/liquidsoap_compile/run.sh @@ -105,12 +105,12 @@ while getopts b:c:u: arg; do b) if [ "$OPTARG" = "all" ]; then echo "Building all platforms on server..." - for i in $(seq 0 $(($num - 1))); do + for i in $(seq 0 $((num - 1))); do build_env ${os_versions[$i]} | tee ./liquidsoap-compile_logs/build_env_${os_versions[$i]}.log done else flag=1 - for i in $(seq 0 $(($num - 1))); do + for i in $(seq 0 $((num - 1))); do if [ "$OPTARG" = ${os_versions[$i]} ]; then echo "Building platform: $OPTARG ..." build_env ${os_versions[$i]} | tee ./liquidsoap-compile_logs/build_env_${os_versions[$i]}.log @@ -129,13 +129,13 @@ while getopts b:c:u: arg; do c) if [ "$OPTARG" = "all" ]; then echo "Compiling liquidsoap for all platforms on server..." - for i in $(seq 0 $(($num - 1))); do + for i in $(seq 0 $((num - 1))); do compile_liq ${os_versions[$i]} | tee ./liquidsoap-compile_logs/compile_liq_${os_versions[$i]}.log done else flag=1 - for i in $(seq 0 $(($num - 1))); do + for i in $(seq 0 $((num - 1))); do if [ "$OPTARG" = ${os_versions[$i]} ]; then echo "Compiling liquidsoap for platform: $OPTARG ..." compile_liq ${os_versions[$i]} | tee ./liquidsoap-compile_logs/compile_liq_${os_versions[$i]}.log diff --git a/dev_tools/propel_regenerate.sh b/dev_tools/propel_regenerate.sh index 966afc08b..bd2aac7eb 100755 --- a/dev_tools/propel_regenerate.sh +++ b/dev_tools/propel_regenerate.sh @@ -1,4 +1,7 @@ -#!/usr/bin/env bash -e +#!/usr/bin/env bash + +set -e + # Absolute path to this script SCRIPT=$(readlink -f $0) # Absolute directory this script is in diff --git a/dev_tools/release/release.sh b/dev_tools/release/release.sh index 5993e0eef..c50f3fa3d 100755 --- a/dev_tools/release/release.sh +++ b/dev_tools/release/release.sh @@ -1,4 +1,6 @@ -#!/usr/bin/env bash -e +#!/usr/bin/env bash + +set -e #release.sh 1.8.2 #creates a libretime folder with a "1.8.2" suffix diff --git a/install b/install index 3f4d192a5..ca90bc661 100755 --- a/install +++ b/install @@ -1,7 +1,6 @@ -#!/usr/bin/env bash -e +#!/usr/bin/env bash -#-e Causes bash script to exit if any of the installers -#return with a non-zero return value. +set -e # Exit if any of the steps fails. if [[ $EUID -ne 0 ]]; then echo "Please run as root user." @@ -111,16 +110,16 @@ function loud() { function loudCmd() { if [[ ${_q} -eq 0 ]]; then verbose "$@" - eval $@ + eval "$@" else - eval $@ > /dev/null + eval "$@" > /dev/null fi } function checkCommandExists() { set +e - command=$@ - eval hash ${command} 2> /dev/null + command="$1" + eval hash "${command}" 2> /dev/null commandFound=$? if [[ ! ${commandFound} -eq 0 ]]; then echo -e "Error: ${command} not found. Please ensure you have the corresponding dependency installed." @@ -150,8 +149,8 @@ function systemInitDetect() { # Get package of PID=1 path as it identifies the init system. # Allow this to fail, at least then the init system can be guessed from the # PID 1 executable alone - pid_1_package=$(dpkg -S $pid_1_path 2> /dev/null || - rpm --qf '%{name}\n' -qf $pid_1_path 2> /dev/null || + pid_1_package=$(dpkg -S "$pid_1_path" 2> /dev/null || + rpm --qf '%{name}\n' -qf "$pid_1_path" 2> /dev/null || echo "unknown") verbose "Detected package name for PID=1 process: $pid_1_package" case "${pid_1_package}:${pid_1_path}" in @@ -185,6 +184,7 @@ function systemInitDetect() { function systemInitInstall() { local service_name="$1" local user="$2" + # shellcheck disable=SC2034 local source_base_path="" local source_path="" local target_path="" @@ -198,26 +198,26 @@ function systemInitInstall() { libretime-analyzer) source_path="${python_source_path}/airtime_analyzer/install/systemd/${service_name}.service" target_path="/etc/systemd/system/${service_name}.service" - alt_path=$(echo $target_path | sed 's/libretime-/airtime_/') + alt_path="${target_path//libretime-/airtime_}" ;; libretime-celery) source_path="${python_source_path}/airtime-celery/install/systemd/${service_name}.service" target_path="/etc/systemd/system/${service_name}.service" - alt_path=$(echo $target_path | sed 's/libretime-/airtime-/') + alt_path="${target_path//libretime-/airtime-}" ;; libretime-liquidsoap | libretime-playout) source_path="${python_source_path}/pypo/install/systemd/${service_name}.service" target_path="/etc/systemd/system/${service_name}.service" - alt_path=$(echo $target_path | sed 's/libretime-/airtime-/') + alt_path="${target_path//libretime-/airtime-}" ;; libretime-api) source_path="${SCRIPT_DIR-$PWD}/api/install/systemd/${service_name}.service" target_path="/etc/systemd/system/${service_name}.service" - alt_path=$(echo $target_path | sed 's/libretime-/airtime-/') + alt_path="${target_path//libretime-/airtime-}" ;; esac if [[ ! -e $source_path ]]; then - echo "$0:${FUNCNAME}(): ERROR: service \"$service_name\" with source path \"$source_path\" does not exist!" >&2 + echo "$0:${FUNCNAME[0]}(): ERROR: service \"$service_name\" with source path \"$source_path\" does not exist!" >&2 exit 1 fi # Stop and disable the service if it already exists @@ -229,7 +229,8 @@ function systemInitInstall() { local old_style_unit_exists="f" # Migrate old style airtime unit exist if it exists if [[ -e $alt_path && ! -L $alt_path ]]; then - local old_service=$(echo $service_name | sed 's/libretime/airtime/' | sed 's/-analyzer/_analyzer/') + local old_service + old_service=$(echo "$service_name" | sed 's/libretime/airtime/' | sed 's/-analyzer/_analyzer/') verbose "Old service $old_service already exists - migrating." loudCmd "systemctl disable ${old_service}.service" loudCmd "systemctl stop ${old_service}.service" @@ -241,15 +242,15 @@ function systemInitInstall() { loudCmd "cp $source_path $target_path" else sed -e "s/User=.*/User=${user}/" \ - -e "s/Group=.*/Group=${user}/" $source_path > $target_path + -e "s/Group=.*/Group=${user}/" "$source_path" > "$target_path" fi if [[ $old_style_unit_exists == "t" ]]; then verbose "Maintaining compatibility with old systemd unit names" # Alias to old Airtime names loudCmd "ln -s $source_path $alt_path" fi - chmod 0644 $target_path - chown root:root $target_path + chmod 0644 "$target_path" + chown root:root "$target_path" verbose "Service ${service_name} installed into ${target_path}" # Enable and start the service loudCmd "systemctl enable ${service_name}.service" @@ -273,7 +274,7 @@ function systemInitInstall() { ;; esac if [[ ! -e $source_path ]]; then - echo "$0:${FUNCNAME}(): ERROR: service \"$service_name\" with source path \"$source_path\" does not exist!" >&2 + echo "$0:${FUNCNAME[0]}(): ERROR: service \"$service_name\" with source path \"$source_path\" does not exist!" >&2 exit 1 fi # Stop the service if it already exists @@ -286,10 +287,10 @@ function systemInitInstall() { loudCmd "cp $source_path $target_path" else sed -e "s/WEB_USER/${user}/g" \ - -e "/^set[gu]id/{s/www-data/${user}/}" $source_path > $target_path + -e "/^set[gu]id/{s/www-data/${user}/}" "$source_path" > "$target_path" fi - chmod 0644 $target_path - chown root:root $target_path + chmod 0644 "$target_path" + chown root:root "$target_path" verbose "Service ${service_name} installed into ${target_path}" loudCmd "initctl check-config $service_name" elif $has_systemv_init; then @@ -313,7 +314,7 @@ function systemInitInstall() { ;; esac if [[ ! -e $source_path ]]; then - echo "$0:${FUNCNAME}(): ERROR: service \"$service_name\" with source path \"$source_path\" does not exist!" >&2 + echo "$0:${FUNCNAME[0]}(): ERROR: service \"$service_name\" with source path \"$source_path\" does not exist!" >&2 exit 1 fi # Stop the service if it already exists @@ -328,13 +329,13 @@ function systemInitInstall() { loudCmd "cp $source_config_path $target_config_path" else sed -e "/^USERID/{s/www-data/${user}/}" \ - -e "/^GROUPID/{s/www-data/${user}/}" $source_path > $target_path + -e "/^GROUPID/{s/www-data/${user}/}" "$source_path" > "$target_path" fi - chmod 0644 $target_path - chown root:root $target_path + chmod 0644 "$target_path" + chown root:root "$target_path" if [[ -n $target_config_path ]]; then - chmod 0644 $target_config_path - chown root:root $target_config_path + chmod 0644 "$target_config_path" + chown root:root "$target_config_path" fi verbose "Service ${service_name} installed into ${target_path}" # Create symlinks for the appropriate runlevels @@ -356,13 +357,13 @@ function systemInitCommand() { case "$command" in start | stop | status | reload | restart) if $has_systemd_init; then - loudCmd "systemctl $command $@" + loudCmd "systemctl $command $*" elif $has_upstart_init; then - for svc_name in $@; do + for svc_name in "$@"; do loudCmd "service $svc_name $command" done elif $has_systemv_init; then - for svc_name in $@; do + for svc_name in "$@"; do loudCmd "invoke-rc.d $svc_name $command" done fi @@ -371,7 +372,7 @@ function systemInitCommand() { $has_systemd_init && loudCmd "systemctl $command $1.service" if $has_systemv_init; then - if [[ "$command" = "enable" ]]; then + if [[ "$command" == "enable" ]]; then loudCmd "update-rc.d $1 defaults" else loudCmd "update-rc.d $1 enable" @@ -385,7 +386,7 @@ function systemInitCommand() { loudCmd "initctl reload-configuration" ;; *) - echo -e "$0:${FUNCNAME}(): ERROR: command \"$command\" is not supported!" >&2 + echo -e "$0:${FUNCNAME[0]}(): ERROR: command \"$command\" is not supported!" >&2 exit 1 ;; esac @@ -477,7 +478,7 @@ while :; do ;; --web-root) if [ "$2" ]; then - web_root=$(readlink -f $2) + web_root=$(readlink -f "$2") shift 2 continue else @@ -568,7 +569,7 @@ while :; do fi ;; *) - echo "$0: error - unrecognized option '${1:$i:1}'" >&2 + echo "$0: error - unrecognized option '${1:i:1}'" >&2 echo "Try 'install --help' for more information." exit 1 ;; @@ -582,7 +583,7 @@ while :; do shift done -if [ -z web_root -a ! -d web_root ]; then +if [[ -z $web_root || ! -d $web_root ]]; then echo "$web_root doesn't exist!" exit 1 fi @@ -596,6 +597,7 @@ echo -e " \/ \/ \/ \/ \/\n" echo -e "Detecting distribution and release ..." if [ -e /etc/os-release ]; then # Access $ID, $VERSION_ID and $PRETTY_NAME + # shellcheck disable=SC1091 source /etc/os-release echo "Detected distribution id: $ID" echo "Detected distribution release id: $VERSION_ID" @@ -605,7 +607,7 @@ else VERSION_ID=unknown PRETTY_NAME="Unknown distribution and release" echo "WARNING: /etc/os-release configuration not found. Unable to detect distribution." >&2 - if [ -z "$dist" -o -z "$code" ]; then + if [[ -z $dist || -z $code ]]; then echo "ERROR: One or both of --distribution and --release options were not specified." >&2 echo "This is an unsupported distribution and/or version!" >&2 exit 1 @@ -646,6 +648,7 @@ is_debian_buster=false is_ubuntu_dist=false is_ubuntu_bionic=false is_centos_dist=false +# shellcheck disable=SC2034 is_centos_7=false is_centos_8=false # Use specified distribution and release or detected otherwise. @@ -685,6 +688,7 @@ case "${dist}-${code}" in raspbian-10 | 10) code="buster" dist="debian" + # shellcheck disable=SC2034 is_debian_dist=true is_debian_buster=true ;; @@ -697,6 +701,7 @@ case "${dist}-${code}" in ;; centos-8) is_centos_dist=true + # shellcheck disable=SC2034 is_centos_8=true ;; *) @@ -926,9 +931,9 @@ fi if [ "$icecast" = "f" -a ${_i} -eq 1 ]; then echo -e "Install default Airtime Icecast configuration? (Y/n): \c" - read IN + read -r IN IN=${IN:-$default_value} - if [ "$IN" = "y" -o "$IN" = "Y" ]; then + if [[ $IN == "y" || $IN == "Y" ]]; then icecast="t" fi fi @@ -947,15 +952,15 @@ if [ "$icecast" = "t" ]; then icecast_unit_name="icecast" icecast_config="/etc/icecast.xml" fi - systemInitCommand enable ${icecast_unit_name} + systemInitCommand enable "${icecast_unit_name}" # only update icecast password if if [ ! -e "/etc/airtime/airtime.conf" ] && [ ! -e "/etc/airtime/airtime.conf.tmp" ]; then - icecast_pass=$(tr -dc _A-Z-a-z-0-9 < /dev/urandom | head -c${1:-12}) - echo $icecast_pass > /tmp/icecast_pass + icecast_pass=$(tr -dc _A-Z-a-z-0-9 < /dev/urandom | head -c"${1:-12}") + echo "$icecast_pass" > /tmp/icecast_pass loud "\n New install detected setting icecast password to random value." - xmlstarlet ed --inplace -u /icecast/authentication/source-password -v $icecast_pass $icecast_config - xmlstarlet ed --inplace -u /icecast/authentication/relay-password -v $icecast_pass $icecast_config - xmlstarlet ed --inplace -u /icecast/authentication/admin-password -v $icecast_pass $icecast_config + xmlstarlet ed --inplace -u /icecast/authentication/source-password -v "$icecast_pass" "$icecast_config" + xmlstarlet ed --inplace -u /icecast/authentication/relay-password -v "$icecast_pass" "$icecast_config" + xmlstarlet ed --inplace -u /icecast/authentication/admin-password -v "$icecast_pass" "$icecast_config" fi # restart in case icecast was already started (like is the case on debian) systemInitCommand restart ${icecast_unit_name} @@ -979,7 +984,7 @@ verbose "...Done" verbose "\n * Creating /run/airtime..." mkdir -p /run/airtime chmod 755 /run/airtime -chown -R ${web_user}:${web_user} /run/airtime +chown -R "${web_user}:${web_user}" /run/airtime verbose "...Done" if [ ! -d /var/log/airtime ]; then @@ -1003,8 +1008,8 @@ verbose "\n * Installing pypo and liquidsoap..." loudCmd "$python_bin ${AIRTIMEROOT}/python_apps/pypo/setup.py install --install-scripts=/usr/bin --no-init-script" loudCmd "mkdir -p /var/log/airtime/{pypo,pypo-liquidsoap} /var/tmp/airtime/pypo/{cache,files,tmp} /var/tmp/airtime/show-recorder/" loudCmd "chown -R ${web_user}:${web_user} /var/log/airtime/{pypo,pypo-liquidsoap} /var/tmp/airtime/pypo/{cache,files,tmp} /var/tmp/airtime/show-recorder/" -systemInitInstall libretime-liquidsoap $web_user -systemInitInstall libretime-playout $web_user +systemInitInstall libretime-liquidsoap "$web_user" +systemInitInstall libretime-playout "$web_user" verbose "...Done" verbose "\n * Installing airtime-celery..." @@ -1025,16 +1030,16 @@ verbose "...Done" verbose "\n * Installing libretime-analyzer..." loudCmd "$python_bin ${AIRTIMEROOT}/python_apps/airtime_analyzer/setup.py install --install-scripts=/usr/bin" -systemInitInstall libretime-analyzer $web_user +systemInitInstall libretime-analyzer "$web_user" verbose "...Done" verbose "\n * Installing API..." loudCmd "python3 ${AIRTIMEROOT}/api/setup.py install --install-scripts=/usr/bin" -systemInitInstall libretime-api $web_user +systemInitInstall libretime-api "$web_user" mkdir -p /etc/airtime sed -e "s@WEB_USER@${web_user}@g" \ -e "s@WEB_ROOT@${web_root}@g" \ - ${AIRTIMEROOT}/installer/uwsgi/libretime-api.ini > /etc/airtime/libretime-api.ini + "${AIRTIMEROOT}/installer/uwsgi/libretime-api.ini" > /etc/airtime/libretime-api.ini loudCmd "libretime-api collectstatic --clear --noinput" verbose "...Done" @@ -1058,7 +1063,7 @@ php_conf_dirs=( "/etc/php5/apache2/conf.d" # Debian Stretch, Debian Jessie, Ubuntu Trusty "/etc/php.d" # CentOS 7 ) -for php_conf in ${php_conf_dirs[@]}; do +for php_conf in "${php_conf_dirs[@]}"; do [[ -d $php_conf ]] && break done if [[ -d $php_conf ]]; then diff --git a/installer/lxc-bootstrap b/installer/lxc-bootstrap index 79eb227e3..6ecb1423a 100755 --- a/installer/lxc-bootstrap +++ b/installer/lxc-bootstrap @@ -1,4 +1,6 @@ -#!/usr/bin/env bash -e +#!/usr/bin/env bash + +set -e #-e Causes bash script to exit if any of the installers #return with a non-zero return value. diff --git a/jekyll.sh b/jekyll.sh old mode 100644 new mode 100755 index aa8af1ab0..48fc0cab8 --- a/jekyll.sh +++ b/jekyll.sh @@ -1,4 +1,4 @@ -#/bin/bash +#!/usr/bin/env bash echo "Installing Ruby" apt-get update -y && apt-get install -y ruby-full build-essential zlib1g-dev @@ -8,7 +8,7 @@ export PATH=".gems/bin:$PATH" echo "Installing Jekyll" -cd docs +cd docs || (echo "Could not cd in docs" && exit 1) gem install jekyll bundler # Running Jekyll diff --git a/python_apps/airtime_analyzer/tools/ftp-upload-hook.sh b/python_apps/airtime_analyzer/tools/ftp-upload-hook.sh index 01fe1b148..90cb85a1e 100755 --- a/python_apps/airtime_analyzer/tools/ftp-upload-hook.sh +++ b/python_apps/airtime_analyzer/tools/ftp-upload-hook.sh @@ -1,4 +1,6 @@ -#!/usr/bin/env bash -xv +#!/usr/bin/env bash + +set -xv post_file() { #kill process after 30 minutes (360*5=30 minutes) @@ -35,7 +37,7 @@ post_file() { # -f is needed to make curl fail if there's an HTTP error code # -L is needed to follow redirects! (just in case) until curl -fL --max-time 30 $url -u $api_key":" -X POST -F "file=@${file_path}"; do - retry_count=$(($retry_count + 1)) + retry_count=$((retry_count + 1)) if [ $retry_count -ge $max_retry ]; then break fi diff --git a/python_apps/airtime_analyzer/tools/test-hook-script.sh b/python_apps/airtime_analyzer/tools/test-hook-script.sh index fcb925a8b..001d3fea6 100755 --- a/python_apps/airtime_analyzer/tools/test-hook-script.sh +++ b/python_apps/airtime_analyzer/tools/test-hook-script.sh @@ -9,7 +9,7 @@ post_file() { retry_count=0 until curl --max-time 30 http://localhost/rest/media -u 3188BDIMPJROQP89Z0OX: -X POST -F "file=@${file_path}" -F "name=${filename}"; do - retry_count=$(($retry_count + 1)) + retry_count=$((retry_count + 1)) if [ $retry_count -ge $max_retry ]; then break fi diff --git a/uninstall b/uninstall index 4d48a89ec..1ef277f46 100755 --- a/uninstall +++ b/uninstall @@ -1,6 +1,6 @@ -#!/usr/bin/env bash -e -# -e Causes bash script to exit if any of the steps -# return with a non-zero return value. +#!/usr/bin/env bash + +set -e # Exit if any of the steps fails. if [[ $EUID -ne 0 ]]; then echo "Please run as root user." @@ -8,20 +8,13 @@ if [[ $EUID -ne 0 ]]; then fi getStorDirFromDatabase() { - echo $(sudo -u postgres psql -d airtime -tAc "SELECT directory FROM cc_music_dirs WHERE type='stor'") + sudo -u postgres psql -d airtime -tAc "SELECT directory FROM cc_music_dirs WHERE type='stor'" } dropLibreTimeDatabase() { - # here-doc to execute this block as postgres user - su postgres << 'EOF' -set +e -# DROP DATABASE cannot be executed from a function or multi-command string -psql -d postgres -tAc "DROP DATABASE IF EXISTS airtime_test" -psql -d postgres -tAc "DROP DATABASE IF EXISTS airtime" -psql -d postgres -tAc "DROP USER IF EXISTS airtime" -set -e -# don't indent this! -EOF + sudo -u postgres psql -d postgres -tAc "DROP DATABASE IF EXISTS airtime_test" + sudo -u postgres psql -d postgres -tAc "DROP DATABASE IF EXISTS airtime" + sudo -u postgres psql -d postgres -tAc "DROP USER IF EXISTS airtime" } removeRabbitmqLibreTimeSettings() { @@ -37,9 +30,6 @@ removeRabbitmqLibreTimeSettings() { rabbitmqctl delete_user ${RMQ_USER} } -SCRIPT_DIR="$( cd "$( dirname "$0")" && pwd)" -AIRTIMEROOT=${SCRIPT_DIR} - STOR_DIR=$(getStorDirFromDatabase) FILES=( @@ -57,7 +47,7 @@ FILES=( echo -e "The following files, directories, and services will be removed:\n" for i in ${FILES[*]}; do - echo $i + echo "$i" done echo "pip3 airtime-playout" @@ -65,15 +55,15 @@ echo -e "\nIf your web root is not listed, you will need to manually remove it." echo -e "\nThis will *permanently* remove LibreTime and all related files from your computer. \ Any files in LibreTime directories and subdirectories will be deleted. Are you sure you want to proceed? [y/N]: \c" -read IN -if [[ ! ("$IN" = "y" || "$IN" = "Y") ]]; then +read -r IN +if [[ ! ($IN == "y" || $IN == "Y") ]]; then exit 0 fi if [ -n "${STOR_DIR}" ]; then echo -e "\nDo you want to remove your music storage directory ${STOR_DIR} and all of its subdirectories? [y/N]: \c" - read IN - if [[ ("$IN" = "y" || "$IN" = "Y") ]]; then + read -r IN + if [[ $IN == "y" || $IN == "Y" ]]; then rm -rf "${STOR_DIR}" fi else @@ -87,12 +77,12 @@ removeRabbitmqLibreTimeSettings set -e for i in ${FILES[*]}; do - rm -rf $i + rm -rf "$i" done echo -e "\nDo you want to drop your current LibreTime database? [y/N]: \c" -read IN -if [[ "$IN" = "y" || "$IN" = "Y" ]]; then +read -r IN +if [[ $IN == "y" || $IN == "Y" ]]; then echo -e "\nDropping LibreTime database..." dropLibreTimeDatabase fi From 9881eebf55b457964c23e389d3c9af519f09af3c Mon Sep 17 00:00:00 2001 From: jo Date: Mon, 16 Aug 2021 23:00:01 +0200 Subject: [PATCH 7/8] Fix shellcheck warnings --- .github/scripts/release.sh | 6 +-- airtime_mvc/tests/runtests.sh | 2 +- .../liquidsoap_compile/liquidsoap-compile.sh | 18 ++++----- dev_tools/propel_regenerate.sh | 8 ++-- dev_tools/release/release.sh | 6 +-- dev_tools/scripts/git-merge-po | 3 +- dev_tools/update_po_files.sh | 4 +- install | 34 ++++++++-------- .../install/initd/libretime-celery | 39 ++++++++++++------- .../install/sysvinit/libretime-analyzer | 1 + .../airtime_analyzer/tools/ftp-upload-hook.sh | 2 +- .../install/sysvinit/libretime-liquidsoap | 1 + .../pypo/install/sysvinit/libretime-playout | 1 + utils/airtime-test-soundcard | 2 +- utils/airtime-test-stream | 2 +- utils/libretime-backup.sh | 30 +++++++------- utils/rivendell-converter.sh | 6 +-- 17 files changed, 90 insertions(+), 75 deletions(-) diff --git a/.github/scripts/release.sh b/.github/scripts/release.sh index a09c1e42c..5dc03e557 100755 --- a/.github/scripts/release.sh +++ b/.github/scripts/release.sh @@ -17,10 +17,8 @@ if [ $# == 0 ]; then exit 1 elif [ $# == 1 ]; then suffix=$1 - version=$1 else suffix=$1-$2 - version=$1 fi echo "Creating tarball for LibreTime ${suffix}." @@ -41,9 +39,9 @@ echo " Done" #echo "Done" cd .. -find libretime-${suffix} -type f -exec dos2unix {} \; +find "libretime-${suffix}" -type f -exec dos2unix {} \; echo -n "Creating tarball..." -tar -czf libretime-${suffix}.tar.gz \ +tar -czf "libretime-${suffix}.tar.gz" \ --owner=root --group=root \ --exclude-vcs \ --exclude .zfproject.xml \ diff --git a/airtime_mvc/tests/runtests.sh b/airtime_mvc/tests/runtests.sh index 7213ecadb..ed9ca7624 100755 --- a/airtime_mvc/tests/runtests.sh +++ b/airtime_mvc/tests/runtests.sh @@ -30,7 +30,7 @@ export AIRTIME_UNIT_TEST="1" #Change the working directory to this script's directory DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" && pwd)" -cd $DIR +cd "$DIR" || (echo "could not cd in $DIR!" && exit 1) #Run the unit tests phpunit --verbose --log-junit test_results.xml diff --git a/dev_tools/liquidsoap_compile/liquidsoap-compile.sh b/dev_tools/liquidsoap_compile/liquidsoap-compile.sh index 211dd7fd3..f59a52e69 100755 --- a/dev_tools/liquidsoap_compile/liquidsoap-compile.sh +++ b/dev_tools/liquidsoap_compile/liquidsoap-compile.sh @@ -5,8 +5,8 @@ set -e apt-get install -y --force-yes lsb-release sudo dist=$(lsb_release -is) code=$(lsb_release -cs) -cpu=$(getconf LONG_BIT) -cpuvalue= +# cpu=$(getconf LONG_BIT) +# cpuvalue= #enable apt.sourcefabric.org source set +e @@ -32,7 +32,7 @@ if [ "$dist" = "Ubuntu" ]; then fi #enable squeeze backports to get lame packages -if [ "$dist" = "Debian" -a "$code" = "squeeze" ]; then +if [[ "$dist" == "Debian" && "$code" == "squeeze" ]]; then set +e grep -E "deb http://backports.debian.org/debian-backports squeeze-backports main" /etc/apt/sources.list returncode=$? @@ -42,12 +42,12 @@ if [ "$dist" = "Debian" -a "$code" = "squeeze" ]; then fi fi -echo "System is $cpu bit..." -if [ "$cpu" = "64" ]; then - cpuvalue="amd64" -else - cpuvalue="i386" -fi +# echo "System is $cpu bit..." +# if [ "$cpu" = "64" ]; then +# cpuvalue="amd64" +# else +# cpuvalue="i386" +# fi apt-get update apt-get -o Dpkg::Options::="--force-confold" upgrade diff --git a/dev_tools/propel_regenerate.sh b/dev_tools/propel_regenerate.sh index bd2aac7eb..31dfd01c1 100755 --- a/dev_tools/propel_regenerate.sh +++ b/dev_tools/propel_regenerate.sh @@ -3,12 +3,12 @@ set -e # Absolute path to this script -SCRIPT=$(readlink -f $0) +SCRIPT=$(readlink -f "$0") # Absolute directory this script is in -SCRIPTPATH=$(dirname $SCRIPT) +SCRIPTPATH=$(dirname "$SCRIPT") -cd $SCRIPTPATH/../airtime_mvc/ +cd "$SCRIPTPATH/../airtime_mvc/" || (echo "could not cd in $SCRIPTPATH/../airtime_mvc/" && exit 1) path=$(pwd) cd build -sed -i s:"project\.home =.*$":"project.home = $path":g build.properties +sed -i "s|\"project\.home =.*$\"|\"project.home = $path\"|g" build.properties ../../vendor/propel/propel1/generator/bin/propel-gen diff --git a/dev_tools/release/release.sh b/dev_tools/release/release.sh index c50f3fa3d..4fac2376a 100755 --- a/dev_tools/release/release.sh +++ b/dev_tools/release/release.sh @@ -19,13 +19,13 @@ if [ $# == 0 ]; then exit elif [ $# == 1 ]; then suffix=$1 - version=$1 + # version=$1 else suffix=$1-$2 - version=$1 + # version=$1 fi -dir=$(dirname $(readlink -f $0)) +# dir=$(dirname "$(readlink -f "$0")") gitrepo=$(readlink -f ./../../) echo "Creating tarball for LibreTime ${suffix}." diff --git a/dev_tools/scripts/git-merge-po b/dev_tools/scripts/git-merge-po index e717fc75d..ac91091bb 100755 --- a/dev_tools/scripts/git-merge-po +++ b/dev_tools/scripts/git-merge-po @@ -22,7 +22,8 @@ # # - When merging branches, conflicts in PO files will be marked with "#-#-#-#" # -O=$1 + +# O=$1 A=$2 B=$3 diff --git a/dev_tools/update_po_files.sh b/dev_tools/update_po_files.sh index ee9626aae..ecdb86177 100755 --- a/dev_tools/update_po_files.sh +++ b/dev_tools/update_po_files.sh @@ -4,8 +4,8 @@ cd .. #generate a new .po file #this will generate a file called messages.po -find airtime_mvc -iname "*.phtml" -o -name "*.php" | xargs xgettext -L php --from-code=UTF-8 -find airtime_mvc -iname "*.phtml" -o -name "*.php" | xargs xgettext -L php --from-code=UTF-8 -k --keyword=_pro:1 -d pro --force-po +find airtime_mvc -print0 -iname "*.phtml" -o -name "*.php" | xargs xgettext -L php --from-code=UTF-8 +find airtime_mvc -print0 -iname "*.phtml" -o -name "*.php" | xargs xgettext -L php --from-code=UTF-8 -k --keyword=_pro:1 -d pro --force-po #merge the new messages from messages.po into each existing .po file #this will generate new .po files diff --git a/install b/install index ca90bc661..f7922f9da 100755 --- a/install +++ b/install @@ -678,14 +678,14 @@ case "${dist}-${code}" in is_debian_buster=true ;; #Fix for Raspbian 9 (stretch) - raspbian-9 | 9) + raspbian-9) echo -e "ERROR: Raspbian Stretch is archived and does not receive any security or other updates since 2020-06-06." >&2 echo -e "The LibreTime installer dropped support for installing LibreTime on Stretch in 3.0.0-alpha.10." >&2 exit 1 ;; #End of fix #Fix for Raspbian 10 (buster) - raspbian-10 | 10) + raspbian-10) code="buster" dist="debian" # shellcheck disable=SC2034 @@ -811,8 +811,8 @@ will be moved to /etc/airtime/airtime.conf.tmp" rm -f /etc/apache2/sites-available/airtime.conf /etc/apache2/sites-enabled/airtime.conf fi - if [ -d /usr/share/airtime -a web_root = /usr/share/airtime ]; then - rm -rf /usr/share/airtime + if [[ -d "/usr/share/airtime" && $web_root == "/usr/share/airtime" ]]; then + rm -rf "/usr/share/airtime" fi mv /etc/airtime/airtime.conf /etc/airtime/airtime.conf.tmp @@ -821,17 +821,17 @@ will be moved to /etc/airtime/airtime.conf.tmp" fi API2_APACHE_CONF=$(grep -F "ProxyPass" /etc/apache2/sites-available/airtime.conf || true) -if [ -z "${API2_APACHE_CONF}" -a "$apache" = "t" ]; then +if [[ -z "${API2_APACHE_CONF}" && "$apache" == "t" ]]; then # Remove Apache configuration so that the ProxyPass configuration for API 2.0 # is installed rm -f /etc/apache2/sites-available/airtime.conf /etc/apache2/sites-enabled/airtime.conf fi -if [ "$apache" = "f" -a ${_i} -eq 1 ]; then +if [[ "$apache" = "f" && ${_i} -eq 1 ]]; then echo -e "Install default Airtime apache configuration? (Y/n): \c" read IN IN=${IN:-$default_value} - if [ "$IN" = "y" -o "$IN" = "Y" ]; then + if [[ "$IN" = "y" || "$IN" = "Y" ]]; then apache="t" fi fi @@ -861,7 +861,7 @@ if [ "$apache" = "t" ]; then loud " * Configuring Apache * " loud "-----------------------------------------------------" # Detect Apache root folder, e.g. /etc/apache2 or /etc/httpd - eval $($apache_bin -V | awk '/HTTPD_ROOT|SERVER_CONFIG_FILE/ { print $2 }') + eval "$($apache_bin -V | awk '/HTTPD_ROOT|SERVER_CONFIG_FILE/ { print $2 }')" apache_conf="${HTTPD_ROOT}/${SERVER_CONFIG_FILE}" verbose "Detected Apache root folder is: ${HTTPD_ROOT}" if [[ ! -e $apache_conf ]]; then @@ -896,7 +896,7 @@ if [ "$apache" = "t" ]; then # install apache, we should overwrite any existing configuration. If we don't do this, doing # an in-place installation over an old Airtime install (which installs to /usr/share by default) # will fail - if [ "$upgrade" = "t" -o ! -f ${apache_sitedir}${airtimeconfigfile} ]; then + if [[ "$upgrade" == "t" || ! -f "${apache_sitedir}${airtimeconfigfile}" ]]; then verbose "\n * Creating Apache config for Airtime..." listen_port="" if [ "$web_port" != "80" ]; then @@ -929,7 +929,7 @@ if [ "$apache" = "t" ]; then fi fi -if [ "$icecast" = "f" -a ${_i} -eq 1 ]; then +if [[ "$icecast" == "f" && ${_i} -eq 1 ]]; then echo -e "Install default Airtime Icecast configuration? (Y/n): \c" read -r IN IN=${IN:-$default_value} @@ -1123,7 +1123,7 @@ EOF echo -e "Create default airtime postgres user? (Y/n): \c" read IN IN=${IN:-$default_value} - if [ "$IN" = "y" -o "$IN" = "Y" ]; then + if [[ "$IN" = "y" || "$IN" = "Y" ]]; then setupAirtimePostgresUser fi fi @@ -1138,7 +1138,7 @@ if [ $skip_rabbitmq -eq 0 ]; then RABBITMQ_VHOST=/airtime RABBITMQ_USER=airtime RABBITMQ_PASSWORD=airtime - EXCHANGES="airtime-pypo|pypo-fetch|airtime-analyzer|media-monitor" + # EXCHANGES="airtime-pypo|pypo-fetch|airtime-analyzer|media-monitor" # Ignore errors in this check to avoid dying when vhost isn't found set +e @@ -1197,14 +1197,14 @@ if [ "$ignore_dependencies" = "f" ]; then else set +e verbose "\n * Generating locales" - for i in $(ls ${web_root}/../locale | grep ".._.."); do + for locale_file in "${web_root}"/../locale/*_*; do + locale=$(basename "$locale_file") if [ "$dist" = "debian" ]; then - grep -qi "^$i" /etc/locale.gen - if [ $? -ne 0 ]; then - verbose "$i.UTF-8 UTF-8" >> /etc/locale.gen + if ! grep -qi "^$locale" /etc/locale.gen; then + verbose "$locale.UTF-8 UTF-8" >> /etc/locale.gen fi else - loudCmd "locale-gen \"$i.utf8\"" + loudCmd "locale-gen \"$locale.utf8\"" fi done set -e diff --git a/python_apps/airtime-celery/install/initd/libretime-celery b/python_apps/airtime-celery/install/initd/libretime-celery index 5f2969cde..6028a1aeb 100755 --- a/python_apps/airtime-celery/install/initd/libretime-celery +++ b/python_apps/airtime-celery/install/initd/libretime-celery @@ -1,4 +1,7 @@ -#!/bin/sh -e +#!/usr/bin/env bash + +set -e + # ============================================ # celeryd - Starts the Celery worker daemon. # ============================================ @@ -29,7 +32,7 @@ # VERSION=10.1 echo "celery init v${VERSION}." -if [ $(id -u) -ne 0 ]; then +if [ "$(id -u)" -ne 0 ]; then echo "Error: This program can only be used by the root user." echo " Unprivileged users must use the 'celery multi' utility, " echo " or 'celery worker --detach'." @@ -51,15 +54,19 @@ DEFAULT_PID_FILE="/var/run/celery/%n.pid" DEFAULT_LOG_FILE="/var/log/celery/%n.log" DEFAULT_LOG_LEVEL="INFO" DEFAULT_NODES="celery" -DEFAULT_CELERYD="-m celery worker --detach" +# DEFAULT_CELERYD="-m celery worker --detach" CELERY_DEFAULTS=${CELERY_DEFAULTS:-"/etc/default/${SCRIPT_NAME}"} # Make sure executable configuration script is owned by root _config_sanity() { - local path="$1" - local owner=$(ls -ld "$path" | awk '{print $3}') - local iwgrp=$(ls -ld "$path" | cut -b 6) - local iwoth=$(ls -ld "$path" | cut -b 9) + local path + local owner + local iwgrp + local iwoth + path="$1" + owner=$(ls -ld "$path" | awk '{print $3}') + iwgrp=$(ls -ld "$path" | cut -b 6) + iwoth=$(ls -ld "$path" | cut -b 9) if [ "$(id -u $owner)" != "0" ]; then echo "Error: Config script '$path' must be owned by root!" echo @@ -97,6 +104,7 @@ _config_sanity() { if [ -f "$CELERY_DEFAULTS" ]; then _config_sanity "$CELERY_DEFAULTS" echo "Using config script: $CELERY_DEFAULTS" + # shellcheck disable=SC1090 . "$CELERY_DEFAULTS" fi # Sets --app argument for CELERY_BIN @@ -184,8 +192,10 @@ _get_pids() { found_pids=0 my_exitcode=0 for pidfile in $(_get_pidfiles); do - local pid=$(cat "$pidfile") - local cleaned_pid=$(echo "$pid" | sed -e 's/[^0-9]//g') + local pid + local cleaned_pid + pid=$(cat "$pidfile") + cleaned_pid=$(echo "$pid" | sed -e 's/[^0-9]//g') if [ -z "$pid" ] || [ "$cleaned_pid" != "$pid" ]; then echo "bad pid file ($pidfile)" one_failed=true @@ -207,7 +217,7 @@ start_workers() { if [ ! -z "$CELERYD_ULIMIT" ]; then ulimit $CELERYD_ULIMIT fi - _chuid $* start $CELERYD_NODES $DAEMON_OPTS \ + _chuid "$@" start $CELERYD_NODES $DAEMON_OPTS \ --pidfile="$CELERYD_PID_FILE" \ --logfile="$CELERYD_LOG_FILE" \ --loglevel="$CELERYD_LOG_LEVEL" \ @@ -259,9 +269,12 @@ check_status() { one_failed=true break fi - local node=$(basename "$pidfile" .pid) - local pid=$(cat "$pidfile") - local cleaned_pid=$(echo "$pid" | sed -e 's/[^0-9]//g') + local node + local pid + local cleaned_pid + node=$(basename "$pidfile" .pid) + pid=$(cat "$pidfile") + cleaned_pid=$(echo "$pid" | sed -e 's/[^0-9]//g') if [ -z "$pid" ] || [ "$cleaned_pid" != "$pid" ]; then echo "bad pid file ($pidfile)" one_failed=true diff --git a/python_apps/airtime_analyzer/install/sysvinit/libretime-analyzer b/python_apps/airtime_analyzer/install/sysvinit/libretime-analyzer index 31da8d5f7..c88be1ea8 100755 --- a/python_apps/airtime_analyzer/install/sysvinit/libretime-analyzer +++ b/python_apps/airtime_analyzer/install/sysvinit/libretime-analyzer @@ -20,6 +20,7 @@ PIDFILE=/var/run/$NAME.pid [ -x "$DAEMON" ] || exit 0 # Read configuration variable file if it is present +# shellcheck disable=SC1090 [ -r /etc/default/$NAME ] && . /etc/default/$NAME # Load the VERBOSE setting and other rcS variables diff --git a/python_apps/airtime_analyzer/tools/ftp-upload-hook.sh b/python_apps/airtime_analyzer/tools/ftp-upload-hook.sh index 90cb85a1e..82b02b118 100755 --- a/python_apps/airtime_analyzer/tools/ftp-upload-hook.sh +++ b/python_apps/airtime_analyzer/tools/ftp-upload-hook.sh @@ -17,7 +17,7 @@ post_file() { stripped_file_path=${file_path//','/''} mv "${file_path}" "${stripped_file_path}" file_path="${stripped_file_path}" - filename="${file_path##*/}" + # filename="${file_path##*/}" airtime_conf_path=/etc/airtime/airtime.conf diff --git a/python_apps/pypo/install/sysvinit/libretime-liquidsoap b/python_apps/pypo/install/sysvinit/libretime-liquidsoap index c90142c3a..35b2cd020 100755 --- a/python_apps/pypo/install/sysvinit/libretime-liquidsoap +++ b/python_apps/pypo/install/sysvinit/libretime-liquidsoap @@ -20,6 +20,7 @@ PIDFILE=/var/run/$NAME.pid [ -x "$DAEMON" ] || exit 0 # Read configuration variable file if it is present +# shellcheck disable=SC1090 [ -r /etc/default/$NAME ] && . /etc/default/$NAME # Load the VERBOSE setting and other rcS variables diff --git a/python_apps/pypo/install/sysvinit/libretime-playout b/python_apps/pypo/install/sysvinit/libretime-playout index 7a0b121ed..0183336ac 100755 --- a/python_apps/pypo/install/sysvinit/libretime-playout +++ b/python_apps/pypo/install/sysvinit/libretime-playout @@ -20,6 +20,7 @@ PIDFILE=/var/run/$NAME.pid [ -x "$DAEMON" ] || exit 0 # Read configuration variable file if it is present +# shellcheck disable=SC1090 [ -r /etc/default/$NAME ] && . /etc/default/$NAME # Load the VERBOSE setting and other rcS variables diff --git a/utils/airtime-test-soundcard b/utils/airtime-test-soundcard index 67722cdf2..f852267a7 100755 --- a/utils/airtime-test-soundcard +++ b/utils/airtime-test-soundcard @@ -28,6 +28,6 @@ SCRIPT=$(readlink -f $0) # Absolute directory this script is in SCRIPTPATH=$(dirname $SCRIPT) -cd $SCRIPTPATH +cd $SCRIPTPATH || exit 1 python airtime-test-soundcard.py "$@" || exit 1 diff --git a/utils/airtime-test-stream b/utils/airtime-test-stream index 8634b2dc2..1ebc328dc 100755 --- a/utils/airtime-test-stream +++ b/utils/airtime-test-stream @@ -28,6 +28,6 @@ SCRIPT=$(readlink -f $0) # Absolute directory this script is in SCRIPTPATH=$(dirname $SCRIPT) -cd $SCRIPTPATH +cd $SCRIPTPATH || exit 1 python airtime-test-stream.py "$@" || exit 1 diff --git a/utils/libretime-backup.sh b/utils/libretime-backup.sh index 03f7602c1..529cc64dd 100755 --- a/utils/libretime-backup.sh +++ b/utils/libretime-backup.sh @@ -11,34 +11,34 @@ fi airtime_conf_path=/etc/airtime/airtime.conf uploads_folder=/srv/airtime/stor/ -psdl_db=$(grep dbname ${airtime_conf_path} | awk '{print $3;}') +psql_db=$(grep dbname ${airtime_conf_path} | awk '{print $3;}') psql_user=$(grep dbuser ${airtime_conf_path} | awk '{print $3;}') psql_password=$(grep dbpass ${airtime_conf_path} | awk '{print $3;}') ## Remove old backup -rm -rf $backup_folder -mkdir $backup_folder +rm -rf "$backup_folder" +mkdir "$backup_folder" ## Backup of database -echo 'db: Getting database...' -pg_dump --dbname='postgresql://'$psql_user':'$psql_password'@localhost/'$psql_db > $backup_folder'database' -echo 'db: Complete' +echo "db: Getting database..." +pg_dump --dbname="postgresql://$psql_user:$psql_password@localhost/$psql_db" > "${backup_folder}database" +echo "db: Complete" ## Backup of sounds -mkdir $backup_folder'uploads/' +mkdir "${backup_folder}uploads/" -echo 'stor : Copying uploaded files...' -rsync -r -a --info=progress2 $uploads_folder $backup_folder'uploads/' -echo 'stor: Complete' +echo "stor : Copying uploaded files..." +rsync -r -a --info=progress2 $uploads_folder "${backup_folder}uploads/" +echo "stor: Complete" ## Backup of libretime config -mkdir $backup_folder'airtime_config/' +mkdir "${backup_folder}airtime_config/" -echo 'config: Copying config...' -rsync -r -a --info=progress2 /etc/airtime/ $backup_folder'airtime_config/' -echo 'config: Complete' +echo "config: Copying config..." +rsync -r -a --info=progress2 /etc/airtime/ "${backup_folder}airtime_config/" +echo "config: Complete" -date >> $backup_folder'datelog.txt' +date >> "${backup_folder}datelog.txt" diff --git a/utils/rivendell-converter.sh b/utils/rivendell-converter.sh index a16b26c2d..38f3d071d 100755 --- a/utils/rivendell-converter.sh +++ b/utils/rivendell-converter.sh @@ -21,17 +21,17 @@ db="Rivendell" #Edit this only if you changed Rivendell's database name :-) rivendell_dir=$1 end_dir=$2 -cd "$rivendell_dir" +cd "$rivendell_dir" || (echo "could not cd in $rivendell_dir" && exit 1) for file in *; do lame "$file" done mv "$rivendell_dir"/*.mp3 "$end_dir" -cd "$end_dir" +cd "$end_dir" || (echo "could not cd in $end_dir" && exit 1) for file in *; do - id=$(echo $file | head -c 10) + id=$(echo "$file" | head -c 10) title=$(mysql -u $user -p$pass -sN -e "SELECT CU.DESCRIPTION FROM CUTS CU, CART CA WHERE CA.NUMBER=CU.CART_NUMBER AND CU.CUT_NAME=\"${id}\"" $db) artist=$(mysql -u $user -p$pass -sN -e "SELECT CA.ARTIST FROM CUTS CU, CART CA WHERE CA.NUMBER=CU.CART_NUMBER AND CU.CUT_NAME=\"${id}\"" $db) album=$(mysql -u $user -p$pass -sN -e "SELECT CA.ALBUM FROM CUTS CU, CART CA WHERE CA.NUMBER=CU.CART_NUMBER AND CU.CUT_NAME=\"${id}\"" $db) From 5ec5ef8a40e368e02861d3c72f02a2ef137bee5a Mon Sep 17 00:00:00 2001 From: jo Date: Tue, 17 Aug 2021 00:00:18 +0200 Subject: [PATCH 8/8] Fix CI python app installation --- .github/scripts/python-pkg-install.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/scripts/python-pkg-install.sh b/.github/scripts/python-pkg-install.sh index e30b8ce84..063b2df46 100755 --- a/.github/scripts/python-pkg-install.sh +++ b/.github/scripts/python-pkg-install.sh @@ -2,9 +2,9 @@ echo "::group::Install Python apps" for app in python_apps/*; do - if [[ -f "python_apps/$app/requirements-dev.txt" ]]; then - pip3 install -r "python_apps/$app/requirements-dev.txt" + if [[ -f "$app/requirements-dev.txt" ]]; then + pip3 install -r "$app/requirements-dev.txt" fi - pip3 install -e "python_apps/$app" + pip3 install -e "$app" done echo "::endgroup::"