arm 自动升级脚本

哈哈,试验成功了,效果还不错!!

#SubtitleServer autoupdate script.
#author:zhangshaoyan
#date:January 14,2016.

LocalAppFile=SubtitleServer_Local
LocalMD5File=${LocalAppFile}.md5

RemoteAppFile=SubtitleServer
RemoteMD5File=${RemoteAppFile}.md5

FTPServer=172.23.142.82


#download md5 file from server.
ftp -n < open $FTPServer
user root root
binary
get $RemoteMD5File
close
bye
EOF

#check local md5 file.
if [ ! -f $LocalMD5File ];then
    echo "can't find $LocalMD5File !"
    exit -1
fi

#check download success or not.
if [ ! -f $RemoteMD5File ];then
    echo "Can't find $RemoteMD5File !"
    exit -1
fi

#extract two md5 values.
LocalMD5Value=$(cat $LocalMD5File | awk '{print $1}')
RemoteMD5Value=$(cat $RemoteMD5File | awk '{print $1}')
echo "LocalMD5:" $LocalMD5Value
echo "RemoteMD5:" $RemoteMD5Value

#compare two md5 values.
if [ ${LocalMD5Value} = ${RemoteMD5Value} ];then
    echo "No need to update,exit"
    exit 0
fi
echo "execute update process..."

#backup current version.
mv $LocalAppFile ${LocalAppFile}.backup
mv $LocalMD5File ${LocalMD5File}.backup

#download new version from ftp server.
ftp -n < open $FTPServer
user root root
binary
get $RemoteAppFile
get $RemoteMD5File
close
bye
EOF

#add executive permission.
chmod +x $RemoteAppFile

#fix its name.
mv $RemoteAppFile $LocalAppFile
mv $RemoteMD5File $LocalMD5File

echo "update done!"


#this is the end of file.

下面是试验结果:

shell.albert@zhangshaoyan:~/project/NXPiMX53/SubtitleServer/update> ls
autoupdate.sh  SubtitleServer_Local  SubtitleServer_Local.md5
shell.albert@zhangshaoyan:~/project/NXPiMX53/SubtitleServer/update> ./autoupdate.sh
Connected to 172.23.142.82.
220 Operation successful
230 Operation successful
Remote system type is UNIX.
Using binary mode to transfer files.
200 Operation successful
local: SubtitleServer.md5 remote: SubtitleServer.md5
229 EPSV ok (|||57693|)
150 Opening BINARY connection for SubtitleServer.md5 (49 bytes)
100% |*************************************************************************************************|    49      736.17 KiB/s    00:00 ETA
226 Operation successful
49 bytes received in 00:00 (341.79 KiB/s)
Can't parse time `19700001032226'.
221 Operation successful
LocalMD5: 335c6c59831f093a276391d89f08126d
RemoteMD5: bd0940afc3bd94262d9f076d27d2ccd6
execute update process...
Connected to 172.23.142.82.
220 Operation successful
230 Operation successful
Remote system type is UNIX.
Using binary mode to transfer files.
200 Operation successful
local: SubtitleServer remote: SubtitleServer
229 EPSV ok (|||51800|)
150 Opening BINARY connection for SubtitleServer (1047787 bytes)
100% |*************************************************************************************************|  1023 KiB   11.21 MiB/s    00:00 ETA
226 Operation successful
1047787 bytes received in 00:00 (11.20 MiB/s)
Can't parse time `19700001025835'.
local: SubtitleServer.md5 remote: SubtitleServer.md5
229 EPSV ok (|||35470|)
150 Opening BINARY connection for SubtitleServer.md5 (49 bytes)
100% |*************************************************************************************************|    49        1.06 MiB/s    00:00 ETA
226 Operation successful
49 bytes received in 00:00 (455.72 KiB/s)
Can't parse time `19700001032226'.
221 Operation successful
update done!
shell.albert@zhangshaoyan:~/project/NXPiMX53/SubtitleServer/update> echo $?
0
shell.albert@zhangshaoyan:~/project/NXPiMX53/SubtitleServer/update>

你可能感兴趣的:(软件技术)