summarylogtreecommitdiffstats
path: root/chaotic-keyring.install
blob: f7fc5b9d87f468c1dd1b781feefcdfad37a190c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

## copy from pacman-key
_msg() {
        (( QUIET )) && return
        local mesg=$1; shift
        printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&1
}


_error() {
        local mesg=$1; shift
        printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
}

_get_from() {
        while IFS='=' read -r key value; do
                [[ -z $key || ${key:0:1} = '#' ]] && continue

                if [[ ${key%% *} = "$2" && -n ${value##* } ]]; then
                        echo "${value##* }"
                        return 0
                fi
        done < "$1"
        if [[ -n "$3" ]]; then
                printf '%s\n' "$3"
                return 0
        fi
        return 1
}

CONFIG=${CONFIG:-/etc/pacman.conf}
PACMAN_KEYRING_DIR=${PACMAN_KEYRING_DIR:-$(_get_from "$CONFIG" "GPGDir" "/etc/pacman.d/gnupg")}
GPG_PACMAN=(gpg --homedir "${PACMAN_KEYRING_DIR}" --no-permission-warning)


post_upgrade() {
        if usr/bin/pacman-key -l >/dev/null 2>&1; then
                usr/bin/pacman-key --populate chaotic

                ## needed for https://github.com/archlinuxcn/repo/issues/300
                _msg "$(gettext "Updating trust database...")"
                if ! "${GPG_PACMAN[@]}" --batch --check-trustdb --yes ; then
                        _error "$(gettext "Trust database could not be updated.")"
                        exit 1
                fi
        fi
    if (usr/bin/grep -A3 "[^#]*\[chaotic-aur\]" /etc/pacman.conf | grep "TrustAll" >/dev/null 2>&1); then
        _error 'Please remove the SigLevel= line of [chaotic-aur] from "/etc/pacman.conf" to use the default setting'
        _error '请删除 /etc/pacman.conf 中 [chaotic-aur] 下的 SigLevel= 行,以使用默认设置'
    fi  
}

post_install() {
        if [ -x usr/bin/pacman-key ]; then
                post_upgrade
        fi
}