Fix shellcheck errors
This commit is contained in:
parent
b5f302ac61
commit
dc999f9006
15 changed files with 108 additions and 98 deletions
109
install
109
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue