Chinaunix首页 | 论坛 | 博客
  • 博客访问: 133756
  • 博文数量: 85
  • 博客积分: 3980
  • 博客等级: 中校
  • 技术积分: 1000
  • 用 户 组: 普通用户
  • 注册时间: 2009-06-08 06:42
文章分类

全部博文(85)

文章存档

2010年(1)

2009年(84)

我的朋友

分类: LINUX

2009-08-05 11:32:12

# !/bin/bash
# getmirror -- to wget a website in your device as a mirror, and manage the mirrorlist
# using:
#    getmirror [-d ]     -- save the website in the directory your specify
#                         or using the default
# getmirror ud                 -- update the mirror in the directory
# getmirror dir          -- specify your mirror directory as a default
#    getmirror add             -- add a new website in your mirror list to manage
#                         the default mirror
GMDIR=$HOME/.wget
PREFDIR=$GMDIR/prefdir
MIRLIST=$GMDIR/wgetlist
test ! -d $GMDIR && mkdir $GMDIR
test ! -e $PREFDIR && echo $HOME/webmirror > $PREFDIR
# give the website to the directory you prefer, default is $HOME/webmirror
case $1 in
    dir)
    if [ -z $2 ];then
        echo "Current mirror directory is "`cat $PREFDIR`
        echo -e "Use \"getmirror dir [directory]\" to change it."
        exit 0
    fi
    mkdir $2
    cd $2 && echo `pwd` > $PREFDIR
    ;;
    add)    
    if [ -z $2 ]; then
        echo "No website specified."
        exit 0
    fi
    echo $2 >> $MIRLIST
    ;;
    ud)
    test ! -e $MIRLIST && echo "there’s not mirrorlist. you should using getmirror add  first." && exit 0
    cd `cat $PREFDIR` && wget -m -t99 -l1 `cat $MIRLIST`
    ;;
    -d)
    if [ $# != 3 ]; then
        echo "Usage: getmirror [-d directory] website"
        exit 0
    fi
    CURDIR=$2
    test ! -d $CURDIR && mkdir $CURDIR
    test ! -w $CURDIR && echo "Error: current directory isn’t writeable." && exit 1
    cd $CURDIR
    wget -m -t99 -l1 $3
    ;;
    *)
    if [ $# = 0 ];then
        echo -e "Usage:
    getmirror [ option  | command ]
Option:
    [-d ]     -- save the website in the directory you specify or
                      using the default
Command:
    dir             -- specify your mirror directory as a default
    add             -- add a new website in your mirror
    ud                -- update your mirror"
        exit 0
    fi
    CURDIR=$PREFDIR
    test ! -d $CURDIR && mkdir $CURDIR
    test ! -w $CURDIR && echo "Error: current directory isn’t writeable." && exit 1
    cd $CURDIR
    wget -m -t99 -l1 $1
    ;;
esac
 
reference:
阅读(505) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~