commit | author | age
|
00a98f
|
1 |
#!/bin/bash |
C |
2 |
|
a45f88
|
3 |
#Number of old packages to store, should be at least 1 |
C |
4 |
NUM_BACK=5 |
|
5 |
|
00a98f
|
6 |
function newest_matching_file |
C |
7 |
{ |
|
8 |
# Use ${1-} instead of $1 in case 'nounset' is set |
|
9 |
local -r glob_pattern=${1-} |
|
10 |
|
|
11 |
if (( $# != 1 )) ; then |
|
12 |
echo 'usage: newest_matching_file GLOB_PATTERN' >&2 |
|
13 |
return 1 |
|
14 |
fi |
|
15 |
|
|
16 |
# To avoid printing garbage if no files match the pattern, set |
|
17 |
# 'nullglob' if necessary |
|
18 |
local -i need_to_unset_nullglob=0 |
|
19 |
if [[ ":$BASHOPTS:" != *:nullglob:* ]] ; then |
|
20 |
shopt -s nullglob |
|
21 |
need_to_unset_nullglob=1 |
|
22 |
fi |
|
23 |
|
|
24 |
newest_file= |
|
25 |
for file in $glob_pattern ; do |
|
26 |
[[ -z $newest_file || $file -nt $newest_file ]] \ |
|
27 |
&& newest_file=$file |
|
28 |
done |
|
29 |
|
|
30 |
# To avoid unexpected behaviour elsewhere, unset nullglob if it was |
|
31 |
# set by this function |
|
32 |
(( need_to_unset_nullglob )) && shopt -u nullglob |
|
33 |
|
|
34 |
# Use printf instead of echo in case the file name begins with '-' |
|
35 |
[[ -n $newest_file ]] && printf '%s\n' "$newest_file" |
|
36 |
|
|
37 |
return 0 |
|
38 |
} |
|
39 |
|
a45f88
|
40 |
function oldest_matching_file |
C |
41 |
{ |
|
42 |
# Use ${1-} instead of $1 in case 'nounset' is set |
|
43 |
local -r glob_pattern=${1-} |
|
44 |
|
|
45 |
if (( $# != 1 )) ; then |
|
46 |
echo 'usage: oldest_matching_file GLOB_PATTERN' >&2 |
|
47 |
return 1 |
|
48 |
fi |
|
49 |
|
|
50 |
# To avoid printing garbage if no files match the pattern, set |
|
51 |
# 'nullglob' if necessary |
|
52 |
local -i need_to_unset_nullglob=0 |
|
53 |
if [[ ":$BASHOPTS:" != *:nullglob:* ]] ; then |
|
54 |
shopt -s nullglob |
|
55 |
need_to_unset_nullglob=1 |
|
56 |
fi |
|
57 |
|
|
58 |
oldest_file= |
|
59 |
for file in $glob_pattern ; do |
|
60 |
[[ -z $oldest_file || $file -ot $oldest_file ]] \ |
|
61 |
&& oldest_file=$file |
|
62 |
done |
|
63 |
|
|
64 |
# To avoid unexpected behaviour elsewhere, unset nullglob if it was |
|
65 |
# set by this function |
|
66 |
(( need_to_unset_nullglob )) && shopt -u nullglob |
|
67 |
|
|
68 |
# Use printf instead of echo in case the file name begins with '-' |
|
69 |
[[ -n $oldest_file ]] && printf '%s\n' "$oldest_file" |
|
70 |
|
|
71 |
return 0 |
|
72 |
} |
|
73 |
|
99cd84
|
74 |
#update system |
C |
75 |
sudo pacman -Syu --noconfirm |
|
76 |
|
|
77 |
#go to build directory |
48a8a8
|
78 |
cd $(dirname "$(realpath $0)") |
99cd84
|
79 |
|
C |
80 |
#Remove old packages |
7df843
|
81 |
git rm -r x86_64/* |
a45f88
|
82 |
rm -r x86_64 |
7df843
|
83 |
mkdir x86_64 |
48a8a8
|
84 |
|
7df843
|
85 |
#dependencies |
C |
86 |
cd dependencies |
01b1e0
|
87 |
for d in `find . -maxdepth 1 -not -path '*/\.*' -type d` |
00a98f
|
88 |
do |
99cd84
|
89 |
#Only do package directories |
01b1e0
|
90 |
if [ "$d" = "./x86_64" ] || [ "$d" = "." ]; then |
0969d0
|
91 |
continue |
C |
92 |
fi |
00a98f
|
93 |
cd $d |
99cd84
|
94 |
#update package to latest from AUR |
00a98f
|
95 |
git pull |
7df843
|
96 |
makepkg -si --noconfirm |
C |
97 |
latest=$(newest_matching_file '*.pkg.tar.xz') |
a45f88
|
98 |
while [ $NUM_BACK \< $(find . -name "*.pkg.tar.xz" | wc -l) ] |
C |
99 |
do |
|
100 |
oldest=$(oldest_matching_file '*.pkg.tar.xz') |
|
101 |
rm $oldest |
|
102 |
done |
7df843
|
103 |
cd .. |
C |
104 |
ln $d/$latest ../x86_64/$latest |
|
105 |
repo-add ../Chizi123.db.tar.xz ../x86_64/$latest |
|
106 |
done |
|
107 |
cd .. |
|
108 |
|
|
109 |
#main packages |
|
110 |
for d in `find . -maxdepth 1 -not -path '*/\.*' -type d` |
|
111 |
do |
|
112 |
#Only do package directories |
a45f88
|
113 |
if [ "$d" = "./x86_64" ] || [ "$d" = "." ] || [ "$d" = "./dependencies" ]; then |
7df843
|
114 |
continue |
C |
115 |
fi |
|
116 |
cd $d |
|
117 |
#update package to latest from AUR |
|
118 |
git pull |
01b1e0
|
119 |
makepkg -s --noconfirm |
00a98f
|
120 |
latest=$(newest_matching_file '*.pkg.tar.xz') |
a45f88
|
121 |
while [ $NUM_BACK \< $(find . -name "*.pkg.tar.xz" | wc -l) ] |
C |
122 |
do |
|
123 |
oldest=$(oldest_matching_file '*.pkg.tar.xz') |
|
124 |
rm $oldest |
|
125 |
done |
00a98f
|
126 |
cd .. |
99cd84
|
127 |
ln $d/$latest x86_64/$latest |
01b1e0
|
128 |
repo-add ./Chizi123.db.tar.xz x86_64/$latest |
00a98f
|
129 |
done |
C |
130 |
|
99cd84
|
131 |
ln Chizi123.db.tar.xz x86_64/Chizi123.db |
C |
132 |
ln Chizi123.files.tar.xz x86_64/Chizi123.files |
48a8a8
|
133 |
git add x86_64 |
C |
134 |
git commit -m "'$(date +%d/%m/%y-%H:%M)'" |
|
135 |
git push |