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

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

View file

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