OSDN Git Service

Merge branch 'alteriso-3.1' into dev
[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 yes | sudo -u aurbuild \
66     yay -Sy \
67         --mflags "-AcC" \
68         --aur \
69         --noconfirm \
70         --nocleanmenu \
71         --nodiffmenu \
72         --noeditmenu \
73         --noupgrademenu \
74         --noprovides \
75         --removemake \
76         --useask \
77         --color always \
78         --config "/etc/alteriso-pacman.conf" \
79         --cachedir "/var/cache/pacman/pkg/" \
80         ${*}
81
82 yay -Sccc --noconfirm --config "/etc/alteriso-pacman.conf"
83
84 # remove user and file
85 userdel aurbuild
86 remove /aurbuild_temp
87 remove /etc/sudoers.d/aurbuild
88 remove "/etc/alteriso-pacman.conf"
89 remove "/var/cache/pacman/pkg/"