Created
May 31, 2013 09:28
-
-
Save hiccupzhu/5683872 to your computer and use it in GitHub Desktop.
parse some confs with shell script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
usage() | |
{ | |
echo "Release time:xxxx-xx-xx" | |
echo " -v|--version : version" | |
echo " -h|--help : help" | |
echo " --add : add a channel" | |
echo " --list : list all channels" | |
echo " --name : channel name" | |
echo " --streamaddr <...> : stream address like[0.0.0.0:21000]" | |
echo " --manageaddr <...> : manage address like[0.0.0.0:11000]" | |
echo " --sourceaddr <...> : source address like[udp://192.168.xxx.xxx:xxxx]" | |
echo " --vpid <...> : source video pid like[18b0]" | |
echo " --apid <...> : source audio pid like[18b1]" | |
echo "e.g.: shtool --add --name example --streamaddr 0.0.0.0:20130 --manageaddr 0.0.0.0:10130 --sourceaddr udp://239.100.194.2:1234 --vpid 18b0 --apid 18b1" | |
return; | |
} | |
workmode="" | |
#channel name | |
chname="" | |
streamaddr="" | |
manageaddr="" | |
sourceaddr="" | |
vpid="" | |
apid="" | |
check_root() | |
{ | |
if [ "root" != "$USER" ]; then | |
echo "Permission denied! Please use root try again." | |
exit 0; | |
fi | |
} | |
channel_add() | |
{ | |
if [ "$chname" == "" ]; then echo "channel name must to set!" >&2 ; exit 1 ; fi | |
if [ "$streamaddr" == "" ]; then echo "streamaddr must to set!" >&2 ; exit 1 ; fi | |
if [ "$manageaddr" == "" ]; then echo "manageaddr must to set!" >&2 ; exit 1 ; fi | |
if [ "$sourceaddr" == "" ]; then echo "sourceaddr must to set!" >&2 ; exit 1 ; fi | |
if [ "$vpid" == "" ]; then echo "vpid must to set!" >&2 ; exit 1 ; fi | |
if [ "$apid" == "" ]; then echo "apid must to set!" >&2 ; exit 1 ; fi | |
check_root; | |
target="/etc/itvencoder/$chname.conf" | |
cp /etc/template.conf $target | |
perl -pi -e "s/STREAM_ADDR/$streamaddr/g" $target | |
perl -pi -e "s/MANAGE_ADDR/$manageaddr/g" $target | |
perl -pi -e "s#SOURCE_ADDR#$sourceaddr#g" $target | |
perl -pi -e "s/VPID/$vpid/g" $target | |
perl -pi -e "s/APID/$apid/g" $target | |
target="/etc/supervisord.d/$chname.ini" | |
mkdir -p /var/log/itvencoder/$chname | |
cp /etc/template.ini $target | |
perl -pi -e "s/CHNAME/$chname/g" $target | |
exit 0; | |
} | |
channel_list() | |
{ | |
ls /etc/itvencoder/*.conf | xargs grep -E "^httpstreaming|^httpmgmt|^ *uri" | perl -pe "s/#.*$//g" | perl -pe "s/<\/var>//g" | perl -pe "s/<.*>//g" | perl -pe "s/ //g" | |
exit 0; | |
} | |
TEMP=`getopt -o vh --long version,help,add,list,name:,streamaddr:,manageaddr:,sourceaddr:,vpid:,apid: '--' $@` | |
if [ $? != 0 ] ; then echo "Please check args!!!" >&2 ; exit 1 ; fi | |
#echo $TEMP | |
eval set -- $TEMP | |
#echo $@ | |
while [ $# -gt 0 ] | |
do | |
case "$1" in | |
-h|--help) | |
usage | |
exit 0 | |
;; | |
-v|--version) | |
echo "iTVEncoder 0.3.0" | |
exit 0 | |
;; | |
--add) | |
workmode="add"; | |
;; | |
--list) | |
workmode="list"; | |
;; | |
--name) | |
chname="$2"; | |
shift; | |
;; | |
--streamaddr) | |
streamaddr="$2"; | |
shift; | |
;; | |
--manageaddr) | |
manageaddr="$2"; | |
shift; | |
;; | |
--sourceaddr) | |
sourceaddr="$2"; | |
shift; | |
;; | |
--vpid) | |
vpid="$2"; | |
shift; | |
;; | |
--apid) | |
apid="$2"; | |
shift; | |
;; | |
esac | |
shift; | |
done | |
if [ "$workmode" == "add" ]; then | |
channel_add; | |
elif [ "$workmode" == "list" ]; then | |
channel_list; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment