This commit is contained in:
xdtianyu
2015-01-27 13:57:10 +08:00
parent 53c24c488b
commit 1afd98180e
3 changed files with 77 additions and 0 deletions

54
py/build.sh Normal file
View File

@@ -0,0 +1,54 @@
#!/bin/bash
USER=$(cat /etc/passwd |grep bash| grep home|head -n1 |cut -d ':' -f 1)
if [ -z '$USER' ];then
echo 'Error, must have a normal user!!'
exit 0
else
echo "Run as $USER now."
fi
if [ -d '/tmp/rtmpweb' ];then
rm -r /tmp/rtmpweb
fi
sudo -u $USER mkdir /tmp/rtmpweb
sudo -u $USER cp -a . /tmp/rtmpweb
cd /tmp/rtmpweb
echo -e "cleaning...\n"
sudo -u $USER ./clean.sh
sudo -u $USER python server.py -c server.cfg -g
sudo -u $USER pyinstaller server.py -F
if [ -f '.auto' ];then
sudo -u $USER cp .auto dist
else
echo "Error, .auto file not find"
fi
if [ ! -d 'dist' ];then
echo "Error, pyinstall failed!"
exit 0
fi
if [ -d 'records' ];then
sudo -u $USER cp -r records dist
fi
if [ -d 'static' ];then
sudo -u $USER cp -r static dist
else
echo "Error, no static."
fi
if [ -f 'server.cfg' ];then
sudo -u $USER cp server.cfg dist
fi
cd -
echo "DONE!"

23
py/clean.sh Normal file
View File

@@ -0,0 +1,23 @@
#!/bin/bash
if [ $(find -name \*.pyc|wc -l) != 0 ];then
rm *.pyc
fi
if [ -f ".auto" ];then
rm .auto
fi
if [ -d "dist" ];then
rm -r dist
fi
if [ -d "build" ];then
rm -r build
fi
if [ -f "server.spec" ];then
rm server.spec
fi
echo "DONE!"

63
py/header.sh Normal file
View File

@@ -0,0 +1,63 @@
#!/bin/bash
#'''
# File name: header.sh
# Author: xdtianyu@gmail.com
# Date created: 2015-01-07 14:24:16
# Date last modified: 2015-01-09 15:19:31
# Bash Version: 4.3.11(1)-release
#'''
AUTHOR="xdtianyu@gmail.com"
PYTHON_VERSION=$(python -c 'import sys; print(sys.version[:5])')
for file in $(ls *.py); do
echo "check $file ..."
MODIFIED=$(stat -c %y $file| cut -d'.' -f1)
#echo "Last modified: $MODIFIED"
CURRENT_DATE=$(date "+%Y-%m-%d %H:%M:%S")
AUTHOR_COUNT=$(cat "$file" |grep " Author:" |wc -l)
if [ $AUTHOR_COUNT -gt 1 ];then
echo "More than one author, skip."
continue
elif [ $AUTHOR_COUNT -eq 1 ];then
echo "Have author, check modified date."
ORI=$(cat $file |grep " Date last modified: ")
if [ "$ORI" == "" ];then
echo "no line"
continue
fi
TARGET=" Date last modified: ${MODIFIED}"
#echo $ORI
#echo $TARGET
if [ "$ORI" == "$TARGET" ];then
echo "No change detected."
else
if [ $(cat $file |grep " Date last modified: "|wc -l) -gt 1 ];then
echo "More than one \"Date last modified\" detected, skip"
continue
fi
LINE=$(cat $file |grep " Date last modified: " -n | cut -d':' -f1)
sed -i "${LINE}s/.*/ Date last modified: ${CURRENT_DATE}/" $file
fi
# Check file name
FILE_COUNT=$(cat $file |grep " File name:"|wc -l)
if [ $FILE_COUNT -gt 1 ];then
echo "More than one \"File name\" detecetd, skip"
continue
elif [ $FILE_COUNT -eq 1 ];then
echo "Check file name..."
ORI_FILE_NAME=$(cat $file |grep " File name:")
TARGET_FILE_NAME=" File name: $file"
if [ ! "$ORI_FILE_NAME" == "$TARGET_FILE_NAME" ];then
echo "File name changed, update now"
FILE_LINE=$(cat $file |grep " File name: " -n | cut -d':' -f1)
sed -i "${FILE_LINE}s/.*/${TARGET_FILE_NAME}/" $file
else
echo "No change detected."
fi
fi
else
echo "Have no author, add header."
sed -i "1s/^/\'\'\'\n File name: $file\n Author: $AUTHOR\n Date created: $MODIFIED\n Date last modified: $CURRENT_DATE\n Python Version: $PYTHON_VERSION\n\'\'\'\n\n/" $file
fi
done