summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2014-06-17 09:45:47 (GMT)
committerSam Thursfield <sam.thursfield@codethink.co.uk>2014-06-17 09:45:47 (GMT)
commit5de20e562aee3213e09f569f0976eefc7c1132c5 (patch)
tree11b092ea0f104fc579ccec73e19a0c7412b785be
parente83ee0e46b11ac08706044388c6990fa048cfdc2 (diff)
parentd28cf3af108c45101cf254a56334426614521091 (diff)
downloadbaserock-chroot-5de20e562aee3213e09f569f0976eefc7c1132c5.tar.gz
Merge branch 'sam/niceties'
Reviewed-By: Richard Maw <richard.maw@codethink.co.uk>
-rwxr-xr-xmanage-baserock30
1 files changed, 27 insertions, 3 deletions
diff --git a/manage-baserock b/manage-baserock
index c878d18..b3a8f52 100755
--- a/manage-baserock
+++ b/manage-baserock
@@ -21,9 +21,20 @@
BASEROCK_BASE="${BASEROCK_BASE:-/opt/baserock/chroots}"
ACTION="$1"
-SYSTEM=$(echo $2 | tr -c -d A-Za-z0-9_-)
+SYSTEM="$2"
URL="$3"
+check_system_name () {
+ local system="$1"
+ local valid_chars='A-Za-z0-9_-.'
+ case $system in
+ *[^${valid_chars}]*)
+ echo "The specified name '${system}' contains invalid characters."
+ echo "Valid characters are ${valid_chars}."
+ exit 1
+ esac
+}
+
list_baserocks () {
(cd "${BASEROCK_BASE}" && ls -d */baserock) 2>/dev/null | sed -e's@/baserock$@@'
}
@@ -43,16 +54,29 @@ case "${ACTION}" in
exec sudo "$0" "$@"
fi
+ check_system_name $SYSTEM
+
if test -d "${BASEROCK_BASE}/${SYSTEM}/baserock"; then
echo "Sorry, $SYSTEM already exists"
exit 1
fi
-
+
+ if test -z "$URL"; then
+ echo "Usage: $0 add <name> <url>"
+ exit 1
+ fi
+
+ mkdir -p ${BASEROCK_BASE}
+
TEMP_BASE=$(mktemp -d --tmpdir="${BASEROCK_BASE}")
cleanup () { rm -rf "${TEMP_BASE}"; }
trap cleanup 0
if test "x${URL}" = "x${URL##http://}" -a "x${URL}" = "x${URL##https://}"; then
+ if ! test -e ${URL}; then
+ echo "${URL} is neither a HTTP/HTTPS url nor a path to a local file";
+ exit 1;
+ fi
if ! ln -s "$(readlink -e "${URL}")" "${TEMP_BASE}/tarball"; then
echo "Sorry, could not link ${URL} into place";
exit 1;
@@ -105,7 +129,7 @@ EOF
fi
br-ct-sync-chroots
-
+
;;
rm)
if test $(id -u) != "0"; then