diff options
Diffstat (limited to 'src/chroot-tools/librechroot')
-rwxr-xr-x | src/chroot-tools/librechroot | 188 |
1 files changed, 101 insertions, 87 deletions
diff --git a/src/chroot-tools/librechroot b/src/chroot-tools/librechroot index f57c2cc..9367ef8 100755 --- a/src/chroot-tools/librechroot +++ b/src/chroot-tools/librechroot @@ -210,106 +210,120 @@ mkarchroot() { # Main program # ################################################################################ -readonly DEF_PACMANCONF_DIR=/usr/share/pacman/defaults/ +readonly DEF_PACMANCONF_DIR=/usr/share/pacman/defaults usage() { eval "$(calculate_directories)" + print "Usage: %s [OPTIONS] COMMAND [ARGS...]" "${0##*/}" - print 'Interacts with an archroot (arch chroot).' - echo - prose 'This is configured with `chroot.conf`, either in - `/etc/libretools.d/`, or `$XDG_CONFIG_HOME/libretools/`. - The variables you may set are $CHROOTDIR, $CHROOT, and - $CHROOTEXTRAPKG.' echo - prose 'There may be multiple chroots; they are stored in $CHROOTDIR.' + print 'Interacts with a libre "archroot" (similarly to `arch-chroot`).' echo - prose 'Each chroot is named; the default is configured with $CHROOT.' + prose 'This is configured with `chroot.conf`, + either in `/etc/libretools.d/`, or `$XDG_CONFIG_HOME/libretools/`. + The configurable variables are:' + bullet '$CHROOTDIR' + bullet '$CHROOT' + bullet '$CHROOTEXTRAPKG' echo - prose 'Each named chroot has a master clean copy (named `root`), and any - number of other named copies; the copy used by default is the - current username (or $SUDO_USER, or `copy` if root).' + prose 'Each chroot is named; and there may be multiple chroots; all of which, + are stored in $CHROOTDIR, with the default chroot name being: $CHROOT. + Each named chroot has a pristine, read-only master system (`root`), + which is used as the seed for any number of named working copies, + which may be derived from it. + If a working copy is not specified, the default is the $LIBREUSER, + determined at runtime, per /usr/lib/libretools/conf.sh. + $LIBREUSER is normally the current local login; but may be + over-ridden by setting $SUDO_USER in the environment.' echo - prose 'The full path to the chroot copy is "$CHROOTDIR/$CHROOT/$COPY", - unless the copy name is manually specified as an absolute path, - in which case, that path is used.' + prose 'Unless the working copy is manually specified as an absolute path, + the path to the working copy ($copydir) will determined at runtime:' + print ' $CHROOTDIR/$CHROOT/$COPY' echo prose 'The current settings for the above variables are:' - printf ' CHROOTDIR : %s\n' "${CHROOTDIR:-$(_ 'ERROR: NO SETTING')}" - printf ' CHROOT : %s\n' "${CHROOT:-$(_ 'ERROR: NO SETTING')}" - printf ' COPY : %s\n' "$COPY" - printf ' rootdir : %s\n' "${rootdir:-$(_ 'ERROR')}" - printf ' copydir : %s\n' "${copydir:-$(_ 'ERROR')}" + bullet "\$CHROOTDIR : %s" "${CHROOTDIR:-$(_ 'ERROR: NO SETTING')}" + bullet "\$CHROOT : %s" "${CHROOT:-$( _ 'ERROR: NO SETTING')}" + bullet "\$COPY : %s" "${COPY}" + bullet "\$rootdir : %s" "${rootdir:-$( _ 'ERROR' )}" + bullet "\$copydir : %s" "${copydir:-$( _ 'ERROR' )}" echo - prose "If the chroot or copy does not exist, it will be created - automatically. A chroot by default contains the packages in the - group 'base-devel' and any packages named in \$CHROOTEXTRAPKG. - However, for technical reasons, 'fakeroot-tcp' replaces 'fakeroot' - in armv7h chroots (BR #2775)." - echo - prose 'Unless the `-C` or `-M` flags are used, the configuration files - that this program installs are the stock versions supplied in the - packages, not the versions from your host system. Other tools - (such as libremakepkg) may alter the configuration.' + prose 'If the chroot-set or working copy does not exist, it will be created + automatically. A chroot by default contains the packages in the + `base-devel` group and any packages named in $CHROOTEXTRAPKG. + However, for technical reasons, `fakeroot-tcp` replaces `fakeroot` + in armv7h chroots (per BR #2775). + The packages installed into the chroot, will be those found + in the standard Parabola repos: (libre, core, extra, community, pcr), + regardless of the pacman/makepkg configuration of the host system. + The configuration files in the chroot will also be the standard ones + installed by the `pacman` package. + These defaults may be over-ridden with the `-C`, `-M`, and `-A` flags; + and other tools (such as `libremakepkg`) may over-ride them later.' echo prose 'This command will make the following configuration changes in the chroot:' bullet 'overwrite `/etc/libretools.d/chroot.conf`' # libretools/librechroot bullet 'overwrite `/etc/pacman.d/mirrorlist`' # devtools/arch-nspawn bullet 'set `CacheDir` in `/etc/pacman.conf`' # devtools/arch-nspawn - prose 'If a new `pacman.conf` is inserted with the `-C` flag, the change - is made after the file is copied in; the `-C` flag doesn'"'"'t - stop the change from being effective.' + prose 'If an over-ride `pacman.conf` is specified with the `-C` flag, + the changes above are made after the file is copied in. + The `-C` flag will not prevent these modifications.' echo - prose 'The processor architecture of the chroot is determined - by the by `CARCH` variable in the `/etc/makepkg.conf` - file inside of the chroot.' + prose 'The processor architecture of the chroot is determined by the `$CARCH` + variable, in the `/etc/makepkg.conf` file, inside of the chroot. + The `-M` flag allows specifying an over-ride of the standard file.' echo - prose 'The `-A CARCH` flag is *almost* simply an alias for' - printf ' %s\n' \ - "-C \"${DEF_PACMAN_CONF_DIR}pacman.conf.\$CARCH\" \\" \ - "-M \"${DEF_PACMAN_CONF_DIR}makepkg.conf.\$CARCH\"" - prose 'However, before doing that, it actually makes a temporary copy of - `pacman.conf`, and modifies it to:' - bullet 'set `Architecture` to match the `CARCH` line in `makepkg.conf`' - bullet 'comment out any `Include = /etc/pacman.d/*.conf` lines' + print 'The `-A <CARCH>` flag sets the -C and -M flags as:' + echo " -C \"${DEF_PACMANCONF_DIR}/pacman.conf.\$CARCH\" \\" + echo " -M \"${DEF_PACMANCONF_DIR}/makepkg.conf.\$CARCH\"" + prose 'However, `pacman.conf` will be modified to:' + bullet 'set `Architecture` to match the `CARCH=` line in `makepkg.conf`' + bullet 'comment-out any `Include = /etc/pacman.d/*.conf` lines' + bullet 'add special-case build support repos (commented-out)' + prose 'The `-A` option is recommended for creating a new `root` seed, e.g.:' + echo ' sudo librechroot -n i686 -A i686 make' echo - prose 'Creating a copy, deleting a copy, or syncing a copy can be fairly - slow; but are very fast if $CHROOTDIR is on a btrfs partition.' + prose 'Creating/deleting/synchronizing a copy, can be relatively slow; + but can be very fast, if $CHROOTDIR is on a btrfs partition.' echo - print 'Options:' - flag "-n <$(_ CHROOT)>" 'Name of the chroot to use' - flag "-l <$(_ COPY)>" 'Name of, or absolute path to, the copy to use' - flag '-N' 'Disable networking in the chroot' - flag "-C <$(_ FILE)>" 'Copy this file to `$copydir/etc/pacman.conf`' - flag "-M <$(_ FILE)>" 'Copy this file to `$copydir/etc/makepkg.conf`' - flag "-A <$(_ CARCH)>" 'Set the architecture of the copy; simply an - alias for the `-C` and `-M` flags, see above.' - flag "-w <$(_ 'PATH[:INSIDE_PATH[:OPTIONS]]')>" 'Bind mount a file or directory, read/write' - flag "-r <$(_ 'PATH[:INSIDE_PATH[:OPTIONS]]')>" 'Bind mount a file or directory, read-only' + flag 'Options:' \ + "-n <$(_ NAME)>" 'Name of the chroot to use' \ + "-l <$(_ COPY)>" 'Name of, or absolute path to, the copy to use' \ + "-C <$(_ FILE)>" 'Copy this file to chroot as: `/etc/pacman.conf` + This option is mutually exclusive with -A.' \ + "-M <$(_ FILE)>" 'Copy this file to chroot as: `/etc/makepkg.conf` + This option is mutually exclusive with -A.' \ + "-A <$(_ CARCH)>" 'Specify the architecture of a new `root` seed. + This option is mutually exclusive with -C and -M.' \ + "-N" 'Disable networking in the chroot' \ + "-w <$(_ 'PATH[:INSIDE_PATH[:OPTIONS]]')>" 'Bind mount a file or + directory, read/write' \ + "-r <$(_ 'PATH[:INSIDE_PATH[:OPTIONS]]')>" 'Bind mount a file or + directory, read-only' echo - print 'Commands:' - print ' Create/copy/delete:' - flag 'noop|make' 'Do not do anything, but still creates the chroot - copy if it does not exist' - flag 'sync' 'Sync the copy with the clean (`root`) copy' - flag 'delete' 'Delete the chroot copy' - print ' Dealing with packages:' - flag "install-file $(_ FILES...)" 'Like `pacman -U FILES...`' - flag "install-name $(_ NAMES...)" 'Like `pacman -S NAMES...`' - flag 'update' 'Like `pacman -Syu`' - flag 'clean-pkgs' 'Remove all packages from the chroot copy that - are not in base-devel, $CHROOTEXTRAPKG, or named - as a dependency in the file `/startdir/PKGBUILD` - in the chroot copy; and install all packages - that are.' - print ' Other:' - flag "run $(_ CMD...)" 'Run CMD in the chroot copy' - flag 'enter' 'Enter an interactive shell in the chroot copy' - flag 'clean-repo' 'Clean /repo in the chroot copy' - flag 'help' 'Show this message' + flag 'Commands (create/copy/delete):' \ + 'make' 'Create a `root` seed and working copy' \ + 'sync' 'Sync the copy with the clean `root` seed' \ + 'delete' 'Delete the working copy' + flag 'Commands (packages):' \ + "install-file $(_ FILES...)" 'Like `pacman -U FILES...`' \ + "install-name $(_ NAMES...)" 'Like `pacman -S NAMES...`' \ + 'update' 'Like `pacman -Syu`' \ + 'clean-pkgs' 'Remove all packages from the working copy + that are not in `base-devel`, + $CHROOTEXTRAPKG, or in the depends array + of the working copy /startdir/PKGBUILD; + and install all packages that are. + `libremakepkg` does this implicitly.' + flag 'Commands (maintenance):' \ + "run $(_ CMD...)" 'Run CMD in the working copy' \ + 'enter' 'Enter an interactive shell in the working copy' \ + 'clean-repo' 'Clean /repo in the working copy' + flag 'Commands (misc):' \ + 'help' 'Show this message' } + readonly commands=( noop make sync delete install-file install-name update clean-pkgs @@ -340,20 +354,20 @@ main() { while getopts 'n:l:NC:M:A:w:r:' opt; do case $opt in - n ) CHROOT=$OPTARG ;; - l ) COPY=$OPTARG ;; - N ) sysd_nspawn_flags+=(--private-network) ;; + n ) CHROOT=$OPTARG ;; + l ) COPY=$OPTARG ;; + N ) sysd_nspawn_flags+=(--private-network) ;; C|M) target_arch=$(detect_chroot_arch "$OPTARG") - arch_nspawn_flags+=(-$opt "$OPTARG") ;; + arch_nspawn_flags+=(-$opt "$OPTARG") ;; A ) target_arch=$OPTARG - def_pacmanconf="${DEF_PACMANCONF_DIR}"pacman.conf.${target_arch} - def_makepkgconf="${DEF_PACMANCONF_DIR}"makepkg.conf.${target_arch} + def_pacmanconf="${DEF_PACMANCONF_DIR}"/pacman.conf.${target_arch} + def_makepkgconf="${DEF_PACMANCONF_DIR}"/makepkg.conf.${target_arch} arch_nspawn_flags+=( -C "${tmp_pacmanconf}" -M "${def_makepkgconf}" ) - has_tmp_pacmanconf=1 ;; - w ) sysd_nspawn_flags+=("--bind=$OPTARG") ;; - r ) sysd_nspawn_flags+=("--bind-ro=$OPTARG") ;; - * ) usage >&2; return $EXIT_INVALIDARGUMENT ;; + has_tmp_pacmanconf=1 ;; + w ) sysd_nspawn_flags+=("--bind=$OPTARG") ;; + r ) sysd_nspawn_flags+=("--bind-ro=$OPTARG") ;; + * ) usage >&2; return $EXIT_INVALIDARGUMENT ;; esac used_opts[$opt]+=1 done @@ -435,7 +449,7 @@ main() { if (( has_tmp_pacmanconf )) && \ ! [[ -f "${def_pacmanconf}" && -f "${def_makepkgconf}" ]]; then error 'Unsupported architecture: %s' "${target_arch}" - plain 'See the files in %q for valid architectures.' "${DEF_PACMANCONF_DIR}" + plain 'See the files in %q for valid architectures.' "${DEF_PACMANCONF_DIR}/" return $EXIT_INVALIDARGUMENT; fi |