Blame view

trunk/scripts/package.sh 6.7 KB
1
#!/bin/bash
2
winlin authored
3 4
echo "通用打包脚本,--help查看参数"
winlin authored
5
# Usage:
winlin authored
6
#       bash package.sh [--help]
winlin authored
7 8
#           option arm, whether build for arm, requires ubuntu12.
9
# user can config the following configs, then package.
10
INSTALL=/usr/local/srs
winlin authored
11
# whether build for arm, only for ubuntu12.
12
help=NO
13
X86_X64=NO
winlin authored
14
ARM=NO
winlin authored
15
PI=NO
winlin authored
16 17 18
MIPS=NO
#
EMBEDED=NO
19
20 21 22
##################################################################################
##################################################################################
##################################################################################
winlin authored
23
# parse options.
24 25 26 27 28 29 30 31 32 33 34 35 36
for option
do
    case "$option" in
        -*=*) 
            value=`echo "$option" | sed -e 's|[-_a-zA-Z0-9/]*=||'` 
            option=`echo "$option" | sed -e 's|=[-_a-zA-Z0-9/]*||'`
        ;;
           *) value="" ;;
    esac
    
    case "$option" in
        --help)                         help=yes                  ;;
        
37
        --x86-x64)                      X86_X64=YES               ;;
winlin authored
38
        --mips)                         MIPS=YES                  ;;
39
        --arm)                          ARM=YES                   ;;
40
        --pi)                           PI=YES                    ;;
41 42

        *)
43
            echo "$0: error: invalid option \"$option\", @see $0 --help"
44 45 46 47 48 49 50 51 52
            exit 1
        ;;
    esac
done
if [ $help = yes ]; then
    cat << END

  --help                   print this message
53
  --x86-x64                for x86-x64 platform, configure/make/package.
winlin authored
54
  --arm                    for arm cross-build platform, configure/make/package.
winlin authored
55
  --mips                   for mips cross-build platform, configure/make/package.
winlin authored
56
  --pi                     for pi platform, configure/make/package.
57 58 59
END
    exit 0
fi
winlin authored
60
winlin authored
61 62 63 64
# embeded(arm/mips)
if [ $ARM = YES ]; then EMBEDED=YES; fi
if [ $MIPS = YES ]; then EMBEDED=YES; fi
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
# 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
82 83 84
# check lsb_release
lsb_release -a >/dev/null 2>&1
ret=$?; if [[ $ret -ne 0 ]]; then 
85 86
	failed_msg "lsb_release not found. "
	failed_msg "to install on centos/debian(ubuntu/respberry-pi):"; 
87 88 89 90 91
	failed_msg "	sudo yum install -y lsb-release"; 
	failed_msg "	sudo aptitude install -y lsb-release"; 
	exit $ret; 
fi
92 93 94
# check os version
os_name=`lsb_release --id|awk '{print $3}'` &&
os_release=`lsb_release --release|awk '{print $2}'` &&
95
os_major_version=`echo $os_release|awk -F '.' '{print $1}'` &&
winlin authored
96
os_machine=`uname -i`
97
ret=$?; if [[ $ret -ne 0 ]]; then failed_msg "lsb_release get os info failed."; exit $ret; fi
98
ok_msg "target os is ${os_name}-${os_major_version} ${os_release} ${os_machine}"
99
winlin authored
100 101
# for raspberry-pi
# use rasberry-pi instead all release
102 103 104 105 106 107 108
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}"
winlin authored
109
110
# build srs
111
# @see https://github.com/winlinvip/simple-rtmp-server/wiki/v1_CN_Build
winlin authored
112
ok_msg "start build srs"
winlin authored
113
if [ $ARM = YES ]; then
winlin authored
114 115 116 117
    (
        cd $work_dir && 
        ./configure --arm --prefix=$INSTALL && make
    ) >> $log 2>&1
winlin authored
118 119 120 121 122
elif [ $MIPS = YES ]; then
    (
        cd $work_dir && 
        ./configure --mips --prefix=$INSTALL && make
    ) >> $log 2>&1
winlin authored
123 124 125 126 127
elif [ $PI = YES ]; then
    (
        cd $work_dir && 
        ./configure --pi --prefix=$INSTALL && make
    ) >> $log 2>&1
128
elif [ $X86_X64 = YES ]; then
winlin authored
129 130 131 132
    (
        cd $work_dir && 
        ./configure --x86-x64 --prefix=$INSTALL && make
    ) >> $log 2>&1
winlin authored
133
else
winlin authored
134
    failed_msg "invalid option, must be --x86-x64/--arm/--mips/--pi, see --help"; exit 1;
winlin authored
135
fi
winlin authored
136 137
ret=$?; if [[ 0 -ne ${ret} ]]; then failed_msg "build srs failed"; exit $ret; fi
ok_msg "build srs success"
138 139 140 141 142 143 144 145

# 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"
146 147 148 149 150 151 152 153 154 155 156 157 158

# 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"
winlin authored
159 160 161
# 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}'`
winlin authored
162
    os_machine=arm${arm_cpu}cpu
winlin authored
163
fi
winlin authored
164 165 166
if [ $MIPS = YES ]; then
    os_machine=mips
fi
winlin authored
167
ok_msg "machine: $os_machine"
winlin authored
168
169
# generate zip dir and zip filename
winlin authored
170
if [ $EMBEDED = YES ]; then
winlin authored
171 172 173 174 175 176 177 178 179 180
    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
ok_msg "get srs version $srs_version"
181 182
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
winlin authored
183
ok_msg "target zip filename $zip_dir"
184
185 186 187 188
# zip package.
ok_msg "start zip package"
(
    mv $package_dir ${build_objs}/${zip_dir} &&
189
    cd ${build_objs} && rm -rf ${zip_dir}.zip && zip -q -r ${zip_dir}.zip ${zip_dir} &&
190 191 192 193 194 195
    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"
196 197 198 199 200 201
echo ""
echo "package: ${build_objs}/${zip_dir}.zip"
echo "install:"
echo "      unzip -q ${zip_dir}.zip &&"
echo "      cd ${zip_dir} &&"
echo "      sudo bash INSTALL"
202 203

exit 0