5 # Email : hayao@fascode.net
7 # (c) 2019-2021 Fascode Network.
11 aur_username="aurbuild"
16 aur_helper_depends=("go")
19 trap 'exit 1' 1 2 3 15
22 echo "usage ${0} [option]"
24 echo "Install aur packages with ${aur_helper}"
26 echo " General options:"
27 echo " -d Enable pacman debug message"
28 echo " -u [user] Set the user name to build packages"
29 echo " -x Enable bash debug message"
30 echo " -h This help message"
33 while getopts "du:xh" arg; do
35 d) pacman_debug=true ;;
36 u) aur_username="${OPTARG}" ;;
49 shift "$((OPTIND - 1))"
51 # Show message when file is removed
52 # remove <file> <file> ...
55 for _file in "${@}"; do echo "Removing ${_file}" >&2; rm -rf "${_file}"; done
59 function user_check () {
60 if [[ ! -v 1 ]]; then return 2; fi
61 getent passwd "${1}" > /dev/null
64 # Creating a aur user.
65 if ! user_check "${aur_username}"; then
66 useradd -m -d "/aurbuild_temp" "${aur_username}"
68 mkdir -p "/aurbuild_temp"
69 chmod 700 -R "/aurbuild_temp"
70 chown "${aur_username}:${aur_username}" -R "/aurbuild_temp"
71 echo "${aur_username} ALL=(ALL) NOPASSWD:ALL" > "/etc/sudoers.d/aurbuild"
77 # Un comment the mirror list.
78 #sed -i "s/#Server/Server/g" "/etc/pacman.d/mirrorlist"
81 pacman_args=("--config" "/etc/alteriso-pacman.conf" "--noconfirm")
82 if [[ "${pacman_debug}" = true ]]; then
83 pacman_args+=("--debug")
87 if ! pacman -Qq "${aur_helper}" 1> /dev/null 2>&1; then
90 pacman -Syy "${pacman_args[@]}"
93 for _pkg in "${aur_helper_depends[@]}"; do
94 if ! pacman -Qq "${_pkg}" > /dev/null 2>&1 | grep -q "${_pkg}"; then
95 # --asdepsをつけているのでaur.shで削除される --neededをつけているので明示的にインストールされている場合削除されない
96 pacman -S --asdeps --needed "${pacman_args[@]}" "${_pkg}"
97 remove_list+=("${_pkg}")
102 sudo -u "${aur_username}" git clone "https://aur.archlinux.org/${aur_helper}.git" "/tmp/${aur_helper}"
103 cd "/tmp/${aur_helper}"
104 sudo -u "${aur_username}" makepkg --ignorearch --clean --cleanbuild --force --skippgpcheck --noconfirm
107 for _pkg in $(sudo -u "${aur_username}" makepkg --packagelist); do
108 pacman "${pacman_args[@]}" -U "${_pkg}"
113 remove "/tmp/${aur_helper}"
117 if ! type -p "${aur_helper}" > /dev/null; then
118 echo "Failed to install ${aur_helper}"
123 yes | sudo -u "${aur_username}" \
124 "${aur_helper}" -Sy \
135 --mflags "--skippgpcheck" \
136 "${pacman_args[@]}" \
137 --cachedir "/var/cache/pacman/pkg/" \
143 chmod +s /usr/bin/sudo
144 for _pkg in "${@}"; do
145 pacman -Qq "${_pkg}" > /dev/null 2>&1 && continue
148 if ! pacman -Qq "${_pkg}" > /dev/null 2>&1; then
149 echo -e "\n[aur.sh] Failed to install ${_pkg}\n"
150 failedpkg+=("${_pkg}")
154 # Reinstall failed package
155 for _pkg in "${failedpkg[@]}"; do
157 if ! pacman -Qq "${_pkg}" > /dev/null 2>&1; then
158 echo -e "\n[aur.sh] Failed to install ${_pkg}\n"
164 readarray -t -O "${#remove_list[@]}" remove_list < <(pacman -Qttdq)
165 (( "${#remove_list[@]}" != 0 )) && pacman -Rsnc "${remove_list[@]}" "${pacman_args[@]}"
168 "${aur_helper}" -Sccc "${pacman_args[@]}"
170 # remove user and file
171 userdel "${aur_username}"
172 remove /aurbuild_temp
173 remove /etc/sudoers.d/aurbuild
174 remove "/etc/alteriso-pacman.conf"
175 remove "/var/cache/pacman/pkg/"