-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup-pbuilder-repo
executable file
·93 lines (75 loc) · 3.05 KB
/
setup-pbuilder-repo
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
# Setup wrouesnel style pbuilder configuration for quick and easy automatic
# builds.
# See: https://stackoverflow.com/questions/59895/how-to-get-the-source-directory-of-a-bash-script-from-within-the-script-itself
# Note: you can't refactor this out: its at the top of every script so the scripts can find their includes.
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
function log() {
echo "$*" 1>&2
}
function fatal() {
echo "$*" 1>&2
exit 1
}
PBUILDER_REPO="$HOME/pbuilder/repo"
PBUILDER_HOOKS="$HOME/pbuilder/hooks"
PBUILDER_CACHE="$HOME/.cache/pbuilder"
PBUILDER_GPG="$HOME/pbuilder/repo/gpg"
mkdir -p "$PBUILDER_REPO"
mkdir -p "$PBUILDER_HOOKS"
gpg_args=(\
--no-options \
--no-default-keyring \
--homedir "$PBUILDER_GPG" \
--keyring "$PBUILDER_REPO/pbuilder-public.gpg" \
--trustdb-name "$PBUILDER_REPO/trustdb.gpg" \
)
if [ ! -e "$PBUILDER_REPO/pbuilder-public.gpg" ]; then
echo "Generating a key for use as signing..."
gpg "${gpg_args[@]}" --gen-key
fi
echo "Installing the new key as a trusted key in the users keyring..."
gpg "${gpg_args[@]}" \
--export-secret-keys \
--armor | gpg --allow-secret-key-import --import --no-options
echo "Installing $1 as trusted key in apt..."
gpg "${gpg_args[@]}" --export | sudo tee /etc/apt/trusted.gpg.d/pbuilder.gpg >/dev/null
echo "Setting up a trustedkeys.gpg keyring"
echo "Making pbuilder repository directory..."
if ! cp -r pbuilder-repo/* "$PBUILDER_REPO/" ; then
fatal "Error setting up repository base"
fi
echo "Setting up pbuilder hooks..."
mkdir -p "$PBUILDER_HOOKS"
if ! cp -t "$PBUILDER_HOOKS" "${SCRIPT_DIR}/.pbuilder-hooks"/*; then
fatal "Error setting up pbuilder hooks"
fi
echo "Installing .pbuilderrc..."
if ! cp "${SCRIPT_DIR}/.pbuilderrc" "$HOME/.pbuilderrc"; then
fatal "Error setting up pbuilderrc"
fi
echo "Your new pbuilder keys are the following:"
gpg "${gpg_args[@]}" --list-keys
read -r -p "Would you like to install the included .pbuilderrc file? (y/n default NO)" ANSWER
if [[ $ANSWER =~ ^[Yy]$ ]]; then
echo "Installing to $HOME/.pbuilderrc..."
if [ -e "$HOME/.pbuilderrc" ]; then
echo "Backing up existing .pbuilderrc as .pbuilderrc.$(date +%Y%m%d%H%M%S).bak"
mv "$HOME/.pbuilderrc" "$HOME/.pbuilderrc.$(date +%Y%m%d%H%M%S).bak"
fi
cp "${SCRIPT_DIR}/.pbuilderrc" "$HOME/.pbuilderrc" || fatal "Could not copy .pbuilderrc"
fi
log "Installing the pbuilder override command to ensure correct execution"
if ! cp -f "${SCRIPT_DIR}/pbuilder" "$HOME/bin/pbuilder"; then
fatal "Failed to copy local pbuilder command"
fi
if ! chmod +x "$HOME/bin/pbuilder"; then
fatal "Failed to make local pbuilder command executable"
fi
exit 0