-
Notifications
You must be signed in to change notification settings - Fork 2
/
move-repo.sh
executable file
·103 lines (92 loc) · 2.19 KB
/
move-repo.sh
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
#!/bin/bash
#
# Move packages from current directory to the REPO dir.
# Run under the directory of where *.zst was saved.
# The directcory name should match the name of the local db file.
# eg: your zst file should located in /some/path/extra-staging/os/loong64/
#
umask 002
if [[ $# -lt 1 ]]; then
echo "Usage: ${0##*/} <repo-name> [optional filelist]"
exit 1
fi
FROM=$(basename `pwd | sed 's/\/os\/loong64$//g'`)
TO=$1
# destination
if [[ "$TO" == *"/"* ]]; then
# with full path
NEWPATH=$TO/os/loong64
TO=$(basename $TO)
else
NEWPATH=/srv/http/loongarch/archlinux/$TO/os/loong64
fi
if [ "$(realpath $NEWPATH)" = "$(realpath `pwd`)" ]; then
echo "The paths refer to the same directory."
exit 1
fi
if [[ ! -d $NEWPATH ]]; then
echo "Destination path don't exist!"
exit 1
fi
if [[ $# -gt 1 ]]; then
shift
ALLFILES="$@"
else
ALLFILES=$(ls *.zst)
fi
# arrary of packages
ALLPKG=()
ALLZST=()
fcount=1
do_move(){
if [ "${#ALLPKG[@]}" -eq 0 ]; then
return
fi
if [ -f $FROM.db.tar.gz ]; then
repo-remove $FROM.db.tar.gz "${ALLPKG[@]}"
fi
for i in "${ALLZST[@]}"; do
echo "Copying file: $i ..."
cp $i $NEWPATH
cp $i.sig $NEWPATH
done
repo-add -R $NEWPATH/$TO.db.tar.gz "${ALLZST[@]}" | tee add.log
exit_code=${PIPESTATUS[0]}
if [[ ! $exit_code -eq 0 ]]; then
exit 2
fi
about_to_delete=()
for pkg in $(grep -oP "Removing old package file '\K[^']*(?=')" add.log); do
about_to_delete+=($pkg)
done
if [ ! "${#about_to_delete[@]}" -eq 0 ]; then
for file in "${about_to_delete[@]}"; do
echo "Deleting $file ..."
rm -f $NEWPATH/$file{,.sig}
done
fi
rm -f add.log
for i in "${ALLZST[@]}"; do
echo "Deleting file: $i ..."
rm -f $i{,.sig}
done
fcount=1
ALLZST=()
ALLPKG=()
}
for pkg in ${ALLFILES[@]}; do
((fcount++))
if [ ! -f $pkg.sig ]; then
echo "Signing $pkg ..."
gpg --detach-sign $pkg || exit 1
fi
chmod 664 $pkg{,.sig}
ALLZST+=($pkg)
j=${pkg%-*}
k=${j%-*}
ALLPKG+=(${k%-*})
if [[ $fcount -gt 100 ]]; then
do_move
fi
done
do_move