QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 962|回复: 7

自动升级LumaQQ脚本

[复制链接]
发表于 2005-3-9 20:31:41 | 显示全部楼层 |阅读模式
自动升级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]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
发表于 2005-3-9 21:15:05 | 显示全部楼层
有用
回复

使用道具 举报

发表于 2005-3-9 21:39:55 | 显示全部楼层
明天试一下,多谢楼主共享
回复

使用道具 举报

 楼主| 发表于 2005-3-9 21:44:20 | 显示全部楼层
更新了一下,因为手工从linuxsir上下载patch,老是说 503错。第一个版本会一直去尝试下载直到
成功为止,如果太多人都这样干的话,linuxsir的webmaster估计得踢我PP了。所以修改成只
重试7次,如果都失败了,只能怪自己倒霉了。
回复

使用道具 举报

发表于 2005-3-9 22:01:45 | 显示全部楼层
欢迎放到shell脚本欣赏区
谢谢
回复

使用道具 举报

发表于 2005-3-10 23:23:51 | 显示全部楼层
oldver=`zipgrep -h "update.time" "${LUMAQQ_ROOT}"/lib/lumaqq.jar -x "*.class" | head -n 1`
偶挂在这里了,打开文件看见里面版本升级信息update.time都在local/*.properties里面阿,
回复

使用道具 举报

 楼主| 发表于 2005-3-11 17:19:06 | 显示全部楼层
zipgrep解压缩会比较耗cpu,我PM 1.7G的cpu用zipgrep查这个字符串用了大概10秒。所以可能需要等一会。
回复

使用道具 举报

 楼主| 发表于 2005-3-14 15:48:57 | 显示全部楼层
更新脚本,加入功能:
3. 如果你是Gnome的用户的话,加入了一个提醒功能,当升级成功后,并且发现你当前正在运行LumaQQ程序,会弹出一个对话框提示你升级完毕,请重新运行LumaQQ程序。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-10-6 15:24 , Processed in 0.075052 second(s), 17 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表