aboutsummaryrefslogtreecommitdiffstats
path: root/pacstrap.in
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2022-07-05 01:31:24 -0400
committerLibravatarUnit 193 <unit193@unit193.net>2022-07-05 01:31:24 -0400
commit22faa4b00068fc50c66614c4e4812273aa231d55 (patch)
treee881c40b156e2e1c6d5c3bca72908c9b38277f64 /pacstrap.in
parentf922fa446f9893e571bf038c5e2d2520837c9814 (diff)
New upstream version 25.upstream/25
Diffstat (limited to 'pacstrap.in')
-rw-r--r--pacstrap.in57
1 files changed, 34 insertions, 23 deletions
diff --git a/pacstrap.in b/pacstrap.in
index 703df11..9ffe17c 100644
--- a/pacstrap.in
+++ b/pacstrap.in
@@ -16,6 +16,8 @@ hostcache=0
copykeyring=1
copymirrorlist=1
pacmode=-Sy
+setup=chroot_setup
+unshare="$root_unshare"
usage() {
cat <<EOF
@@ -27,6 +29,7 @@ usage: ${0##*/} [options] root [packages...]
-G Avoid copying the host's pacman keyring to the target
-i Prompt for package confirmation when needed (run interactively)
-M Avoid copying the host's mirrorlist to the target
+ -N Run in unshare mode as a regular user
-U Use pacman -U to install packages
-h Print this help message
@@ -42,9 +45,7 @@ if [[ -z $1 || $1 = @(-h|--help) ]]; then
exit $(( $# ? 0 : 1 ))
fi
-(( EUID == 0 )) || die 'This script must be run with root privileges'
-
-while getopts ':C:cdGiMU' flag; do
+while getopts ':C:cdGiMNU' flag; do
case $flag in
C)
pacman_config=$OPTARG
@@ -64,6 +65,10 @@ while getopts ':C:cdGiMU' flag; do
M)
copymirrorlist=0
;;
+ N)
+ setup=unshare_setup
+ unshare="$user_unshare"
+ ;;
U)
pacmode=-U
;;
@@ -95,30 +100,36 @@ fi
[[ -d $newroot ]] || die "%s is not a directory" "$newroot"
-# create obligatory directories
-msg 'Creating install root at %s' "$newroot"
-mkdir -m 0755 -p "$newroot"/var/{cache/pacman/pkg,lib/pacman,log} "$newroot"/{dev,run,etc/pacman.d}
-mkdir -m 1777 -p "$newroot"/tmp
-mkdir -m 0555 -p "$newroot"/{sys,proc}
+pacstrap() {
+ (( EUID == 0 )) || die 'This script must be run with root privileges'
+
+ # create obligatory directories
+ msg 'Creating install root at %s' "$newroot"
+ mkdir -m 0755 -p "$newroot"/var/{cache/pacman/pkg,lib/pacman,log} "$newroot"/{dev,run,etc/pacman.d}
+ mkdir -m 1777 -p "$newroot"/tmp
+ mkdir -m 0555 -p "$newroot"/{sys,proc}
-# mount API filesystems
-chroot_setup "$newroot" || die "failed to setup chroot %s" "$newroot"
+ # mount API filesystems
+ $setup "$newroot" || die "failed to setup chroot %s" "$newroot"
-if (( copykeyring )); then
- # if there's a keyring on the host, copy it into the new root, unless it exists already
- if [[ -d /etc/pacman.d/gnupg && ! -d $newroot/etc/pacman.d/gnupg ]]; then
- cp -a /etc/pacman.d/gnupg "$newroot/etc/pacman.d/"
+ if (( copykeyring )); then
+ # if there's a keyring on the host, copy it into the new root, unless it exists already
+ if [[ -d /etc/pacman.d/gnupg && ! -d $newroot/etc/pacman.d/gnupg ]]; then
+ cp -a --no-preserve=ownership /etc/pacman.d/gnupg "$newroot/etc/pacman.d/"
+ fi
fi
-fi
-msg 'Installing packages to %s' "$newroot"
-if ! unshare --fork --pid pacman -r "$newroot" $pacmode "${pacman_args[@]}"; then
- die 'Failed to install packages to new root'
-fi
+ msg 'Installing packages to %s' "$newroot"
+ if ! pacman -r "$newroot" $pacmode "${pacman_args[@]}"; then
+ die 'Failed to install packages to new root'
+ fi
-if (( copymirrorlist )); then
- # install the host's mirrorlist onto the new root
- cp -a /etc/pacman.d/mirrorlist "$newroot/etc/pacman.d/"
-fi
+ if (( copymirrorlist )); then
+ # install the host's mirrorlist onto the new root
+ cp -a /etc/pacman.d/mirrorlist "$newroot/etc/pacman.d/"
+ fi
+}
+
+$unshare bash -c "$(declare_all); pacstrap"
# vim: et ts=2 sw=2 ft=sh: