5 # Email : hayao@fascode.net
7 # (c) 2019-2021 Fascode Network.
11 # Script to import Alter Linux and ArchLinux keys.
17 script_path="$( cd -P "$( dirname "$(readlink -f "$0")" )" && cd .. && pwd )"
19 archlinux32_repo="http://mirror.juniorjpdj.pl/archlinux32/i486/core/"
21 # Set pacman.conf when build alterlinux
22 alter_pacman_conf_x86_64="${script_path}/system/pacman-x86_64.conf"
23 alter_pacman_conf_i686="${script_path}/system/pacman-i686.conf"
25 # Message common function
26 # msg_common [type] [-n] [string]
28 local _msg_opts=("-a" "keyring.sh") _type="${1}"
30 [[ "${1}" = "-n" ]] && _msg_opts+=("-o" "-n") && shift 1
31 _msg_opts+=("${_type}" "${@}")
32 "${script_path}/tools/msg.sh" "${_msg_opts[@]}"
35 # Show an INFO message
36 # ${1}: message string
37 msg_info() { msg_common info "${@}"; }
39 # Show an Warning message
40 # ${1}: message string
41 msg_warn() { msg_common warn "${@}"; }
43 # Show an ERROR message then exit with status
44 # ${1}: message string
45 # ${2}: exit code number (with 0 does not exit)
47 msg_common error "${1}"
48 [[ -n "${2:-}" ]] && exit "${2}"
52 # Usage: getclm <number>
53 # 標準入力から値を受けとり、引数で指定された列を抽出します。
54 getclm() { cut -d " " -f "${1}"; }
59 echo "usage ${0} [options]"
61 echo " General options:"
62 echo " -a | --alter-add Add alterlinux-keyring."
63 echo " -r | --alter-remove Remove alterlinux-keyring."
64 echo " -c | --arch-add Add archlinux-keyring."
65 echo " -h | --help Show this help and exit."
66 echo " -l | --arch32-add Add archlinux32-keyring."
67 echo " -i | --arch32-remove Remove archlinux32-keyring."
72 # Check if the package is installed.
75 _pkg=$(echo "${1}" | cut -d'/' -f2)
77 if [[ ${#} -gt 2 ]]; then
78 msg_error "Multiple package specification is not available."
81 if [[ -n $( pacman -Q "${_pkg}" 2> /dev/null| getclm 1 ) ]]; then
90 msg_info "Running ${*}"
96 if [[ ! ${UID} = 0 ]]; then
97 msg_error "You dont have root permission."
98 msg_error 'Please run as root.'
102 if [[ ! -f "${alter_pacman_conf_x86_64}" ]]; then
103 msg_error "${alter_pacman_conf_x86_64} does not exist."
107 if [[ ! -f "${alter_pacman_conf_i686}" ]]; then
108 msg_error "${alter_pacman_conf_i686} does not exist."
112 pacman -Sc --noconfirm > /dev/null 2>&1
118 pacman-key --refresh-keys
120 pacman-key --populate archlinux
121 pacman -Sy --noconfirm core/archlinux-keyring
123 pacman-key --populate archlinux
128 curl -Lo - "http://repo.dyama.net/fascode.pub" \
130 pacman-key --lsign-key development@fascode.net
132 pacman --config "${alter_pacman_conf_x86_64}" -Sy --noconfirm alter-stable/alterlinux-keyring
135 pacman-key --populate alterlinux
140 pacman-key -d BDC396346243AB57ACD090F9F50544048389DA36
141 if checkpkg alterlinux-keyring; then
142 pacman -Rsnc --noconfirm alterlinux-keyring
146 update_arch32_key() {
147 ! pacman -Ssq archlinux32-keyring | grep -x archlinux32-keyring 2> /dev/null 1>&2 && msg_error "Not found archlinux32-keyring on remote repository. You should install it manually." 1
148 pacman --noconfirm -S archlinux32-keyring
150 pacman-key --populate archlinux32
151 #pacman-key --refresh-keys
154 new_update_arch32_key(){
155 local _savedir="${HOME}/.cache"
156 while read -r _pkg ; do
157 curl -o "${_savedir}/${_pkg}" "${archlinux32_repo}/${_pkg}"
158 pacman -U --noconfirm "${_savedir}/${_pkg}"
159 rm -f "${_savedir}/${_pkg}"
160 done < <(curl -sL "${archlinux32_repo}" | sed "s|<a href=\"||g" | cut -d "\"" -f 1 | grep -v "^<" | grep -v ".sig$" | grep ".pkg.tar." | grep "archlinux32-keyring" | grep -v "archlinux32-keyring-transition")
162 pacman-key --populate archlinux32
165 remove_arch32_key() {
166 pacman -Rsnc archlinux32-keyring
171 while getopts 'archli-:' arg; do
195 run update_arch32_key
200 run remove_arch32_key
221 run update_arch32_key
225 run remove_arch32_key
238 if [[ ${#} = 0 ]]; then
240 # run update_arch_key
242 run update_arch32_key