Skip to content

Commit c911fbf

Browse files
committed
pacstrap: stop interleaving functions and sequential code
Makes it easier to reason about the code. Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
1 parent 6c68163 commit c911fbf

File tree

1 file changed

+36
-36
lines changed

1 file changed

+36
-36
lines changed

pacstrap.in

+36-36
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,42 @@ are given, pacstrap defaults to the "base" group.
4747
EOF
4848
}
4949

50+
pacstrap() {
51+
(( EUID == 0 )) || die 'This script must be run with root privileges'
52+
53+
# create obligatory directories
54+
msg 'Creating install root at %s' "$newroot"
55+
mkdir -m 0755 -p "$newroot"/var/{cache/pacman/pkg,lib/pacman,log} "$newroot"/{dev,run,etc/pacman.d}
56+
mkdir -m 1777 -p "$newroot"/tmp
57+
mkdir -m 0555 -p "$newroot"/{sys,proc}
58+
59+
# mount API filesystems
60+
$setup "$newroot" || die "failed to setup chroot %s" "$newroot"
61+
62+
if [[ ! -d $newroot/etc/pacman.d/gnupg ]]; then
63+
if (( initkeyring )); then
64+
pacman-key --gpgdir "$newroot"/etc/pacman.d/gnupg --init
65+
elif (( copykeyring )) && [[ -d /etc/pacman.d/gnupg ]]; then
66+
# if there's a keyring on the host, copy it into the new root
67+
cp -a --no-preserve=ownership /etc/pacman.d/gnupg "$newroot/etc/pacman.d/"
68+
fi
69+
fi
70+
71+
msg 'Installing packages to %s' "$newroot"
72+
if ! $pid_unshare pacman -r "$newroot" "${pacman_args[@]}"; then
73+
die 'Failed to install packages to new root'
74+
fi
75+
76+
if (( copymirrorlist )); then
77+
# install the host's mirrorlist onto the new root
78+
cp -a /etc/pacman.d/mirrorlist "$newroot/etc/pacman.d/"
79+
fi
80+
81+
if (( copyconf )); then
82+
cp -a "$pacman_config" "$newroot/etc/pacman.conf"
83+
fi
84+
}
85+
5086
if [[ -z $1 || $1 = @(-h|--help) ]]; then
5187
usage
5288
exit $(( $# ? 0 : 1 ))
@@ -109,42 +145,6 @@ fi
109145

110146
[[ -d $newroot ]] || die "%s is not a directory" "$newroot"
111147

112-
pacstrap() {
113-
(( EUID == 0 )) || die 'This script must be run with root privileges'
114-
115-
# create obligatory directories
116-
msg 'Creating install root at %s' "$newroot"
117-
mkdir -m 0755 -p "$newroot"/var/{cache/pacman/pkg,lib/pacman,log} "$newroot"/{dev,run,etc/pacman.d}
118-
mkdir -m 1777 -p "$newroot"/tmp
119-
mkdir -m 0555 -p "$newroot"/{sys,proc}
120-
121-
# mount API filesystems
122-
$setup "$newroot" || die "failed to setup chroot %s" "$newroot"
123-
124-
if [[ ! -d $newroot/etc/pacman.d/gnupg ]]; then
125-
if (( initkeyring )); then
126-
pacman-key --gpgdir "$newroot"/etc/pacman.d/gnupg --init
127-
elif (( copykeyring )) && [[ -d /etc/pacman.d/gnupg ]]; then
128-
# if there's a keyring on the host, copy it into the new root
129-
cp -a --no-preserve=ownership /etc/pacman.d/gnupg "$newroot/etc/pacman.d/"
130-
fi
131-
fi
132-
133-
msg 'Installing packages to %s' "$newroot"
134-
if ! $pid_unshare pacman -r "$newroot" "${pacman_args[@]}"; then
135-
die 'Failed to install packages to new root'
136-
fi
137-
138-
if (( copymirrorlist )); then
139-
# install the host's mirrorlist onto the new root
140-
cp -a /etc/pacman.d/mirrorlist "$newroot/etc/pacman.d/"
141-
fi
142-
143-
if (( copyconf )); then
144-
cp -a "$pacman_config" "$newroot/etc/pacman.conf"
145-
fi
146-
}
147-
148148
if (( unshare )); then
149149
$mount_unshare bash -c "$(declare_all); pacstrap"
150150
else

0 commit comments

Comments
 (0)