OSDN Git Service

[fix] : Fixed makepkg dir permission
[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 # Delete file only if file exists
14 # remove <file1> <file2> ...
15 function remove () {
16     local _list
17     local _file
18     _list=($(echo "$@"))
19     for _file in "${_list[@]}"; do
20         if [[ -f ${_file} ]]; then
21             rm -f "${_file}"
22         elif [[ -d ${_file} ]]; then
23             rm -rf "${_file}"
24         fi
25         echo "${_file} was deleted."
26     done
27 }
28
29 # user_check <name>
30 function user_check () {
31     if [[ $(getent passwd $1 > /dev/null ; printf $?) = 0 ]]; then
32         if [[ -z $1 ]]; then
33             echo -n "false"
34         fi
35         echo -n "true"
36     else
37         echo -n "false"
38     fi
39 }
40
41 # Creating a aur user.
42 if [[ $(user_check ${aur_username}) = false ]]; then
43     useradd -m -d "/aurbuild_temp" "${aur_username}"
44 fi
45 mkdir -p "/aurbuild_temp"
46 chmod 700 -R "/aurbuild_temp"
47 chown ${aur_username}:${aur_username} -R "/aurbuild_temp"
48 echo "${aur_username} ALL=(ALL) NOPASSWD:ALL" > "/etc/sudoers.d/aurbuild"
49
50 # Setup keyring
51 pacman-key --init
52 #eval $(cat "/etc/systemd/system/pacman-init.service" | grep 'ExecStart' | sed "s|ExecStart=||g" )
53 ls "/usr/share/pacman/keyrings/"*".gpg" | sed "s|.gpg||g" | xargs | pacman-key --populate
54
55 # Un comment the mirror list.
56 sed -i "s/#Server/Server/g" "/etc/pacman.d/mirrorlist"
57
58 # Install yay
59 (
60     _oldpwd="$(pwd)"
61     pacman -Syy --noconfirm
62     pacman --noconfirm -S --asdeps --needed go
63     sudo -u aurbuild git clone "https://aur.archlinux.org/yay.git" "/tmp/yay"
64     cd "/tmp/yay"
65     sudo -u aurbuild makepkg --ignorearch --clean --cleanbuild --force --skippgpcheck --install
66     cd ..
67     rm -rf "/tmp/yay"
68     cd "${_oldpwd}"
69 )
70
71 if ! type -p yay > /dev/null; then
72     echo "Failed to install yay"
73     exit 1
74 fi
75
76
77 # Build and install
78 chmod +s /usr/bin/sudo
79 for _pkg in "${@}"; do
80     yes | sudo -u aurbuild \
81         yay -Sy \
82             --mflags "-AcC" \
83             --aur \
84             --noconfirm \
85             --nocleanmenu \
86             --nodiffmenu \
87             --noeditmenu \
88             --noupgrademenu \
89             --noprovides \
90             --removemake \
91             --useask \
92             --color always \
93             --config "/etc/alteriso-pacman.conf" \
94             --cachedir "/var/cache/pacman/pkg/" \
95             "${_pkg}"
96
97     if ! pacman -Qq "${_pkg}" > /dev/null 2>&1; then
98         echo -e "\n[aur.sh] Failed to install ${_pkg}\n"
99         exit 1
100     fi
101 done
102
103 yay -Sccc --noconfirm --config "/etc/alteriso-pacman.conf"
104
105 # remove user and file
106 userdel aurbuild
107 remove /aurbuild_temp
108 remove /etc/sudoers.d/aurbuild
109 remove "/etc/alteriso-pacman.conf"
110 remove "/var/cache/pacman/pkg/"