-
Notifications
You must be signed in to change notification settings - Fork 0
/
archbootstrap
executable file
·100 lines (84 loc) · 1.98 KB
/
archbootstrap
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
94
95
96
97
98
99
100
#!/bin/sh
usage() {
cat <<EOF
usage: archbootstrap [options] root
-a <arch>
-c <cachedir>
-h help
-i show post-install ideas
-m <mirror>
-n no-cache
EOF
}
is_root() {
[ "$(id -u)" = '0' ]
}
use_cache() {
[ "$no_cache" != 'true' ]
}
show_ideas() {
[ "$ideas" = 'true' ]
}
cleanup() {
# delete cache directory if it is a tempdir
if ! use_cache; then
if [ -d "$cachedir" ]; then
rm -r "$cachedir"
fi
fi
}
trap cleanup EXIT
while getopts 'a:c:him:n' opt; do
case "$opt" in
a) arch=$OPTARG;;
c) cachedir=$OPTARG;;
h) usage; exit;;
i) ideas=true;;
m) mirror=$OPTARG;;
n) no_cache=true;;
*) usage >&2; exit 1;;
esac
done
shift $((OPTIND - 1))
# accept one argument
if [ $# -ne 1 ]; then
usage >&2
exit 1
fi
root=$1
arch=${arch-$(uname -m)}
if use_cache; then
if is_root; then
cachedir=${cachedir-/var/cache/archbootstrap}
else
cachedir=${cachedir-${XDG_CACHE_HOME-$HOME/.cache}/archbootstrap}
fi
else
cachedir=$(mktemp -d)
fi
mirror=${mirror-https://mirrors.kernel.org/archlinux/}
archive=$cachedir/$(
wget --quiet --output-document - "${mirror}iso/latest/" | \
grep --only-matching "archlinux-bootstrap-[0-9]\{4\}\.[0-9]\{2\}\.[0-9]\{2\}-$arch.tar.gz" | \
head -n1)
mkdir -p "$cachedir"
wget --quiet --show-progress --continue --output-document "$archive" "${mirror}iso/latest/$(basename "$archive")"
wget --quiet --show-progress --continue --output-document "$archive.sig" "${mirror}iso/latest/$(basename "$archive").sig"
gpg --verify "$archive.sig" "$archive" || exit $?
mkdir -p "$root"
tar xf "$archive" -C "$root" --strip-components 1
if show_ideas; then
echo
cat <<EOF
post-install ideas:
sed -i 's/^CheckSpace/#CheckSpace/' /etc/pacman.conf
echo 'Server = $mirror\$repo/os/\$arch' > /etc/pacman.d/mirrorlist
echo 'en_US.UTF-8 UTF-8' > /etc/locale.gen
echo LANG="en_US.UTF-8" > /etc/locale.conf
ln -s /usr/share/zoneinfo/UTC /etc/localtime
pacman-key --init
pacman-key --populate archlinux
pacman -Syu --needed base --ignore=linux
locale-gen
EOF
fi