summaryrefslogtreecommitdiff
path: root/setup-hostname.in
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2015-04-28 11:32:28 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2015-04-28 11:32:28 +0000
commit6033ee2c3cfef05ce2b6a26e6557ba42aba2ea3e (patch)
tree30fdfbc15ecfa79a005b498937312d5b89a21955 /setup-hostname.in
parentb3006f309275ffb295bb3e13ea817e70283c6a60 (diff)
downloadalpine-conf-6033ee2c3cfef05ce2b6a26e6557ba42aba2ea3e.zip
setup-hostname: fix validation when non-interacitve
When we specify the hostname as an arg we run the tool non-interactively and we only set it if the specified hostname is valid.
Diffstat (limited to 'setup-hostname.in')
-rw-r--r--setup-hostname.in18
1 files changed, 10 insertions, 8 deletions
diff --git a/setup-hostname.in b/setup-hostname.in
index 16d9b6b..20164bd 100644
--- a/setup-hostname.in
+++ b/setup-hostname.in
@@ -50,14 +50,16 @@ if [ -z "$name" ] && [ $# -eq 1 ]; then
name="$1"
fi
-while true; do
- if [ -n "$name" ]; then
- HOST="$name"
- else
- HOST=`hostname`
- echon "Enter system hostname (short form, e.g. 'foo') [$HOST]: "
- default_read HOST `hostname`
- fi
+# if name is set, then we run non-interactively
+if [ -n "$name" ] && ! valid_hostname "$name"; then
+ exit 1
+fi
+
+HOST="$name"
+while [ -z "$name" ]; do
+ HOST=`hostname`
+ echon "Enter system hostname (short form, e.g. 'foo') [$HOST]: "
+ default_read HOST "$HOST"
if valid_hostname "$HOST"; then
break
fi