Scripts: to compile liquidsoap with chroot env.

This commit is contained in:
cliff.wang 2013-04-29 11:46:38 -04:00
parent 623a67d6aa
commit 2552a52248
2 changed files with 241 additions and 0 deletions

View file

@ -0,0 +1,71 @@
#!/bin/bash -e
apt-get install -y --force-yes lsb-release sudo
dist=`lsb_release -is`
code=`lsb_release -cs`
cpu=`getconf LONG_BIT`
cpuvalue=
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
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
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
apt-get install wget
wget http://apt.sourcefabric.org/misc/libopus_1.0.1/libopus-dbg_1.0.1~$code~sfo-1_$cpuvalue.deb
wget http://apt.sourcefabric.org/misc/libopus_1.0.1/libopus-dev_1.0.1~$code~sfo-1_$cpuvalue.deb
wget http://apt.sourcefabric.org/misc/libopus_1.0.1/libopus0_1.0.1~$code~sfo-1_$cpuvalue.deb
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
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
rm -rf liquidsoap-full
git clone https://github.com/savonet/liquidsoap-full
chmod -R 777 liquidsoap-full
cd liquidsoap-full
sudo -u tmp make init
sudo -u tmp make update
sudo -u tmp cp PACKAGES.minimal PACKAGES
sed -i "s/#ocaml-portaudio/ocaml-portaudio/g" PACKAGES
sed -i "s/#ocaml-alsa/ocaml-alsa/g" PACKAGES
sed -i "s/#ocaml-pulseaudio/ocaml-pulseaudio/g" PACKAGES
sed -i "s/#ocaml-faad/ocaml-faad/g" PACKAGES
sed -i "s/#ocaml-opus/ocaml-opus/g" PACKAGES
#sed -i "s/#ocaml-shine/ocaml-shine/g" PACKAGES
sudo -u tmp ./bootstrap
sudo -u tmp ./configure
sudo -u tmp make
cp /liquidsoap-full/liquidsoap/src/liquidsoap /

View file

@ -0,0 +1,170 @@
#!/bin/bash
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
fi
rm -rf ./liquidsoap_compile_logs
mkdir -p ./liquidsoap_compile_logs
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
}
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}'`
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
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
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 [ $? -ne 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_oneiric_32" "ubuntu_oneiric_64" "ubuntu_precise_32" "ubuntu_precise_64" "ubuntu_quantal_32" "ubuntu_quantal_64" "debian_squeeze_32" "debian_squeeze_64" "debian_wheezy_32" "debian_wheezy_64")
num=${#os_versions[@]}
flag=
os=
sudo_user="-1"
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
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