This repository has been archived by the owner on Feb 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetchports
110 lines (77 loc) · 2.21 KB
/
fetchports
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/sh
. /etc/rc.subr
###### Golable var ###############################
name="fetchports"
rcvar=fetchports_enable
start_cmd="start_fetch"
stop_cmd="stop_fetch"
start_precmd="init_env"
##### Persinal var ################################
thread=150
localdir="/other/ports"
ln_dir="$localdir/distfiles"
#remotedir="/"
remotedir="/pub/FreeBSD/ports"
url="http://ftp2.za.freebsd.org"
#url="http://ports1.chinafreebsd.cn"
####################################################
fetch_bin=`pkg query %n lftp`
[ -z "fetchports_enable" ] && fetchports_enable="NO"
init_env(){
if [ "$fetch_bin" != "lftp" ];then
/usr/sbin/pkg update -f && /usr/sbin/pkg install -y lftp && \
ln -s ln -s /usr/local/bin/lftp /usr/local/bin/ports_lftp
fi
if [ ! -d "$localdir" ];then
mkdir -p $localdir
fi
check_url $url
}
log(){
echo `date +%Y-%m-%d_%H:%M:%S` >> /var/log/fetchports.log
}
make_ln(){
for tmp_dir in `ls $ln_dir` ;do
if [ -d $ln_dir/$tmp_dir ];then
find $ln_dir/$tmp_dir -type f -exec ln -s {} $ln_dir \;
fi
done
}
check_url(){
du1="http://ftp2.za.freebsd.org"
for tmp in "$du1"; do
if [ "$tmp" == "$1" ]; then
echo "url cheack successful"
break
else
echo "Please cheack if input the wrony url:$url"
exit
fi
done
}
start_fetch(){
echo "start Ports fetching ..."
/usr/local/bin/ports_lftp -c open -e "mirror --parallel=$thread --delete $remotedir $localdir" $url > /dev/null 2>&1 &
$(waiting_for_fetch && make_ln > /dev/null 2>&1 && log) &
}
waiting_for_fetch(){
while [ "1" = "1" ];do
pid=`ps aux | grep "[p]orts_lftp" | wc -l`
if [ $pid -gt 0 ];then
sleep 5
else
break
fi
done
}
stop_fetch(){
pid=`ps aux | grep "[p]orts_lftp" | awk '{print $11}' | cut -d / -f 5`
if [ "$pid" == "ports_lftp" ];then
echo "stoping fetchports ..."
kill `ps aux | grep "[p]orts_lftp" | awk '{print $2}'`
else
echo "service dos not exsiting ...."
fi
}
load_rc_config $name
run_rc_command $1