-
Notifications
You must be signed in to change notification settings - Fork 33
/
portsync
executable file
·129 lines (115 loc) · 2.92 KB
/
portsync
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/sh
#
# scratchpkg
#
# Copyright (c) 2018 by Emmett1 ([email protected])
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
cmp_copy() {
# usage:
# cmp_copy <source dir> <target dir>
#
reponame=${2##*/}
for p in $1/*; do
[ -d $p ] || continue
pname=${p##*/}
if [ ! -d $2/$pname ]; then
mkdir -p $2/$pname
for f in $p/* $p/.pkgfiles $p/.checksums; do
[ -f $f ] || continue
case $f in
*/update) continue;;
esac
fname=${f##*/}
echo "+ $reponame/$pname/$fname"
cp $f $2/$pname/$fname
done
else
for f in $p/* $p/.pkgfiles $p/.checksums; do
[ -f $f ] || continue
case $f in
*/update) continue;;
esac
fname=${f##*/}
cmp -s $f $2/$pname/$fname || {
echo "* $reponame/$pname/$fname"
cp $f $2/$pname/$fname
}
done
fi
done
for p in $2/*; do
[ -d $p ] || continue
pname=${p##*/}
for f in $p/* $p/.pkgfiles $p/.checksums; do
[ -f $f ] || continue
fname=${f##*/}
if [ ! -f $1/$pname/$fname ]; then
echo "- $reponame/$pname/$fname"
rm $2/$pname/$fname
fi
done
if [ ! -d $1/$pname ]; then
rmdir $2/$pname
fi
done
}
sync_repo() {
# usage:
# sync_repo <repo url> <ports dir>
#
url=$(echo $1 | cut -d / -f -5)
portdir=$2
case $1 in
*github.com/*)
branch=$(echo $1 | cut -d / -f 7)
repodir=$(echo $1 | cut -d / -f 8-);;
*gitlab.com/*)
branch=$(echo $1 | cut -d / -f 8)
repodir=$(echo $1 | cut -d / -f 9-);;
*) # will add more git service
branch=$(echo $1 | cut -d / -f 8)
repodir=$(echo $1 | cut -d / -f 9-);;
esac
# if branch not in the url, assume it master branch
[ "$branch" ] || branch=master
echo "fetching ports: $1"
# cloning ports repository
git clone --depth 1 -q -b $branch $url $tmprepo || {
echo " failed sync repo"
exit 1
}
# copying ports to port directory by comparing
cmp_copy $tmprepo/$repodir $portdir
# cleanup tmp cloned repo
rm -fr $tmprepo
echo "ports synced: $2"
}
tmprepo=/tmp/tmprepo
repo_file=/etc/scratchpkg.repo
if [ ! -e "$repo_file" ]; then
echo "missing repo file: $repo_file"
exit 1
fi
if [ "$(id -u)" != 0 ]; then
echo "this operation need root access."
exit 1
fi
grep -Ev '^(#|$)' "$repo_file" | awk '{print $1,$2}' | while read -r repodir repourl; do
if [ "$repodir" ] && [ "$repourl" ]; then
sync_repo $repourl $repodir
fi
done
exit 0