|
自动升级LumaQQ脚本
By Mada at geekbone.org
因为自己在Debian上用的QQ 软件一直是 LumaQQ,就喜欢LumaQQ的几乎每天
都有更新出来,看到那么多功能一点点得增加,是一种很满足的感觉,很感谢LumaQQ的
开发小组成员的辛苦劳动。
也是因为频繁的更新,所以如果每天都去手动更新确实是个很麻烦的事情,所以我
写了一个小小的脚本程序,只要运行它就会自动去检查是否有更新存在,并且将更新
应用到你安装的QQ目录下面。代码很简单,我付在下面,想偷懒的人就拿过去用把。
不能保证帖子帖出来的时候有丢三落四的现象出现,所以最后直接从附加里面
下载脚本使用。
使用这个脚本前,请确保你在使用LumaQQ 2004,并且安装有
awk, unzip, wget, sed这几个己本工具。
使用方法,下载附件后给该附件加可执行权限。然后直接运行即可。
Good Luck.
更新记录:
1. 第一个版本发布
2. 只重复用wget尝试下载7次,不然有可能会对lumaqq.linuxsir.net造成过大的压力。
3. 如果你是Gnome的用户的话,加入了一个提醒功能,当升级成功后,并且发现你当前正在运行LumaQQ程序,会弹出一个对话框提示你升级完毕,请重新运行LumaQQ程序。
[code:1]
#!/bin/sh
# Automatic update download LumaQQ upgrade file from lumaqq.linuxsir.net
#
# This is the
# Script by mada at geekbone dot org
# Thanks to LumaQQ team.
#
# History:
# 1. The first 0.1 version released
# 2. Only try 7 times if wget failed, otherwise administrator of linuxsir.net
# will kick my ass.
# 3. Add a warning box once lumaQQ download success, notify us to restart
# the lumaqq application
LUMAQQ_ROOT=""
LUMAQQ_UPDATE_INI="http://lumaqq.linuxsir.org/update/update.txt"
WGET_OPT="-q -C off"
LUMAQQ_TMP=""
LUMAQQ_UPDATE=""
NOTIFIER=`which zenity`
check_env()
{
# Get the LumaQQ working directory
LUMAQQ_ROOT=`readlink ~/.lumaqq/xml`
if [ $? -ne 0 ] ; then
echo "It seems there is no LumaQQ for you."
exit 2
fi
LUMAQQ_ROOT="${LUMAQQ_ROOT}"/..
LUMAQQ_TMP="${LUMAQQ_ROOT}/tmp"
if [ ! -d "${LUMAQQ_TMP}" ] ; then
mkdir -p "${LUMAQQ_TMP}" &>/dev/null
if [ $? -ne 0 ] ; then
echo "You need have write permission on the lumaqq dir."
exit 2
fi
fi
touch "${LUMAQQ_TMP}" &>/dev/null
if [ $? -ne 0 ] ; then
echo "You need have write permission on the lumaqq dir."
exit 2
fi
rm -f "${LUMAQQ_TMP}"/*
if [ $? -ne 0 ] ; then
echo "You need have write permission on the lumaqq dir."
exit 2
fi
}
get_old_ver()
{
oldver=`zipgrep -h "update.time" "${LUMAQQ_ROOT}"/lib/lumaqq.jar -x "*.class" | head -n 1`
if [ $? -ne 0 ] ; then
echo "Could not get current LumaQQ version"
exit 2
fi
oldver=`echo "${oldver}" | sed -e 's/update\.time = //'`
}
get_new_ver()
{
wget ${WGET_OPT} ${LUMAQQ_UPDATE_INI} -O "${LUMAQQ_TMP}"/update.txt &>/dev/null
if [ $? -ne 0 ] ; then
echo "wget could not fetch the update.txt"
exit 2
fi
newver=`head -n 1 "${LUMAQQ_TMP}"/update.txt`
}
compare_version()
{
num_A=`echo $1 | sed -e 's/[^0-9]//g'`
if [ -z "$num_A" ] ; then
return 2
fi
num_B=`echo $2 | sed -e 's/[^0-9]//g'`
if [ -z "$num_B" ] ; then
return 2
fi
ret=`echo ${num_A} ${num_B} | awk '{newer=($1>$2)?1:0;print newer}'`
return ${ret}
}
get_update()
{
LUMAQQ_UPDATE=`echo ${newver} | sed -e 's/[^0-9]/\./g'`
LUMAQQ_UPDATE="http://lumaqq.linuxsir.org/download/patch/lumaqq_2004_patch_${LUMAQQ_UPDATE}.zip"
RETRY=7
while [ ${RETRY} -gt 0 ] ; do
wget ${WGET_OPT} ${LUMAQQ_UPDATE} -O "${LUMAQQ_TMP}"/lumaqq_patch.zip &>/dev/null
if [ $? -eq 0 ] ; then
break
fi
RETRY=`expr ${RETRY} - 1`
done
if [ ${RETRY} -eq 0 ] ; then
echo "Failed donwload update file at this time, try it later."
exit 2
fi
}
do_update()
{
get_update
cd "${LUMAQQ_TMP}"
unzip -o "${LUMAQQ_TMP}"/lumaqq_patch.zip "*.jar"
if [ $? -ne 0 ] ; then
echo "Download lumaqq zip file corrupt"
exit 2
fi
cp "${LUMAQQ_TMP}"/*.jar "${LUMAQQ_ROOT}"/lib
echo "Update success"
ret=`pgrep -lf java | grep -i lumaqq`
if [ ! -z "${ret}" ] ; then
if [ ! -z "${NOTIFIER}" ] ; then
${NOTIFIER} --warning --text="LumaQQ upgrade success, please close your current LumaQQ restart LumaQQ program."
fi
fi
}
#main function
check_env
get_old_ver
get_new_ver
compare_version "${newver}" "${oldver}"
ret=$?
if [ $ret -eq 2 ] ; then
echo "Could not get the LumaQQ version"
exit 2
fi
if [ $ret -eq 1 ] ; then
echo "New LumaQQ available, fetching now...."
do_update
exit 0
fi
if [ $ret -eq 0 ] ; then
echo "No new version available now."
exit 0
fi
[/code:1] |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
×
|