summaryrefslogtreecommitdiff
path: root/src/chroot-tools
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2013-06-05 20:06:19 -0600
committerLuke Shumaker <LukeShu@sbcglobal.net>2013-06-05 20:06:19 -0600
commitdc75575a17044cd35d310ccd0a892f630f7f53cc (patch)
treec2be02bb0c39c152786946ba446fc3f994853c0c /src/chroot-tools
parent90359e5549190507c24b3ac1111a55ced8e6c10c (diff)
libre{chroot,makepkg}: improve handling of when not configured
Diffstat (limited to 'src/chroot-tools')
-rwxr-xr-xsrc/chroot-tools/librechroot48
-rwxr-xr-xsrc/chroot-tools/libremakepkg10
2 files changed, 36 insertions, 22 deletions
diff --git a/src/chroot-tools/librechroot b/src/chroot-tools/librechroot
index a2394d7..9e98126 100755
--- a/src/chroot-tools/librechroot
+++ b/src/chroot-tools/librechroot
@@ -22,7 +22,6 @@
. $(librelib conf.sh)
load_files chroot
-[[ -f /.arch-chroot ]] || check_vars chroot CHROOTDIR CHROOT
. libremessages
. $(librelib makechrootpkg)
@@ -42,6 +41,7 @@ make_empty_repo() {
cmd=${0##*/}
usage() {
+ calculate_directories
echo "Usage: $cmd [OPTIONS] COMMAND [ARGS...]"
echo 'Interacts with an archroot (arch chroot).'
echo ''
@@ -63,11 +63,11 @@ usage() {
echo 'in which case, that path is used.'
echo ''
echo 'The current settings for the above varibles are:'
- echo " CHROOTDIR : $CHROOTDIR"
- echo " CHROOT : $CHROOT"
+ echo " CHROOTDIR : ${CHROOTDIR:-ERROR: NO SETTING}"
+ echo " CHROOT : ${CHROOT:-ERROR: NO SETTING}"
echo " COPY : $COPY"
- echo " root path : $rootdir"
- echo " copy path : $copydir"
+ echo " root path : ${rootdir:-ERROR}"
+ echo " copy path : ${copydir:-ERROR}"
echo ''
echo 'If the chroot, or copy does not exist, it will be created'
echo 'automatically. A chroot by default contains the packages in the'
@@ -110,15 +110,31 @@ usage() {
echo ' help Show this message'
}
+# set $rootdir and $copydir; blank them on error
+calculate_directories() {
+ # Don't assume that CHROOTDIR or CHROOT are set,
+ # but assume that COPY is set.
+
+ if [[ -n ${CHROOTDIR:-} ]] && [[ -n ${CHROOT:-} ]]; then
+ rootdir="${CHROOTDIR}/${CHROOT}/root"
+ else
+ rootdir=''
+ fi
+
+ if [[ ${COPY:0:1} = / ]]; then
+ copydir=$COPY
+ elif [[ -n ${CHROOTDIR:-} ]] && [[ -n ${CHROOT:-} ]]; then
+ copydir="${CHROOTDIR}/${CHROOT}/${COPY}"
+ else
+ copydir=''
+ fi
+}
+
# Globals: $CHROOTDIR, $CHROOT, $COPY, $rootdir and $copydir
main() {
COPY=$LIBREUSER
[[ $COPY != root ]] || COPY=copy
- # defaults
- rootdir="${CHROOTDIR}/${CHROOT}/root"
- copydir="${CHROOTDIR}/${CHROOT}/${COPY}"
-
local mode=enter
local archroot_args=()
while getopts 'n:l:NC:M:' arg; do
@@ -145,20 +161,16 @@ main() {
mode=$1
shift
- rootdir="${CHROOTDIR}/${CHROOT}/root"
- if [[ ${COPY:0:1} = / ]]; then
- copydir=$COPY
- else
- copydir="${CHROOTDIR}/${CHROOT}/${COPY}"
- fi
-
- ########################################################################
-
if [[ $mode == help ]]; then
usage
return 0
fi
+ check_vars chroot CHROOTDIR CHROOT
+ calculate_directories
+
+ ########################################################################
+
if (( EUID )); then
error "This program must be run as root."
return 1
diff --git a/src/chroot-tools/libremakepkg b/src/chroot-tools/libremakepkg
index b86506a..cd81876 100755
--- a/src/chroot-tools/libremakepkg
+++ b/src/chroot-tools/libremakepkg
@@ -22,7 +22,6 @@
. $(librelib conf.sh)
load_files chroot
-[[ -f /.arch-chroot ]] || check_vars chroot CHROOTDIR CHROOT
. libremessages
makechrootpkg=$(librelib makechrootpkg)
@@ -257,10 +256,13 @@ main() {
if $INCHROOT; then
copydir='/'
- elif [[ ${COPY:0:1} = / ]]; then
- copydir=$COPY
else
- copydir="${CHROOTDIR}/${CHROOT}/${COPY}"
+ check_vars chroot CHROOTDIR CHROOT
+ if [[ ${COPY:0:1} = / ]]; then
+ copydir=$COPY
+ else
+ copydir="${CHROOTDIR}/${CHROOT}/${COPY}"
+ fi
fi
# Init #################################################################