summaryrefslogtreecommitdiff
path: root/manage-baserock
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2014-06-16 16:48:53 +0100
committerSam Thursfield <sam.thursfield@codethink.co.uk>2014-06-16 16:56:25 +0100
commita1df7cd597fb1087b678933c2bc3c5f95ed7a1ff (patch)
treed8d42a22c227dcea265919b545fc7ea25444dc61 /manage-baserock
parent169bcef7a5e0b25e26861dff086ef63c5b695c67 (diff)
downloadbaserock-chroot-a1df7cd597fb1087b678933c2bc3c5f95ed7a1ff.tar.gz
Raise an error when system name is invalid
This is better than proceeding to add a system with a different name to the one the user specified, without telling them that the name was mangled.
Diffstat (limited to 'manage-baserock')
-rwxr-xr-xmanage-baserock17
1 files changed, 15 insertions, 2 deletions
diff --git a/manage-baserock b/manage-baserock
index acee510..8210812 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,6 +54,8 @@ 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
@@ -105,7 +118,7 @@ EOF
fi
br-ct-sync-chroots
-
+
;;
rm)
if test $(id -u) != "0"; then