5 # Email : hayao@fascode.net
7 # (c) 2019-2021 Fascode Network.
11 aur_username="aurbuild"
18 trap 'exit 1' 1 2 3 15
21 echo "usage ${0} [option]"
23 echo "Install aur packages with yay"
25 echo " General options:"
26 echo " -d Enable pacman debug message"
27 echo " -u [user] Set the user name to build packages"
28 echo " -x Enable bash debug message"
29 echo " -h This help message"
32 while getopts "du:xh" arg; do
34 d) pacman_debug=true ;;
35 u) aur_username="${OPTARG}" ;;
48 shift "$((OPTIND - 1))"
50 # Show message when file is removed
51 # remove <file> <file> ...
54 for _file in "${@}"; do echo "Removing ${_file}" >&2; rm -rf "${_file}"; done
58 function user_check () {
59 if [[ ! -v 1 ]]; then return 2; fi
60 getent passwd "${1}" > /dev/null
63 # Creating a aur user.
64 if ! user_check "${aur_username}"; then
65 useradd -m -d "/aurbuild_temp" "${aur_username}"
67 mkdir -p "/aurbuild_temp"
68 chmod 700 -R "/aurbuild_temp"
69 chown "${aur_username}:${aur_username}" -R "/aurbuild_temp"
70 echo "${aur_username} ALL=(ALL) NOPASSWD:ALL" > "/etc/sudoers.d/aurbuild"
76 # Un comment the mirror list.
77 #sed -i "s/#Server/Server/g" "/etc/pacman.d/mirrorlist"
80 pacman_args=("--config" "/etc/alteriso-pacman.conf" "--noconfirm")
81 if [[ "${pacman_debug}" = true ]]; then
82 pacman_args+=("--debug")
86 if ! pacman -Qq yay 1> /dev/null 2>&1; then
89 pacman -Syy "${pacman_args[@]}"
92 for _pkg in "${yay_depends[@]}"; do
93 if ! pacman -Qq "${_pkg}" > /dev/null 2>&1 | grep -q "${_pkg}"; then
94 pacman -S --asdeps --needed "${pacman_args[@]}" "${_pkg}"
95 remove_list+=("${_pkg}")
100 sudo -u "${aur_username}" git clone "https://aur.archlinux.org/yay.git" "/tmp/yay"
102 sudo -u "${aur_username}" makepkg --ignorearch --clean --cleanbuild --force --skippgpcheck --noconfirm
105 for _pkg in $(sudo -u "${aur_username}" makepkg --packagelist); do
106 pacman "${pacman_args[@]}" -U "${_pkg}"
115 if ! type -p yay > /dev/null; then
116 echo "Failed to install yay"
121 yes | sudo -u "${aur_username}" \
133 --mflags "--skippgpcheck" \
134 "${pacman_args[@]}" \
135 --cachedir "/var/cache/pacman/pkg/" \
141 chmod +s /usr/bin/sudo
142 for _pkg in "${@}"; do
143 pacman -Qq "${_pkg}" > /dev/null 2>&1 && continue
146 if ! pacman -Qq "${_pkg}" > /dev/null 2>&1; then
147 echo -e "\n[aur.sh] Failed to install ${_pkg}\n"
148 failedpkg+=("${_pkg}")
152 # Reinstall failed package
153 for _pkg in "${failedpkg[@]}"; do
155 if ! pacman -Qq "${_pkg}" > /dev/null 2>&1; then
156 echo -e "\n[aur.sh] Failed to install ${_pkg}\n"
162 readarray -t -O "${#remove_list[@]}" remove_list < <(pacman -Qttdq)
163 (( "${#remove_list[@]}" != 0 )) && pacman -Rsnc "${remove_list[@]}" "${pacman_args[@]}"
166 yay -Sccc "${pacman_args[@]}"
168 # remove user and file
169 userdel "${aur_username}"
170 remove /aurbuild_temp
171 remove /etc/sudoers.d/aurbuild
172 remove "/etc/alteriso-pacman.conf"
173 remove "/var/cache/pacman/pkg/"