-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathenv.sh
More file actions
67 lines (53 loc) · 1.3 KB
/
env.sh
File metadata and controls
67 lines (53 loc) · 1.3 KB
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
case "$DISTRO" in
"archlinux") ;;
"archlinuxarm") ;;
*)
echo >&2 "Unknown distro: '$DISTRO'";
exit 127 ;;
esac
export D_ROOT="/home/www/system/$DISTRO/"
export D_SRC="$D_ROOT/mirror-scripts/$DISTRO/"
export D_VAR="$D_ROOT/var/$DISTRO/"
export D_LOG="$D_VAR/log/"
export D_MIRROR="/home/www/public/$DISTRO/"
mkdir -p $D_LOG $D_VAR
# Please do not include any space in the foutput!
__now__() {
TZ=Asia/Saigon date +'%Y%m%d-%H%M%S'
}
__rand__() {
local _max="${1:-1}"
awk -vseed="$RANDOM" -vmax=$_max \
'BEGIN{ srand(seed); print int(max*rand()); }'
}
__random_mirror_select__() {
local _mirrors=($(cat $D_SRC/rsync.urls | grep ^rsync://))
local _max="${#_mirrors[@]}"
_n="$(__rand__ $_max)"
echo ${_mirrors[$_n]}
}
__locking__() {
_PID_FILE="$D_VAR/$1.pid"
if [[ -f "$_PID_FILE" ]]; then
echo >&2 "$(__now__): PID file does exist $_PID_FILE"
return 1
fi
echo $$ > $_PID_FILE
return 0
}
__unlock__() {
_PID_FILE="$D_VAR/$1.pid"
rm -f $_PID_FILE
}
__sync() {
if [[ ! -w "$D_MIRROR" ]]; then
# echo >&2 "$FUNCNAME: $D_MIRROR is not writable"
return
fi
cd $D_VAR
$D_SRC/sync.sh >> sync.sh.log 2>&1
_flog="$D_LOG/sync.sh.log-$(__now__)"
mv sync.sh.log "$_flog" && gzip "$_flog"
zcat "$_flog.gz" | $D_SRC/report.sh \
> $D_MIRROR/status.json
}