Merge remote-tracking branch 'origin/pull/50'

* origin/pull/50:
  arch-chroot: add option to preserve the chroot resolv.conf
This commit is contained in:
Morten Linderud 2023-04-02 01:24:25 +02:00
commit 77c3cc7c1b
No known key found for this signature in database
GPG Key ID: 9C02FF419FECBE16
4 changed files with 15 additions and 3 deletions

View File

@ -3,6 +3,7 @@
shopt -s extglob
unshare=0
keepresolvconf=0
m4_include(common)
@ -13,6 +14,7 @@ usage: ${0##*/} chroot-dir [command] [arguments...]
-h Print this help message
-N Run in unshare mode as a regular user
-u <user>[:group] Specify non-root user and optional group to use
-r Do not change the resolv.conf within the chroot
If 'command' is unspecified, ${0##*/} will launch /bin/bash.
@ -79,7 +81,9 @@ arch-chroot() {
[[ -d $chrootdir ]] || die "Can't create chroot on non-directory %s" "$chrootdir"
$setup "$chrootdir" || die "failed to setup chroot %s" "$chrootdir"
chroot_add_resolv_conf "$chrootdir" || die "failed to setup resolv.conf"
if (( ! keepresolvconf )); then
chroot_add_resolv_conf "$chrootdir" || die "failed to setup resolv.conf"
fi
if ! mountpoint -q "$chrootdir"; then
warning "$chrootdir is not a mountpoint. This may have undesirable side effects."
@ -91,7 +95,7 @@ arch-chroot() {
SHELL=/bin/bash $pid_unshare chroot "${chroot_args[@]}" -- "$chrootdir" "${args[@]}"
}
while getopts ':hNu:' flag; do
while getopts ':hNu:r' flag; do
case $flag in
h)
usage
@ -103,6 +107,9 @@ while getopts ':hNu:' flag; do
u)
userspec=$OPTARG
;;
r)
keepresolvconf=1
;;
:)
die '%s: option requires an argument -- '\''%s'\' "${0##*/}" "$OPTARG"
;;

View File

@ -2,7 +2,7 @@ _arch_chroot() {
compopt +o dirnames
local cur prev opts i
_init_completion -n : || return
opts="-N -u -h"
opts="-N -u -r -h"
for i in "${COMP_WORDS[@]:1:COMP_CWORD-1}"; do
if [[ -d ${i} ]]; then

View File

@ -5,6 +5,7 @@ local -a args=(
'(-h --help)'{-h,--help}'[display help]'
'-N[Run in unshare mode as a regular user]'
'-u[The non-root user and optional group to use]: :->userspecs'
'-r[Do not change the resolv.conf within the chroot]'
'1:new root directory:_directories'
'*:::command:_normal'
)

View File

@ -40,6 +40,10 @@ Options
*-u <user>[:group]*::
Specify non-root user and optional group to use.
*-r*::
Do not change the resolv.conf within the chroot. This means that the resolver
might not work in the chroot, which could be the required state.
*-h*::
Output syntax and command line options.