代码拉取完成,页面将自动刷新
#!/bin/bash
# user can config the following configs, then package.
INSTALL=/usr/local/AModule
INIT_SH=AModule.sh
########################################################################
# utility functions
########################################################################
RED="\\033[31m"
GREEN="\\033[32m"
YELLOW="\\033[33m"
BLACK="\\033[0m"
POS="\\033[60G"
ok_msg() {
echo -e "${1}${POS}${BLACK}[${GREEN} OK ${BLACK}]"
}
failed_msg() {
echo -e "${1}${POS}${BLACK}[${RED}FAILED${BLACK}]"
}
##################################################################################
##################################################################################
##################################################################################
# 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
work_dir=`dirname $0`; work_dir=`(cd ${work_dir} && pwd)`
echo "execute scripts in file: $0";
echo "work_dir = $work_dir."
fi
#product_dir=$work_dir
#log="${work_dir}/logs/package.`date +%s`.log" && . ${product_dir}/scripts/_log.sh && check_log
log=$work_dir/install.log
ret=$?; if [[ $ret -ne 0 ]]; then exit $ret; fi
# user must stop service first.
ok_msg "check previous install"
if [[ -f /etc/init.d/$INIT_SH ]]; then
/etc/init.d/$INIT_SH status >/dev/null 2>&1
ret=$?; if [[ 0 -eq ${ret} ]]; then
failed_msg "you must stop the service first: sudo /etc/init.d/$INIT_SH stop";
exit 1;
fi
fi
ok_msg "previous install checked"
# backup old ${INIT_SH}
ok_msg "backup old ${INIT_SH}"
install_root=$INSTALL
#install_bin=$install_root/$APP_EXE
if [[ -d $install_root ]]; then
version="unknown"
#if [[ -f $install_bin ]]; then
# version=`$install_bin -v 2>/dev/stdout 1>/dev/null`
#fi
backup_dir=${install_root}.`date "+%Y-%m-%d_%H-%M-%S"`.v-$version
ok_msg "backup installed dir, version=$version"
ok_msg " to=$backup_dir"
mv $install_root $backup_dir >>$log 2>&1
ret=$?; if [[ 0 -ne ${ret} ]]; then failed_msg "backup installed dir failed"; exit $ret; fi
ok_msg "backup installed dir success"
fi
ok_msg "old ${INIT_SH} backuped"
# prepare files.
ok_msg "prepare files"
(
sed -i "s|^ROOT=.*|ROOT=\"${INSTALL}\"|g" $work_dir/${INIT_SH}
) >> $log 2>&1
ret=$?; if [[ 0 -ne ${ret} ]]; then failed_msg "prepare files failed"; exit $ret; fi
ok_msg "prepare files success"
# copy core files
ok_msg "copy core components to $install_root"
(
mkdir -p $install_root
mkdir -p $install_root/logs
cp -r $work_dir/html $install_root
cp -r $work_dir/device_dahua_linux32 $install_root
cp -r $work_dir/device_dahua_linux64 $install_root
cp -r $work_dir/device_hikvision_linux32 $install_root
cp -r $work_dir/device_hikvision_linux64 $install_root
cp -r $work_dir/device_hanbang_linux32 $install_root
cp -r $work_dir/device_hanbang_linux64 $install_root
cp -r $work_dir/device_ffmpeg_linux32 $install_root
cp -r $work_dir/device_ffmpeg_linux64 $install_root
cp $work_dir/device_agent.conf $work_dir/device_manager.conf $install_root
cp $work_dir/lib* $work_dir/GXAgent $work_dir/${INIT_SH} $install_root
) >>$log 2>&1
ret=$?; if [[ 0 -ne ${ret} ]]; then failed_msg "copy core components failed"; exit $ret; fi
ok_msg "copy core components success"
# install init.d scripts
ok_msg "install init.d scripts"
(
rm -rf /etc/init.d/${INIT_SH} &&
ln -sf $install_root/${INIT_SH} /etc/init.d/${INIT_SH}
) >>$log 2>&1
ret=$?; if [[ 0 -ne ${ret} ]]; then failed_msg "install init.d scripts failed"; exit $ret; fi
ok_msg "install init.d scripts success"
# install system service
lsb_release --id|grep "CentOS" >/dev/null 2>&1; os_id_centos=$?
lsb_release --id|grep "Ubuntu" >/dev/null 2>&1; os_id_ubuntu=$?
lsb_release --id|grep "Debian" >/dev/null 2>&1; os_id_debian=$?
lsb_release --id|grep "Raspbian" >/dev/null 2>&1; os_id_rasabian=$?
if [[ 0 -eq $os_id_centos ]]; then
ok_msg "install system service for CentOS"
/sbin/chkconfig --add ${INIT_SH} && /sbin/chkconfig ${INIT_SH} on
ret=$?; if [[ 0 -ne ${ret} ]]; then failed_msg "install system service failed"; exit $ret; fi
ok_msg "install system service success"
elif [[ 0 -eq $os_id_ubuntu ]]; then
ok_msg "install system service for Ubuntu"
update-rc.d ${INIT_SH} defaults
ret=$?; if [[ 0 -ne ${ret} ]]; then failed_msg "install system service failed"; exit $ret; fi
ok_msg "install system service success"
elif [[ 0 -eq $os_id_debian ]]; then
ok_msg "install system service for Debian"
update-rc.d ${INIT_SH} defaults
ret=$?; if [[ 0 -ne ${ret} ]]; then failed_msg "install system service failed"; exit $ret; fi
ok_msg "install system service success"
elif [[ 0 -eq $os_id_rasabian ]]; then
ok_msg "install system service for RaspberryPi"
update-rc.d ${INIT_SH} defaults
ret=$?; if [[ 0 -ne ${ret} ]]; then failed_msg "install system service failed"; exit $ret; fi
ok_msg "install system service success"
else
warn_msg "ignore and donot install system service for `lsb_release --id|awk '{print $3}'`."
fi
echo ""
echo "see: https://github.com/ossrs/srs/wiki/v1_CN_LinuxService"
echo "install success, you can:"
echo -e "${GREEN} sudo /etc/init.d/${INIT_SH} start${BLACK}"
echo -e "${GREEN} sudo service ${INIT_SH} start${BLACK}"
echo "${INIT_SH} root is ${INSTALL}"
exit 0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。