Format shell scripts

Fix flags order
This commit is contained in:
jo 2021-08-16 13:45:32 +02:00
parent 6c2e547808
commit 8b3e09d41c
24 changed files with 1487 additions and 1499 deletions

View File

@ -34,4 +34,3 @@ cd $DIR
#Run the unit tests
phpunit --verbose --log-junit test_results.xml

View File

@ -8,10 +8,10 @@ if [ -d .git ]; then
fi
if [ "${git_build}" = "y" ]; then
git_version=`git tag --points-at HEAD`
git_version=$(git tag --points-at HEAD)
echo " * Version from tag: ${git_version}"
if [ "${git_version}" = "" ]; then
git_version=`git rev-parse --short HEAD`
git_version=$(git rev-parse --short HEAD)
echo " * Overriding empty version with sha1 commit-ish: ${git_version}"
fi
echo ${git_version} > VERSION

View File

@ -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
@ -17,8 +17,6 @@ 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

View File

@ -29,9 +29,9 @@ build_env () {
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}'`
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
@ -76,7 +76,7 @@ build_env () {
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'`
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/
@ -100,20 +100,17 @@ if [ x$1 = x ];then
showhelp
fi
while getopts b:c:u: arg
do
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
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
@ -122,8 +119,7 @@ do
done
if [ $flag = 1 ]; then
echo "Unsupported Platform from:"
for j in "${os_versions[@]}"
do
for j in "${os_versions[@]}"; do
echo $j
done
exit 1
@ -133,15 +129,13 @@ 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
@ -150,8 +144,7 @@ do
done
if [ $flag = 1 ]; then
echo "Unsupported Platform from:"
for k in "${os_versions[@]}"
do
for k in "${os_versions[@]}"; do
echo $k
done
exit 1

View File

@ -21,5 +21,4 @@ while (( "$#" )); do
shift
done
exit 0

View File

@ -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

View File

@ -78,5 +78,4 @@ tar -czf $target_file \
echo " Done"
popd
echo "Output file available at $target_file"

View File

@ -30,7 +30,6 @@ elif [ "$1" = "--disable" ]; then
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
else

56
install
View File

@ -57,8 +57,7 @@ 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
}
@ -156,10 +155,20 @@ function systemInitDetect() {
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
*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
@ -342,7 +351,8 @@ 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
local command=$1
shift
case "$command" in
start | stop | status | reload | restart)
if $has_systemd_init; then
@ -361,9 +371,10 @@ function systemInitCommand() {
$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"
if [[ "$command" = "enable" ]]; then
loudCmd "update-rc.d $1 defaults"
else
loudCmd "update-rc.d $1 enable"
fi
fi
;;
@ -373,7 +384,8 @@ function systemInitCommand() {
$has_upstart_init &&
loudCmd "initctl reload-configuration"
;;
*) echo -e "$0:${FUNCNAME}(): ERROR: command \"$command\" is not supported!" >&2
*)
echo -e "$0:${FUNCNAME}(): ERROR: command \"$command\" is not supported!" >&2
exit 1
;;
esac
@ -556,14 +568,16 @@ 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
;;
esac
done
;;
*)
break
;;
esac
shift
done
@ -606,9 +620,16 @@ if [ -n "$dist" ]; then
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
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
@ -929,7 +950,7 @@ if [ "$icecast" = "t" ]; then
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};)
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
@ -1158,7 +1179,6 @@ if [ ! -d "/srv/airtime" ]; then
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.
@ -1172,7 +1192,7 @@ if [ "$ignore_dependencies" = "f" ]; then
else
set +e
verbose "\n * Generating locales"
for i in `ls ${web_root}/../locale | grep ".._.."`; do
for i in $(ls ${web_root}/../locale | grep ".._.."); do
if [ "$dist" = "debian" ]; then
grep -qi "^$i" /etc/locale.gen
if [ $? -ne 0 ]; then

View File

@ -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

View File

@ -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
@ -126,8 +125,8 @@ export CELERY_LOADER
if [ -n "$2" ]; then
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"
@ -185,8 +184,8 @@ _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=$(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
@ -236,7 +235,7 @@ 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`
worker_pids=$(_get_pids)
[ "$one_failed" ] && exit 1
for worker_pid in $worker_pids; do
local failed=
@ -260,9 +259,9 @@ 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=$(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

View File

@ -19,7 +19,6 @@ post_file() {
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;}')
@ -31,14 +30,12 @@ post_file() {
url+=$http_port
url+=/rest/media
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]
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

View File

@ -8,9 +8,8 @@ post_file() {
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]
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

View File

@ -8,14 +8,7 @@ if [[ $EUID -ne 0 ]]; then
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() {

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1,7 +1,6 @@
#!/bin/bash
if [ -z "$1" ]
then
if [ -z "$1" ]; then
## Use config
backup_folder=~/libretime_backup/
else
@ -9,7 +8,6 @@ if [ -z "$1" ]
backup_folder=$1
fi
airtime_conf_path=/etc/airtime/airtime.conf
uploads_folder=/srv/airtime/stor/

View File

@ -5,10 +5,10 @@ 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/"`
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`
rabbitmqpid=$(sed "s/.*,\(.*\)\}.*/\1/" /var/lib/rabbitmq/pids)
fi
echo "RabbitMQ PID: $rabbitmqpid"

View File

@ -7,7 +7,6 @@
# 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 <rivendell_dir> <final_dir>"
exit
@ -24,21 +23,19 @@ end_dir=$2
cd "$rivendell_dir"
for file in *
do
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`
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