OSDN Git Service

Merge remote-tracking branch 'origin/dev' into alteriso-3-check-mkalteriso
[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-2020 Fascode Network.
8 #
9 set -e -u
10
11 aur_username="aurbuild"
12
13
14 # Delete file only if file exists
15 # remove <file1> <file2> ...
16 function remove () {
17     local _list
18     local _file
19     _list=($(echo "$@"))
20     for _file in "${_list[@]}"; do
21         if [[ -f ${_file} ]]; then
22             rm -f "${_file}"
23         elif [[ -d ${_file} ]]; then
24             rm -rf "${_file}"
25         fi
26         echo "${_file} was deleted."
27     done
28 }
29
30 # user_check <name>
31 function user_check () {
32     if [[ $(getent passwd $1 > /dev/null ; printf $?) = 0 ]]; then
33         if [[ -z $1 ]]; then
34             echo -n "false"
35         fi
36         echo -n "true"
37     else
38         echo -n "false"
39     fi
40 }
41
42 # Creating a aur user.
43 if [[ $(user_check ${aur_username}) = false ]]; then
44     useradd -m -d "/aurbuild_temp" "${aur_username}"
45 fi
46 mkdir -p "/aurbuild_temp"
47 chmod 700 -R "/aurbuild_temp"
48 chown ${aur_username}:${aur_username} -R "/aurbuild_temp"
49 echo "${aur_username} ALL=(ALL) NOPASSWD:ALL" > "/etc/sudoers.d/aurbuild"
50
51 # Setup keyring
52 pacman-key --init
53 #eval $(cat "/etc/systemd/system/pacman-init.service" | grep 'ExecStart' | sed "s|ExecStart=||g" )
54 ls "/usr/share/pacman/keyrings/"*".gpg" | sed "s|.gpg||g" | xargs | pacman-key --populate
55
56
57 # Build and install
58 chmod +s /usr/bin/sudo
59 yes | sudo -u aurbuild \
60     yay -Sy \
61         --mflags "-AcC" \
62         --aur \
63         --noconfirm \
64         --nocleanmenu \
65         --nodiffmenu \
66         --noeditmenu \
67         --noupgrademenu \
68         --noprovides \
69         --removemake \
70         --useask \
71         --color always \
72         --config "/etc/alteriso-pacman.conf" \
73         --cachedir "/var/cache/pacman/pkg/" \
74         ${*}
75
76
77 # remove user and file
78 userdel aurbuild
79 remove /aurbuild_temp
80 remove /etc/sudoers.d/aurbuild
81 remove "/etc/alteriso-pacman.conf"
82 remove "/var/cache/pacman/pkg/"
83
84 yay -Sccc --noconfirm --config "/etc/alteriso-pacman.conf"