aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Bilyk <jbilyk@gmail.com>2011-08-05 21:40:36 -0400
committerJeff Bilyk <jbilyk@gmail.com>2011-08-05 21:40:36 -0400
commit9107a682412905f066c241b34cba7aa06fa1f945 (patch)
tree49f25c0d2cd5acfc7054ef2032602764393290ad
parent0aeb9386c29ca4aa9cb3be058c7b15042df21daf (diff)
downloadalpine-conf-9107a682412905f066c241b34cba7aa06fa1f945.tar.bz2
alpine-conf-9107a682412905f066c241b34cba7aa06fa1f945.tar.xz
setup-hostname: add an option to specify hostname
-rwxr-xr-xsetup-hostname.in32
1 files changed, 29 insertions, 3 deletions
diff --git a/setup-hostname.in b/setup-hostname.in
index f97f487..c551de7 100755
--- a/setup-hostname.in
+++ b/setup-hostname.in
@@ -5,6 +5,20 @@ PREFIX=
. $PREFIX/lib/libalpine.sh
+usage() {
+ cat <<__EOF__
+usage: setup-hostname [-h] [-n hostname]
+
+Sets the system hostname.
+
+options:
+ -h Show this help
+ -n Specify the hostname to set
+__EOF__
+ exit 1
+}
+
+
# http://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names
valid_hostname() {
# check length
@@ -24,10 +38,22 @@ valid_hostname() {
return 0
}
+while getopts "hn:" opt; do
+ case $opt in
+ h) usage;;
+ n) HOSTNAME="$OPTARG";;
+ esac
+done
+
+
while true; do
- HOST=`hostname`
- echon "Enter system hostname (short form, e.g. 'foo') [$HOST]: "
- default_read HOST `hostname`
+ if [ -n "$HOSTNAME" ]; then
+ HOST="$HOSTNAME"
+ else
+ HOST=`hostname`
+ echon "Enter system hostname (short form, e.g. 'foo') [$HOST]: "
+ default_read HOST `hostname`
+ fi
if valid_hostname "$HOST"; then
break
fi