Migrate over to base-install-scripts

This commit is contained in:
Martin Valba 2023-03-19 11:35:18 +02:00
parent 560c00c9c2
commit a716cc810f
8 changed files with 83 additions and 83 deletions

View File

@ -1,16 +1,16 @@
VER=26
VER=2023.1
PREFIX = /usr/local
PREFIX = /usr
BINPROGS = \
arch-chroot \
base-chroot \
genfstab \
pacstrap
base-strap
MANS = \
doc/arch-chroot.8 \
doc/base-chroot.8 \
doc/genfstab.8 \
doc/pacstrap.8
doc/base-strap.8
BASH = bash
@ -39,7 +39,7 @@ check: all
install: all
install -dm755 $(DESTDIR)$(PREFIX)/bin
install -m755 $(BINPROGS) $(DESTDIR)$(PREFIX)/bin
install -Dm644 completion/_archinstallscripts.zsh $(DESTDIR)$(PREFIX)/share/zsh/site-functions/_archinstallscripts
install -Dm644 completion/_baseinstallscripts.zsh $(DESTDIR)$(PREFIX)/share/zsh/site-functions/_baseinstallscripts
cd completion; for comp in *.bash; do \
install -Dm644 $$comp $(DESTDIR)$(PREFIX)/share/bash-completion/completions/$${comp%%.*}; \
done;

View File

@ -17,8 +17,8 @@ usage: ${0##*/} chroot-dir [command] [arguments...]
If 'command' is unspecified, ${0##*/} will launch /bin/bash.
Note that when using arch-chroot, the target chroot directory *should* be a
mountpoint. This ensures that tools such as pacman(8) or findmnt(8) have an
Note that when using base-chroot, the target chroot directory *should* be a
mountpoint. This ensures that tools such as bottle(8) or findmnt(8) have an
accurate hierarchy of the mounted filesystems within the chroot.
If your chroot target is not a mountpoint, you can bind mount the directory on
@ -101,7 +101,7 @@ shift $(( OPTIND - 1 ))
chrootdir=$1
shift
arch-chroot() {
base-chroot() {
(( EUID == 0 )) || die 'This script must be run with root privileges'
[[ -d $chrootdir ]] || die "Can't create chroot on non-directory %s" "$chrootdir"
@ -121,7 +121,7 @@ arch-chroot() {
args=("$@")
if (( unshare )); then
$mount_unshare bash -c "$(declare_all); arch-chroot"
$mount_unshare bash -c "$(declare_all); base-chroot"
else
arch-chroot
base-chroot
fi

View File

@ -4,8 +4,8 @@
# Assumptions:
# 1) User has partitioned, formatted, and mounted partitions on /mnt
# 2) Network is functional
# 3) Arguments passed to the script are valid pacman targets
# 4) A valid mirror appears in /etc/pacman.d/mirrorlist
# 3) Arguments passed to the script are valid bottle targets
# 4) A valid mirror appears in /etc/bottle.d/mirrorlist
#
shopt -s extglob
@ -16,33 +16,33 @@ hostcache=0
copykeyring=1
initkeyring=0
copymirrorlist=1
pacman_args=()
pacmode=-Sy
bottle_args=()
bottlemode=-Sy
setup=chroot_setup
unshare=0
copyconf=0
pacman_config=/etc/pacman.conf
bottle_config=/etc/bottle.conf
usage() {
cat <<EOF
usage: ${0##*/} [options] root [packages...]
Options:
-C <config> Use an alternate config file for pacman
-C <config> Use an alternate config file for bottle
-c Use the package cache on the host, rather than the target
-D Skip pacman dependency checks
-G Avoid copying the host's pacman keyring to the target
-D Skip bottle dependency checks
-G Avoid copying the host's bottle keyring to the target
-i Prompt for package confirmation when needed (run interactively)
-K Initialize an empty pacman keyring in the target (implies '-G')
-K Initialize an empty bottle keyring in the target (implies '-G')
-M Avoid copying the host's mirrorlist to the target
-N Run in unshare mode as a regular user
-P Copy the host's pacman config to the target
-U Use pacman -U to install packages
-P Copy the host's bottle config to the target
-U Use bottle -U to install packages
-h Print this help message
pacstrap installs packages to the specified new root directory. If no packages
are given, pacstrap defaults to the "base" group.
base-strap installs packages to the specified new root directory. If no packages
are given, base-strap defaults to the "base" group.
EOF
}
@ -55,10 +55,10 @@ fi
while getopts ':C:cDGiKMNPU' flag; do
case $flag in
C)
pacman_config=$OPTARG
bottle_config=$OPTARG
;;
D)
pacman_args+=(-dd)
bottle_args+=(-dd)
;;
c)
hostcache=1
@ -83,7 +83,7 @@ while getopts ':C:cDGiKMNPU' flag; do
copyconf=1
;;
U)
pacmode=-U
bottlemode=-U
;;
:)
die '%s: option requires an argument -- '\''%s'\' "${0##*/}" "$OPTARG"
@ -97,58 +97,58 @@ shift $(( OPTIND - 1 ))
(( $# )) || die "No root directory specified"
newroot=$1; shift
pacman_args+=("$pacmode" "${@:-base}" --config="$pacman_config")
bottle_args+=("$bottlemode" "${@:-base}" --config="$bottle_config")
if (( ! hostcache )); then
pacman_args+=(--cachedir="$newroot/var/cache/pacman/pkg")
bottle_args+=(--cachedir="$newroot/var/cache/bottle/pkg")
fi
if (( ! interactive )); then
pacman_args+=(--noconfirm)
bottle_args+=(--noconfirm)
fi
[[ -d $newroot ]] || die "%s is not a directory" "$newroot"
pacstrap() {
base-strap() {
(( 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 0755 -p "$newroot"/var/{cache/bottle/pkg,lib/bottle,log} "$newroot"/{dev,run,etc/bottle.d}
mkdir -m 1777 -p "$newroot"/tmp
mkdir -m 0555 -p "$newroot"/{sys,proc}
# mount API filesystems
$setup "$newroot" || die "failed to setup chroot %s" "$newroot"
if [[ ! -d $newroot/etc/pacman.d/gnupg ]]; then
if [[ ! -d $newroot/etc/bottle.d/gnupg ]]; then
if (( initkeyring )); then
pacman-key --gpgdir "$newroot"/etc/pacman.d/gnupg --init
elif (( copykeyring )) && [[ -d /etc/pacman.d/gnupg ]]; then
bottle-key --gpgdir "$newroot"/etc/bottle.d/gnupg --init
elif (( copykeyring )) && [[ -d /etc/bottle.d/gnupg ]]; then
# if there's a keyring on the host, copy it into the new root
cp -a --no-preserve=ownership /etc/pacman.d/gnupg "$newroot/etc/pacman.d/"
cp -a --no-preserve=ownership /etc/bottle.d/gnupg "$newroot/etc/bottle.d/"
fi
fi
msg 'Installing packages to %s' "$newroot"
if ! $pid_unshare pacman -r "$newroot" "${pacman_args[@]}"; then
if ! $pid_unshare bottle -r "$newroot" "${bottle_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/"
cp -a /etc/bottle.d/mirrorlist "$newroot/etc/bottle.d/"
fi
if (( copyconf )); then
cp -a "$pacman_config" "$newroot/etc/pacman.conf"
cp -a "$bottle_config" "$newroot/etc/bottle.conf"
fi
}
if (( unshare )); then
$mount_unshare bash -c "$(declare_all); pacstrap"
$mount_unshare bash -c "$(declare_all); base-strap"
else
pacstrap
base-strap
fi
# vim: et ts=2 sw=2 ft=sh:

View File

@ -1,21 +1,21 @@
#compdef pacstrap genfstab arch-chroot
#compdef base-strap genfstab base-chroot
_pacstrap_args=(
_base_strap_args=(
'-h[display help]'
)
_pacstrap_args_nonh=(
_base_strap_args_nonh=(
'(-h --help)-c[Use the package cache on the host, rather than the target]'
'(--help -h)-i[Avoid auto-confirmation of package selections]'
)
# builds command for invoking pacman in a _call_program command - extracts
# builds command for invoking bottle in a _call_program command - extracts
# relevant options already specified (config file, etc)
# $cmd must be declared by calling function
_pacman_get_command() {
_bottle_get_command() {
# this is mostly nicked from _perforce
cmd=( "pacman" "2>/dev/null")
cmd=( "bottle" "2>/dev/null")
integer i
for (( i = 2; i < CURRENT - 1; i++ )); do
if [[ ${words[i]} = "--config" || ${words[i]} = "--root" ]]; then
@ -26,9 +26,9 @@ _pacman_get_command() {
# provides completions for packages available from repositories
# these can be specified as either 'package' or 'repository/package'
_pacman_completions_all_packages() {
_bottle_completions_all_packages() {
local -a cmd packages repositories packages_long
_pacman_get_command
_bottle_get_command
if compset -P1 '*/*'; then
packages=( $(_call_program packages $cmd[@] -Sql ${words[CURRENT]%/*}) )
@ -39,15 +39,15 @@ _pacman_completions_all_packages() {
typeset -U packages
_wanted packages expl "packages" compadd - "${(@)packages}"
repositories=(${(o)${${${(M)${(f)"$(</etc/pacman.conf)"}:#\[*}/\[/}/\]/}:#options})
repositories=(${(o)${${${(M)${(f)"$(</etc/bottle.conf)"}:#\[*}/\[/}/\]/}:#options})
typeset -U repositories
_wanted repo_packages expl "repository/package" compadd -S "/" $repositories
fi
}
_pacstrap_none(){
_base_strap_none(){
_arguments -s : \
"$_pacstrap_args[@]" \
"$_base_strap_args[@]" \
"$_longopts[@]" \
}
@ -60,20 +60,20 @@ _genfstab_args_nonh=(
'(-L --help -h)-U[Use UUIDs for source identifiers]'
)
_arch_chroot_args=( '-h[display help]' )
_base_chroot_args=( '-h[display help]' )
_longopts=( '--help[display help]' )
_pacstrap(){
_base_strap(){
if [[ -z ${(M)words:#--help} && -z ${(M)words:#-h} ]]; then
case $words[CURRENT] in
-c*|-d*|-i*)
_arguments -s "$_pacstrap_args_nonh[@]"
_arguments -s "$_base_strap_args_nonh[@]"
;;
-*)
_arguments -s : \
"$_pacstrap_args[@]" \
"$_pacstrap_args_nonh[@]" \
"$_base_strap_args[@]" \
"$_base_strap_args_nonh[@]" \
"$_longopts[@]"
;;
--*)
@ -82,11 +82,11 @@ _pacstrap(){
;;
*)
_arguments -s : \
"$_pacstrap_args[@]" \
"$_pacstrap_args_nonh[@]" \
"$_base_strap_args[@]" \
"$_base_strap_args_nonh[@]" \
"$_longopts[@]" \
":*:_path_files -/" \
":*:_pacman_completions_all_packages"
":*:_bottle_completions_all_packages"
;;
esac
else
@ -124,12 +124,12 @@ _genfstab(){
fi
}
_arch_chroot(){
_base_chroot(){
if [[ -z ${(M)words:#--help} && -z ${(M)words:#-*h} ]]; then
case $words[CURRENT] in
-*)
_arguments -s : \
"$_arch_chroot_args[@]" \
"$_base_chroot_args[@]" \
"$_longopts[@]" \
;;
--*)
@ -148,13 +148,13 @@ _arch_chroot(){
_install_scripts(){
case "$service" in
pacstrap)
_pacstrap "$@"
base-strap)
_base_strap "$@"
;;
genfstab)
_genfstab "$@";;
arch-chroot)
_arch_chroot "$@";;
base-chroot)
_base_chroot "$@";;
*)
_message "Error";;
esac

View File

@ -1,4 +1,4 @@
_arch_chroot() {
_base_chroot() {
compopt +o dirnames
local cur prev opts i
_init_completion -n : || return
@ -22,4 +22,4 @@ _arch_chroot() {
compopt -o dirnames
}
complete -F _arch_chroot arch-chroot
complete -F _base_chroot base-chroot

View File

@ -1,8 +1,8 @@
if ! declare -F _pacman_pkg > /dev/null; then
_completion_loader pacman
if ! declare -F _bottle_pkg > /dev/null; then
_completion_loader bottle
fi
_pacstrap() {
_base_strap() {
compopt +o dirnames +o default
local cur prev opts
COMPREPLY=()
@ -12,7 +12,7 @@ _pacstrap() {
for i in "${COMP_WORDS[@]:1:COMP_CWORD-1}"; do
if [[ -d ${i} ]]; then
_pacman_pkg Slq
_bottle_pkg Slq
return 0
fi
done
@ -35,4 +35,4 @@ _pacstrap() {
compopt -o dirnames
}
complete -F _pacstrap pacstrap
complete -F _base_strap base-strap

View File

@ -1,21 +1,21 @@
arch-chroot(8)
base-chroot(8)
==============
Name
----
arch-chroot - enhanced chroot command
base-chroot - enhanced chroot command
Synopsis
--------
arch-chroot [options] chroot-dir [command] [arguments...]
base-chroot [options] chroot-dir [command] [arguments...]
Description
-----------
arch-chroot wraps the linkman:chroot[1] command while ensuring that important
base-chroot wraps the linkman:chroot[1] command while ensuring that important
functionality is available, e.g. mounting '/dev/', '/proc' and other API
filesystems, or exposing linkman:resolv.conf[5] to the chroot.
If 'command' is unspecified, arch-chroot will launch */bin/bash*.
If 'command' is unspecified, base-chroot will launch */bin/bash*.
[NOTE]
======

View File

@ -1,17 +1,17 @@
pacstrap(8)
base-strap(8)
===========
Name
----
pacstrap - install packages to the specified new root directory
base-strap - install packages to the specified new root directory
Synopsis
--------
pacstrap [options] root [packages...]
base-strap [options] root [packages...]
Description
-----------
pacstrap is designed to create a new system installation from scratch. The
base-strap is designed to create a new system installation from scratch. The
specified packages will be installed into a given directory after setting up
some basic mountpoints. By default, the host system's pacman signing keys
and mirrorlist will be used to seed the chroot.