OSDN Git Service

[fix] : Fixed debugging code
[alterlinux/alterlinux.git] / system / aur.sh
1 #!/usr/bin/env bash
2 #
3 # Yamada Hayao
4 # Twitter: @Hayao0819
5 # Email  : hayao@fascode.net
6 #
7 # (c) 2019-2021 Fascode Network.
8 #
9 set -e -u
10
11 aur_username="aurbuild"
12
13 # Check yay
14 if ! type -p yay > /dev/null; then
15     echo "yay was not found. Please install it."
16     exit 1
17 fi
18
19
20 # Delete file only if file exists
21 # remove <file1> <file2> ...
22 function remove () {
23     local _list
24     local _file
25     _list=($(echo "$@"))
26     for _file in "${_list[@]}"; do
27         if [[ -f ${_file} ]]; then
28             rm -f "${_file}"
29         elif [[ -d ${_file} ]]; then
30             rm -rf "${_file}"
31         fi
32         echo "${_file} was deleted."
33     done
34 }
35
36 # user_check <name>
37 function user_check () {
38     if [[ $(getent passwd $1 > /dev/null ; printf $?) = 0 ]]; then
39         if [[ -z $1 ]]; then
40             echo -n "false"
41         fi
42         echo -n "true"
43     else
44         echo -n "false"
45     fi
46 }
47
48 # Creating a aur user.
49 if [[ $(user_check ${aur_username}) = false ]]; then
50     useradd -m -d "/aurbuild_temp" "${aur_username}"
51 fi
52 mkdir -p "/aurbuild_temp"
53 chmod 700 -R "/aurbuild_temp"
54 chown ${aur_username}:${aur_username} -R "/aurbuild_temp"
55 echo "${aur_username} ALL=(ALL) NOPASSWD:ALL" > "/etc/sudoers.d/aurbuild"
56
57 # Setup keyring
58 pacman-key --init
59 #eval $(cat "/etc/systemd/system/pacman-init.service" | grep 'ExecStart' | sed "s|ExecStart=||g" )
60 ls "/usr/share/pacman/keyrings/"*".gpg" | sed "s|.gpg||g" | xargs | pacman-key --populate
61
62
63 # Build and install
64 chmod +s /usr/bin/sudo
65 for _pkg in "${@}"; do
66     yes | sudo -u aurbuild \
67         yay -Sy \
68             --mflags "-AcC" \
69             --aur \
70             --noconfirm \
71             --nocleanmenu \
72             --nodiffmenu \
73             --noeditmenu \
74             --noupgrademenu \
75             --noprovides \
76             --removemake \
77             --useask \
78             --color always \
79             --config "/etc/alteriso-pacman.conf" \
80             --cachedir "/var/cache/pacman/pkg/" \
81             "${_pkg}"
82
83     if ! pacman -Qq "${_pkg}" > /dev/null 2>&1; then
84         echo -e "\n[aur.sh] Failed to install ${_pkg}\n"
85         exit 1
86     fi
87 done
88
89 yay -Sccc --noconfirm --config "/etc/alteriso-pacman.conf"
90
91 # remove user and file
92 userdel aurbuild
93 remove /aurbuild_temp
94 remove /etc/sudoers.d/aurbuild
95 remove "/etc/alteriso-pacman.conf"
96 remove "/var/cache/pacman/pkg/"