OSDN Git Service

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