@@ -11,6 +11,9 @@ set -e -u
1111aur_username=" aurbuild"
1212pacman_debug=false
1313pacman_args=()
14+ failedpkg=()
15+ remove_list=()
16+ yay_depends=(" go" )
1417
1518trap ' exit 1' 1 2 3 15
1619
8184
8285# Install yay
8386if ! pacman -Qq yay 1> /dev/null 2>&1 ; then
84- (
85- _oldpwd=" $( pwd) "
86- pacman -Syy " ${pacman_args[@]} "
87- pacman -S --asdeps --needed " ${pacman_args[@]} " go
88- sudo -u " ${aur_username} " git clone " https://aur.archlinux.org/yay.git" " /tmp/yay"
89- cd " /tmp/yay"
90- sudo -u " ${aur_username} " makepkg --ignorearch --clean --cleanbuild --force --skippgpcheck --noconfirm
91- for _pkg in $( sudo -u " ${aur_username} " makepkg --packagelist) ; do
92- pacman " ${pacman_args[@]} " -U " ${_pkg} "
93- done
94- cd ..
95- remove " /tmp/yay"
96- cd " ${_oldpwd} "
97- )
87+ # Update database
88+ _oldpwd=" $( pwd) "
89+ pacman -Syy " ${pacman_args[@]} "
90+
91+ # Install depends
92+ for _pkg in " ${yay_depends[@]} " ; do
93+ if ! pacman -Qq " ${_pkg} " | grep -q " ${_pkg} " ; then
94+ pacman -S --asdeps --needed " ${pacman_args[@]} " " ${_pkg} "
95+ remove_list+=(" ${_pkg} " )
96+ fi
97+ done
98+
99+ # Build yay
100+ sudo -u " ${aur_username} " git clone " https://aur.archlinux.org/yay.git" " /tmp/yay"
101+ cd " /tmp/yay"
102+ sudo -u " ${aur_username} " makepkg --ignorearch --clean --cleanbuild --force --skippgpcheck --noconfirm
103+
104+ # Install yay
105+ for _pkg in $( sudo -u " ${aur_username} " makepkg --packagelist) ; do
106+ pacman " ${pacman_args[@]} " -U " ${_pkg} "
107+ done
108+
109+ # Remove debtis
110+ cd ..
111+ remove " /tmp/yay"
112+ cd " ${_oldpwd} "
98113fi
99114
100115if ! type -p yay > /dev/null; then
101116 echo " Failed to install yay"
102117 exit 1
103118fi
104119
105-
106- # Build and install
107- chmod +s /usr/bin/sudo
108- for _pkg in " ${@ } " ; do
120+ installpkg (){
109121 yes | sudo -u " ${aur_username} " \
110122 yay -Sy \
111123 --mflags " -AcC" \
@@ -121,14 +133,36 @@ for _pkg in "${@}"; do
121133 --mflags " --skippgpcheck" \
122134 " ${pacman_args[@]} " \
123135 --cachedir " /var/cache/pacman/pkg/" \
124- " ${_pkg} "
136+ " ${@ } " || true
137+ }
138+
139+
140+ # Build and install
141+ chmod +s /usr/bin/sudo
142+ for _pkg in " ${@ } " ; do
143+ pacman -Qq " ${_pkg} " > /dev/null 2>&1 && continue
144+ installpkg " ${_pkg} "
145+
146+ if ! pacman -Qq " ${_pkg} " > /dev/null 2>&1 ; then
147+ echo -e " \n[aur.sh] Failed to install ${_pkg} \n"
148+ failedpkg+=(" ${_pkg} " )
149+ fi
150+ done
125151
152+ # Reinstall failed package
153+ for _pkg in " ${failedpkg[@]} " ; do
154+ installpkg " ${_pkg} "
126155 if ! pacman -Qq " ${_pkg} " > /dev/null 2>&1 ; then
127156 echo -e " \n[aur.sh] Failed to install ${_pkg} \n"
128157 exit 1
129158 fi
130159done
131160
161+ # Remove packages
162+ readarray -t -O " ${# remove_list[@]} " remove_list < <( pacman -Qttdq)
163+ (( "${# remove_list[@]} " != 0 )) && pacman -Rsnc " ${remove_list[@]} " " ${pacman_args[@]} "
164+
165+ # Clean up
132166yay -Sccc " ${pacman_args[@]} "
133167
134168# remove user and file
0 commit comments