1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-13 11:51:57 +00:00
srs/trunk/scripts/package.sh

219 lines
7.5 KiB
Bash
Raw Normal View History

2014-03-24 01:03:27 +00:00
#!/bin/bash
2014-03-23 14:52:08 +00:00
2014-03-30 04:31:50 +00:00
echo "通用打包脚本,--help查看参数"
2014-03-24 02:51:37 +00:00
# Usage:
2014-03-30 04:31:50 +00:00
# bash package.sh [--help]
2014-03-24 02:51:37 +00:00
# option arm, whether build for arm, requires ubuntu12.
2014-03-24 01:03:27 +00:00
# user can config the following configs, then package.
2014-03-23 14:52:08 +00:00
INSTALL=/usr/local/srs
2014-03-24 02:51:37 +00:00
# whether build for arm, only for ubuntu12.
help=NO
X86_X64=NO
2014-03-24 02:51:37 +00:00
ARM=NO
2014-04-28 10:48:31 +00:00
PI=NO
2014-05-04 10:38:08 +00:00
MIPS=NO
#
EMBEDED=NO
2020-03-29 06:12:37 +00:00
JOBS=1
2021-12-04 02:43:04 +00:00
#
SRS_TAG=
2014-03-23 14:52:08 +00:00
2014-03-24 01:03:27 +00:00
##################################################################################
##################################################################################
##################################################################################
2014-03-24 02:51:37 +00:00
# parse options.
for option
do
case "$option" in
-*=*)
value=`echo "$option" | sed -e 's|[-_a-zA-Z0-9/]*=||'`
2021-12-04 02:43:04 +00:00
option=`echo "$option" | awk -F '=' '{print $1}'`
;;
*) value="" ;;
esac
case "$option" in
2021-12-04 02:43:04 +00:00
-h) help=yes ;;
--help) help=yes ;;
--x86-x64) X86_X64=YES ;;
2015-09-22 05:52:14 +00:00
--x86-64) X86_X64=YES ;;
2014-05-04 10:38:08 +00:00
--mips) MIPS=YES ;;
--arm) ARM=YES ;;
--pi) PI=YES ;;
2020-03-29 06:12:37 +00:00
--jobs) JOBS=$value ;;
2021-12-04 02:43:04 +00:00
--tag) SRS_TAG=$value ;;
*)
echo "$0: error: invalid option \"$option\", @see $0 --help"
exit 1
;;
esac
done
if [ $help = yes ]; then
cat << END
2021-12-04 02:43:04 +00:00
--help Print this message
2021-12-04 02:43:04 +00:00
--x86-x64 For x86-x64 platform, configure/make/package.
--x86-64 Alias for --x86-x64.
--arm For arm cross-build platform, configure/make/package.
--mips For mips cross-build platform, configure/make/package.
--pi For pi platform, configure/make/package.
2020-03-29 06:12:37 +00:00
--jobs Set the configure and make jobs.
2021-12-04 02:43:04 +00:00
--tag Set the version in zip file.
END
exit 0
fi
2014-03-24 02:51:37 +00:00
2014-05-04 10:38:08 +00:00
# embeded(arm/mips)
if [ $ARM = YES ]; then EMBEDED=YES; fi
if [ $MIPS = YES ]; then EMBEDED=YES; fi
2014-03-23 14:52:08 +00:00
# discover the current work dir, the log and access.
echo "argv[0]=$0"
if [[ ! -f $0 ]]; then
echo "directly execute the scripts on shell.";
work_dir=`pwd`
else
echo "execute scripts in file: $0";
work_dir=`dirname $0`; work_dir=`(cd ${work_dir} && pwd)`
fi
work_dir=`(cd ${work_dir}/.. && pwd)`
product_dir=$work_dir
build_objs=${work_dir}/objs
package_dir=${build_objs}/package
log="${build_objs}/logs/package.`date +%s`.log" && . ${product_dir}/scripts/_log.sh && check_log
ret=$?; if [[ $ret -ne 0 ]]; then exit $ret; fi
# check lsb_release
lsb_release -a >/dev/null 2>&1
ret=$?; if [[ $ret -ne 0 ]]; then
failed_msg "lsb_release not found. "
failed_msg "to install on centos/debian(ubuntu/respberry-pi):";
failed_msg " sudo yum install -y lsb-release";
2019-10-05 12:37:25 +00:00
failed_msg " sudo aptitude install -y lsb-release";
failed_msg "or centos7:"
failed_msg " sudo yum install -y redhat-lsb"
exit $ret;
fi
2014-03-23 14:52:08 +00:00
# check os version
os_name=`lsb_release --id|awk '{print $3}'` &&
os_release=`lsb_release --release|awk '{print $2}'` &&
2014-03-24 01:03:27 +00:00
os_major_version=`echo $os_release|awk -F '.' '{print $1}'` &&
2014-03-30 04:31:50 +00:00
os_machine=`uname -i`
2014-03-23 14:52:08 +00:00
ret=$?; if [[ $ret -ne 0 ]]; then failed_msg "lsb_release get os info failed."; exit $ret; fi
2014-03-24 01:03:27 +00:00
ok_msg "target os is ${os_name}-${os_major_version} ${os_release} ${os_machine}"
2014-03-23 14:52:08 +00:00
2014-03-30 04:31:50 +00:00
# for raspberry-pi
# use rasberry-pi instead all release
if [ $PI = YES ]; then
uname -a|grep "raspberrypi"; if [[ 0 -eq $? ]]; then os_name="RaspberryPi"; fi
if [[ "Raspbian" == $os_name ]]; then os_name="RaspberryPi"; fi
# check the cpu machine
if [[ "unknown" == $os_machine ]]; then os_machine=`uname -m`; fi
fi
ok_msg "real os is ${os_name}-${os_major_version} ${os_release} ${os_machine}"
2014-03-30 04:31:50 +00:00
2014-03-24 01:03:27 +00:00
# build srs
2015-11-11 02:37:50 +00:00
# @see https://github.com/ossrs/srs/wiki/v1_CN_Build
2021-12-04 02:43:04 +00:00
ok_msg "start build srs, ARM: $ARM, MIPS: $MIPS, PI: $PI, X86_64: $X86_X64, JOBS: $JOBS, TAG: $SRS_TAG"
2014-04-28 10:55:19 +00:00
if [ $ARM = YES ]; then
2014-04-28 10:48:31 +00:00
(
cd $work_dir &&
2020-03-29 07:29:07 +00:00
./configure --arm --jobs=$JOBS --prefix=$INSTALL --build-tag=${os_name}${os_major_version} && make
2014-04-28 10:48:31 +00:00
) >> $log 2>&1
2014-05-04 10:38:08 +00:00
elif [ $MIPS = YES ]; then
(
cd $work_dir &&
2020-03-29 07:29:07 +00:00
./configure --mips --jobs=$JOBS --prefix=$INSTALL --build-tag=${os_name}${os_major_version} && make
2014-05-04 10:38:08 +00:00
) >> $log 2>&1
2014-04-28 10:48:31 +00:00
elif [ $PI = YES ]; then
(
cd $work_dir &&
2020-03-29 07:29:07 +00:00
./configure --pi --jobs=$JOBS --prefix=$INSTALL --build-tag=${os_name}${os_major_version} && make
2014-04-28 10:48:31 +00:00
) >> $log 2>&1
elif [ $X86_X64 = YES ]; then
2014-04-28 10:55:19 +00:00
(
cd $work_dir &&
2020-03-29 07:29:07 +00:00
./configure --x86-x64 --jobs=$JOBS --prefix=$INSTALL --build-tag=${os_name}${os_major_version} && make
2014-04-28 10:55:19 +00:00
) >> $log 2>&1
2014-03-24 02:51:37 +00:00
else
2014-05-04 10:38:08 +00:00
failed_msg "invalid option, must be --x86-x64/--arm/--mips/--pi, see --help"; exit 1;
2014-03-24 02:51:37 +00:00
fi
2014-04-28 10:48:31 +00:00
ret=$?; if [[ 0 -ne ${ret} ]]; then failed_msg "build srs failed"; exit $ret; fi
ok_msg "build srs success"
# install srs
ok_msg "start install srs"
(
cd $work_dir && rm -rf $package_dir && make DESTDIR=$package_dir install
) >> $log 2>&1
ret=$?; if [[ 0 -ne ${ret} ]]; then failed_msg "install srs failed"; exit $ret; fi
ok_msg "install srs success"
2014-03-23 14:52:08 +00:00
# copy extra files to package.
ok_msg "start copy extra files to package"
(
cp $work_dir/scripts/install.sh $package_dir/INSTALL &&
sed -i "s|^INSTALL=.*|INSTALL=${INSTALL}|g" $package_dir/INSTALL &&
mkdir -p $package_dir/scripts &&
cp $work_dir/scripts/_log.sh $package_dir/scripts/_log.sh &&
chmod +x $package_dir/INSTALL
) >> $log 2>&1
ret=$?; if [[ 0 -ne ${ret} ]]; then failed_msg "copy extra files failed"; exit $ret; fi
ok_msg "copy extra files success"
2014-03-24 02:51:37 +00:00
# detect for arm.
if [ $ARM = YES ]; then
arm_cpu=`arm-linux-gnueabi-readelf --arch-specific ${build_objs}/srs|grep Tag_CPU_arch:|awk '{print $2}'`
2014-03-24 05:13:52 +00:00
os_machine=arm${arm_cpu}cpu
2014-03-24 02:51:37 +00:00
fi
2014-05-04 10:38:08 +00:00
if [ $MIPS = YES ]; then
os_machine=mips
fi
2014-03-24 05:13:52 +00:00
ok_msg "machine: $os_machine"
2014-03-24 02:51:37 +00:00
2014-03-24 01:03:27 +00:00
# generate zip dir and zip filename
2021-12-04 02:43:04 +00:00
srs_version=$SRS_TAG
if [[ $srs_version == '' ]]; then
if [ $EMBEDED = YES ]; then
srs_version_major=`cat $work_dir/src/core/srs_core.hpp| grep '#define VERSION_MAJOR'| awk '{print $3}'|xargs echo` &&
srs_version_minor=`cat $work_dir/src/core/srs_core.hpp| grep '#define VERSION_MINOR'| awk '{print $3}'|xargs echo` &&
srs_version_revision=`cat $work_dir/src/core/srs_core.hpp| grep '#define VERSION_REVISION'| awk '{print $3}'|xargs echo` &&
srs_version=$srs_version_major.$srs_version_minor.$srs_version_revision
else
srs_version=`${build_objs}/srs -v 2>/dev/stdout 1>/dev/null`
fi
ret=$?; if [[ 0 -ne ${ret} ]]; then failed_msg "get srs version failed"; exit $ret; fi
2014-03-24 05:13:52 +00:00
fi
ok_msg "get srs version $srs_version"
2014-03-24 01:03:27 +00:00
zip_dir="SRS-${os_name}${os_major_version}-${os_machine}-${srs_version}"
ret=$?; if [[ 0 -ne ${ret} ]]; then failed_msg "generate zip filename failed"; exit $ret; fi
2014-03-24 05:13:52 +00:00
ok_msg "target zip filename $zip_dir"
2014-03-24 01:03:27 +00:00
2014-03-23 14:52:08 +00:00
# zip package.
ok_msg "start zip package"
(
mv $package_dir ${build_objs}/${zip_dir} &&
2014-03-24 01:03:27 +00:00
cd ${build_objs} && rm -rf ${zip_dir}.zip && zip -q -r ${zip_dir}.zip ${zip_dir} &&
2014-03-23 14:52:08 +00:00
mv ${build_objs}/${zip_dir} $package_dir
) >> $log 2>&1
ret=$?; if [[ 0 -ne ${ret} ]]; then failed_msg "zip package failed"; exit $ret; fi
ok_msg "zip package success"
ok_msg "srs package success"
2014-03-24 01:03:27 +00:00
echo ""
echo "package: ${build_objs}/${zip_dir}.zip"
echo "install:"
echo " unzip -q ${zip_dir}.zip &&"
echo " cd ${zip_dir} &&"
echo " sudo bash INSTALL"
2014-03-23 14:52:08 +00:00
exit 0