5 # Email : hayao@fascode.net
7 # (c) 2019-2021 Fascode Network.
11 aur_username="aurbuild"
15 trap 'exit 1' 1 2 3 15
18 echo "usage ${0} [option]"
20 echo "Install aur packages with yay"
22 echo " General options:"
23 echo " -d Enable pacman debug message"
24 echo " -u [user] Set the user name to build packages"
25 echo " -x Enable bash debug message"
26 echo " -h This help message"
29 while getopts "du:xh" arg; do
31 d) pacman_debug=true ;;
32 u) aur_username="${OPTARG}" ;;
45 shift "$((OPTIND - 1))"
47 # Show message when file is removed
48 # remove <file> <file> ...
51 for _file in "${@}"; do echo "Removing ${_file}" >&2; rm -rf "${_file}"; done
55 function user_check () {
56 if [[ ! -v 1 ]]; then return 2; fi
57 getent passwd "${1}" > /dev/null
60 # Creating a aur user.
61 if ! user_check "${aur_username}"; then
62 useradd -m -d "/aurbuild_temp" "${aur_username}"
64 mkdir -p "/aurbuild_temp"
65 chmod 700 -R "/aurbuild_temp"
66 chown "${aur_username}:${aur_username}" -R "/aurbuild_temp"
67 echo "${aur_username} ALL=(ALL) NOPASSWD:ALL" > "/etc/sudoers.d/aurbuild"
73 # Un comment the mirror list.
74 #sed -i "s/#Server/Server/g" "/etc/pacman.d/mirrorlist"
77 pacman_args=("--config" "/etc/alteriso-pacman.conf" "--noconfirm")
78 if [[ "${pacman_debug}" = true ]]; then
79 pacman_args+=("--debug")
83 if ! pacman -Qq yay 1> /dev/null 2>&1; then
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"
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}"
100 if ! type -p yay > /dev/null; then
101 echo "Failed to install yay"
107 chmod +s /usr/bin/sudo
108 for _pkg in "${@}"; do
109 yes | sudo -u "${aur_username}" \
121 --mflags "--skippgpcheck" \
122 "${pacman_args[@]}" \
123 --cachedir "/var/cache/pacman/pkg/" \
126 if ! pacman -Qq "${_pkg}" > /dev/null 2>&1; then
127 echo -e "\n[aur.sh] Failed to install ${_pkg}\n"
132 yay -Sccc "${pacman_args[@]}"
134 # remove user and file
135 userdel "${aur_username}"
136 remove /aurbuild_temp
137 remove /etc/sudoers.d/aurbuild
138 remove "/etc/alteriso-pacman.conf"
139 remove "/var/cache/pacman/pkg/"