Skip to content

Commit

Permalink
New: Specify the chroot directory (thanks to dagmoller!)
Browse files Browse the repository at this point in the history
  • Loading branch information
idlemoor committed Sep 12, 2017
1 parent 45579b3 commit 65b100d
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 21 deletions.
4 changes: 4 additions & 0 deletions NEWS
Expand Up @@ -37,6 +37,10 @@ of slackrepo-0.2.0:
* If downloading from the normal URL fails, downloads now fall back to both
sbosrcarch and Slackbuilds Direct Links.

* The --chroot control argument now allows any specified chroot directory to
be used (--chroot=/path/to/chroot). This can also be set as a default in
the configuration file (CHROOT="/path/to/chroot").

* The new --debug control argument is a quick way of setting
--very-verbose --dry-run --lint --keep-tmp

Expand Down
2 changes: 1 addition & 1 deletion etc/slackrepo_SBo.conf
Expand Up @@ -102,7 +102,7 @@ VERBOSE='n'
VERY_VERBOSE='n'
DRY_RUN='n'
INSTALL='n'
CHROOT='y'
CHROOT='/'
LINT='n'
KEEP_TMP='n'
COLOR='auto'
Expand Down
2 changes: 1 addition & 1 deletion etc/slackrepo_csb.conf
Expand Up @@ -92,7 +92,7 @@ VERBOSE='n'
VERY_VERBOSE='n'
DRY_RUN='n'
INSTALL='n'
CHROOT='y'
CHROOT='/'
LINT='n'
KEEP_TMP='n'
COLOR='auto'
Expand Down
2 changes: 1 addition & 1 deletion etc/slackrepo_msb.conf
Expand Up @@ -92,7 +92,7 @@ VERBOSE='n'
VERY_VERBOSE='n'
DRY_RUN='n'
INSTALL='n'
CHROOT='y'
CHROOT='/'
LINT='n'
KEEP_TMP='n'
COLOR='auto'
Expand Down
2 changes: 1 addition & 1 deletion etc/slackrepo_ponce.conf
Expand Up @@ -116,7 +116,7 @@ VERBOSE='n'
VERY_VERBOSE='n'
DRY_RUN='n'
INSTALL='n'
CHROOT='y'
CHROOT='/'
LINT='n'
KEEP_TMP='n'
COLOR='auto'
Expand Down
12 changes: 6 additions & 6 deletions libexec/functions.d/buildfunctions.sh
Expand Up @@ -107,7 +107,7 @@ function build_item_packages
# Copy or link the source (if any) into the temporary SlackBuild directory
# (need to copy if this is a chroot, it might be on an inaccessible mounted FS)
if [ -n "${INFODOWNLIST[$itemid]}" ]; then
if [ "$OPT_CHROOT" = 'y' ]; then
if [ "$OPT_CHROOT" != 'n' ]; then
cp -a "${SRCDIR[$itemid]}"/* "$TMP_SLACKBUILD/"
else
# "Copy / is dandy / but linky / is quicky" [after Ogden Nash]
Expand Down Expand Up @@ -370,7 +370,7 @@ function build_item_packages

# Setup the chroot
# (to be destroyed below, or by build_failed if necessary)
if [ "$OPT_CHROOT" = 'y' ]; then
if [ "$OPT_CHROOT" != 'n' ]; then
chroot_setup || return 1
fi

Expand Down Expand Up @@ -518,7 +518,7 @@ function build_item_packages
#### fi ####
done

[ "$OPT_CHROOT" = 'y' ] && chroot_report
[ "$OPT_CHROOT" != 'n' ] && chroot_report

local inst testinst
# Do we want to install it? if not, we'll ask for a test install.
Expand All @@ -532,7 +532,7 @@ function build_item_packages
test_package $testinst "$itemid" "${pkglist[@]}"
[ $? -gt 1 ] && { build_failed "$itemid"; return 7; }

[ "$OPT_CHROOT" = 'y' ] && chroot_destroy
[ "$OPT_CHROOT" != 'n' ] && chroot_destroy
rm -f "$MY_STARTSTAMP" 2>/dev/null

if [ "$inst" = 'y' ]; then
Expand Down Expand Up @@ -700,7 +700,7 @@ function chroot_setup
# Exits completely (status=6) if the overlay failed to mount
{
CHROOTCMD=''
[ "$OPT_CHROOT" != 'y' ] && return 1
[ "$OPT_CHROOT" = 'n' ] && return 1

MY_CHRDIR="$MYTMP"/chrootdir/ # note the trailing slash
${SUDO}mkdir -p "$MY_CHRDIR"
Expand All @@ -717,7 +717,7 @@ function chroot_setup
OVL_DIRTY="$TMP_OVLDIR"/dirty
OVL_WORK="$TMP_OVLDIR"/work
${SUDO}mkdir -p "$OVL_DIRTY" "$OVL_WORK"
${SUDO}mount -t overlay overlay -olowerdir=/,upperdir="$OVL_DIRTY",workdir="$OVL_WORK" "$MY_CHRDIR" || \
${SUDO}mount -t overlay overlay -olowerdir="$OPT_CHROOT",upperdir="$OVL_DIRTY",workdir="$OVL_WORK" "$MY_CHRDIR" || \
{ log_error "Failed to mount $MY_CHRDIR"; exit_cleanup 6; }
CHRMOUNTS+=( "$MY_CHRDIR" )

Expand Down
2 changes: 1 addition & 1 deletion libexec/functions.d/cmdfunctions.sh
Expand Up @@ -632,7 +632,7 @@ function info_command
[ "$OPT_INSTALL" = 'y' ] && echo " --install"
[ "$OPT_LINT" != 'n' ] && echo " --lint=$OPT_LINT"
[ "$OPT_KEEP_TMP" = 'y' ] && echo " --keep-tmp"
[ "$OPT_CHROOT" = 'y' ] && echo " --chroot"
[ "$OPT_CHROOT" != 'n' ] && echo " --chroot=$OPT_CHROOT"
[ "$OPT_COLOR" != 'auto' ] && echo " --color=$OPT_COLOR"
[ "$OPT_NICE" != '5' ] && echo " --nice=$OPT_NICE"
[ "$OPT_REPRODUCIBLE" = 'y' ] && echo " --reproducible"
Expand Down
4 changes: 2 additions & 2 deletions libexec/functions.d/installfunctions.sh
Expand Up @@ -50,7 +50,7 @@ function uninstall_deps
local mydep

if [ -n "${FULLDEPS[$itemid]}" ]; then
[ "$OPT_CHROOT" != 'y' ] && log_normal -a "Uninstalling dependencies ..."
[ "$OPT_CHROOT" = 'n' ] && log_normal -a "Uninstalling dependencies ..."
for mydep in ${FULLDEPS[$itemid]}; do
uninstall_packages "$mydep"
done
Expand Down Expand Up @@ -210,7 +210,7 @@ function uninstall_packages
local pkgpath
local etcnewfiles etcdirs e

if [ "$OPT_CHROOT" = 'y' ]; then
if [ "$OPT_CHROOT" != 'n' ]; then
# Don't bother uninstalling, the chroot has already been destroyed,
# but we need to run 'depmod' if we have removed a kernel module.
if [ "${HINT_KERNEL[$itemid]}" = 'kernelmodule' ]; then
Expand Down
2 changes: 1 addition & 1 deletion man/man5/slackrepo.conf.5
Expand Up @@ -311,7 +311,7 @@ VERBOSE='n'
VERY_VERBOSE='n'
DRY_RUN='n'
INSTALL='n'
CHROOT='n'
CHROOT='/'
LINT='n'
KEEP_TMP='n'
COLOR='auto'
Expand Down
7 changes: 4 additions & 3 deletions man/man8/slackrepo.8
Expand Up @@ -103,10 +103,11 @@ removed).
.
.
.TP
\fB\-\-chroot\fR
\fB\-\-chroot\fI[=path]\fR
Construct and use a temporary chroot environment for each build process.
(Requires a Linux 3.18+ kernel with overlayfs.)
This option has no effect with the remove, revert and lint commands.
(Requires a Linux 3.18+ kernel with overlayfs.) The specified path will
be used to create the chroot (default '/'). This option has no effect
with the remove, revert and lint commands.
.
.TP
\fB\-\-color=always|auto|no\fR
Expand Down
21 changes: 17 additions & 4 deletions slackrepo
Expand Up @@ -324,7 +324,6 @@ fi
# However, they do NOT have the SR_ prefix in the config files or environment.
varnames="SBREPO SRCREPO PKGREPO PKGBACKUP \
HINTDIR DEFAULT_HINTDIR LOGDIR DATABASE TMP \
SUBSTITUTE \
ARCH TAG PKGTYPE NUMJOBS"
# These config vars don't need to be obfuscated:
genrepnames="USE_GENREPOS REPOSROOT REPOSOWNER REPOSOWNERGPG DL_URL \
Expand Down Expand Up @@ -400,10 +399,10 @@ done
[ "$OPT_DRY_RUN" = 'y' ] && OPT_INSTALL='n'
# lazy implementation of --very-verbose ;-)
[ "$OPT_VERY_VERBOSE" = 'y' ] && export VERBOSE=1 V=1
# compatibility fix, OPT_CHROOT is now a pathname or 'n'
[ "$OPT_CHROOT" = 'y' ] && OPT_CHROOT='/'
# chroot will only work if overlayfs is available
if [ "$OPT_CHROOT" = 'y' ] && [ "$SYS_OVERLAYFS" != 'y' ]; then
OPT_CHROOT='n'
fi
[ "$SYS_OVERLAYFS" != 'y' ] && OPT_CHROOT='n'
# accept null niceness, map to zero
[ -z "$OPT_NICE" ] && OPT_NICE='0'
# fixup NOWARNING (if you really want the regex to match 'n', see a doctor)
Expand Down Expand Up @@ -476,6 +475,9 @@ for name in $varnames $genrepnames $initnames; do
srvar="SR_$name"
eval "$srvar=\"$(echo "${!srvar}" | sed -e "s/%REPO%/$OPT_REPO/g" -e "s/%SLACKVER%/$SYS_OSVER/g" -e "s/%ARCH%/$SR_ARCH/g")\""
done
for name in OPT_CHROOT; do
eval "$name=\"$(echo "${!name}" | sed -e "s/%REPO%/$OPT_REPO/g" -e "s/%SLACKVER%/$SYS_OSVER/g" -e "s/%ARCH%/$SR_ARCH/g")\""
done

#-------------------------------------------------------------------------------

Expand Down Expand Up @@ -520,6 +522,17 @@ fi
# Arrays for tracking outcomes:
declare -a OKLIST WARNINGLIST SKIPPEDLIST FAILEDLIST ABORTEDLIST

# Validate $OPT_CHROOT:
if [ "$OPT_CHROOT" != 'n' ]; then
if [ ! -d "$OPT_CHROOT" ]; then
log_error "chroot is not a directory: $OPT_CHROOT"; exit_cleanup 4
elif [ ! -x "$OPT_CHROOT"/bin/bash ]; then
log_error "Not a usable chroot: $OPT_CHROOT"; exit_cleanup 4
else
OPT_CHROOT=$(realpath "$OPT_CHROOT")
fi
fi

# Create directories:
[ -d "$SR_SBREPO" ] || \
{ log_normal "Creating SlackBuild repository: $SR_SBREPO" ; mkdir -p "$SR_SBREPO" || \
Expand Down

0 comments on commit 65b100d

Please sign in to comment.