5 # Email : hayao@fascode.net
7 # (c) 2019-2021 Fascode Network.
9 #shellcheck disable=SC2001
13 aur_username="aurbuild"
18 aur_helper_depends=("go")
19 aur_helper_command="yay"
20 aur_helper_package="yay"
24 trap 'exit 1' 1 2 3 15
27 echo "usage ${0} [option] [aur helper args] ..."
29 echo "Install aur packages with ${aur_helper_command}"
31 echo " General options:"
32 echo " -a [command] Set the command of aur helper"
33 echo " -c Enable pacman debug message"
34 echo " -e [pkg] Set the package name of aur helper"
35 echo " -d [pkg1,pkg2...] Set the oackage of the depends of aur helper"
36 echo " -p [pkg1,pkg2...] Set the AUR package to install"
37 echo " -u [user] Set the user name to build packages"
38 echo " -x Enable bash debug message"
39 echo " -h This help message"
42 while getopts "a:cd:e:p:u:xh" arg; do
44 a) aur_helper_command="${OPTARG}" ;;
45 c) pacman_debug=true ;;
46 e) aur_helper_package="${OPTARG}" ;;
47 p) readarray -t pkglist < <(sed "s|,$||g" <<< "${OPTARG}" | tr "," "\n") ;;
48 d) readarray -t aur_helper_depends < <(sed "s|,$||g" <<< "${OPTARG}" | tr "," "\n") ;;
49 u) aur_username="${OPTARG}" ;;
62 shift "$((OPTIND - 1))"
63 aur_helper_args=("${@}")
64 eval set -- "${pkglist[@]}"
66 # Show message when file is removed
67 # remove <file> <file> ...
70 for _file in "${@}"; do echo "Removing ${_file}" >&2; rm -rf "${_file}"; done
74 function user_check () {
75 if [[ ! -v 1 ]]; then return 2; fi
76 getent passwd "${1}" > /dev/null
79 # Creating a aur user.
80 if ! user_check "${aur_username}"; then
81 useradd -m -d "/aurbuild_temp" "${aur_username}"
83 mkdir -p "/aurbuild_temp"
84 chmod 700 -R "/aurbuild_temp"
85 chown "${aur_username}:${aur_username}" -R "/aurbuild_temp"
86 echo "${aur_username} ALL=(ALL) NOPASSWD:ALL" > "/etc/sudoers.d/aurbuild"
92 # Un comment the mirror list.
93 #sed -i "s/#Server/Server/g" "/etc/pacman.d/mirrorlist"
96 pacman_args=("--config" "/etc/alteriso-pacman.conf" "--noconfirm")
97 if [[ "${pacman_debug}" = true ]]; then
98 pacman_args+=("--debug")
102 if ! pacman -Qq "${aur_helper_package}" 1> /dev/null 2>&1; then
105 pacman -Syy "${pacman_args[@]}"
108 for _pkg in "${aur_helper_depends[@]}"; do
109 if ! pacman -Qq "${_pkg}" > /dev/null 2>&1 | grep -q "${_pkg}"; then
110 # --asdepsをつけているのでaur.shで削除される --neededをつけているので明示的にインストールされている場合削除されない
111 pacman -S --asdeps --needed "${pacman_args[@]}" "${_pkg}"
112 #remove_list+=("${_pkg}")
117 sudo -u "${aur_username}" git clone "https://aur.archlinux.org/${aur_helper_package}.git" "/tmp/${aur_helper_package}"
118 cd "/tmp/${aur_helper_package}"
119 sudo -u "${aur_username}" makepkg --ignorearch --clean --cleanbuild --force --skippgpcheck --noconfirm
122 for _pkg in $(sudo -u "${aur_username}" makepkg --packagelist); do
123 pacman "${pacman_args[@]}" -U "${_pkg}"
128 remove "/tmp/${aur_helper_package}"
132 if ! type -p "${aur_helper_command}" > /dev/null; then
133 echo "Failed to install ${aur_helper_package}"
138 yes | sudo -u "${aur_username}" \
139 "${aur_helper_command}" -Sy \
141 --cachedir "/var/cache/pacman/pkg/" \
142 "${pacman_args[@]}" \
143 "${aur_helper_args[@]}" \
149 chmod +s /usr/bin/sudo
150 for _pkg in "${@}"; do
151 pacman -Qq "${_pkg}" > /dev/null 2>&1 && continue
154 if ! pacman -Qq "${_pkg}" > /dev/null 2>&1; then
155 echo -e "\n[aur.sh] Failed to install ${_pkg}\n"
156 failedpkg+=("${_pkg}")
160 # Reinstall failed package
161 for _pkg in "${failedpkg[@]}"; do
163 if ! pacman -Qq "${_pkg}" > /dev/null 2>&1; then
164 echo -e "\n[aur.sh] Failed to install ${_pkg}\n"
170 readarray -t -O "${#remove_list[@]}" remove_list < <(pacman -Qttdq)
171 (( "${#remove_list[@]}" != 0 )) && pacman -Rsnc "${remove_list[@]}" "${pacman_args[@]}"
174 "${aur_helper_command}" -Sccc "${pacman_args[@]}"
176 # remove user and file
177 userdel "${aur_username}"
178 remove /aurbuild_temp
179 remove /etc/sudoers.d/aurbuild
180 remove "/etc/alteriso-pacman.conf"
181 remove "/var/cache/pacman/pkg/"