mirror of https://github.com/Chizi123/Arch-autobuild-repo.git

Chizi123
2019-08-22 36fa7ee6e8ccd576e6c480aa9fba6eb5844107fa
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
990bd0 81 #git rm -r x86_64/*
JG 82 #rm -r x86_64
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
990bd0 97     if [ $? = 0 ]; then
JG 98         latest=$(newest_matching_file '*.pkg.tar.xz')
99         while [ $NUM_BACK \< $(find . -name "*.pkg.tar.xz" | wc -l) ]
100         do
101             oldest=$(oldest_matching_file '*.pkg.tar.xz')
102             rm $oldest
103         done
104         cd ..
105         rm ../x86_64/"$d"*".pkg.tar.xz"
106         ln $d/$latest ../x86_64/$latest
107     else
108         cd ..
109     fi
110     #    repo-add ../Chizi123.db.tar.xz ../x86_64/$latest
7df843 111 done
C 112 cd ..
113
114 #main packages
115 for d in `find . -maxdepth 1 -not -path '*/\.*' -type d`
116 do
117     #Only do package directories
a45f88 118     if [ "$d" = "./x86_64" ] || [ "$d" = "." ] || [ "$d" = "./dependencies" ]; then
7df843 119         continue
C 120     fi
121     cd $d
122     #update package to latest from AUR
123     git pull
01b1e0 124     makepkg -s --noconfirm
990bd0 125     if [ $? = 0 ]; then
JG 126         latest=$(newest_matching_file '*.pkg.tar.xz')
127         while [ $NUM_BACK \< $(find . -name "*.pkg.tar.xz" | wc -l) ]
128         do
129             oldest=$(oldest_matching_file '*.pkg.tar.xz')
130             rm $oldest
131         done
132         cd ..
133         rm x86_64/"$d"*".pkg.tar.xz"
134         ln $d/$latest x86_64/$latest
135     else
136         cd ..
137     fi
138     #    repo-add ./Chizi123.db.tar.xz x86_64/$latest
00a98f 139 done
C 140
990bd0 141 repo-add Chizi123.db.tar.xz x86_64/*
99cd84 142 ln Chizi123.db.tar.xz x86_64/Chizi123.db
C 143 ln Chizi123.files.tar.xz x86_64/Chizi123.files
48a8a8 144 git add x86_64
C 145 git commit -m "'$(date +%d/%m/%y-%H:%M)'"
146 git push