IP=
HAS_IPV6=
NO_IPV6=
+LOCATION=
REAL_HOSTSFILE='/etc/hosts'
FAKE_HOSTSFILE='/tmp/hosts'
USED_HOSTSFILE="${REAL_HOSTSFILE}"
-SIMULATE="y"
-
#------------------------------------------------------------------------------
get_ip() {
local iface=
fi
}
+#------------------------------------------------------------------------------
+get_os_major_rerlease() {
+
+ (
+ source /etc/os-release
+ echo "${VERSION_ID}" | sed -e 's/\..*//'
+ )
+
+}
+
+OS_MAJOR_RELEASE=$( get_os_major_rerlease )
NODENAME=$( hostname --short )
FQDN=$( hostname --fqdn )
get_ip
#------------------------------------------------------------------------------
usage() {
cat <<-EOF
- Usage: ${BASE_NAME} ${STD_USAGE} [-N|--no-ipv6]
+ Usage: ${BASE_NAME} ${STD_USAGE} [-N|--no-ipv6] [-L|--location LOCATION]
${BASE_NAME} [-h|--help]
${BASE_NAME} [-V|--version]
get_options() {
local tmp=
- local short_options="N${STD_SHORT_OPTIONS}"
- local long_options="no-ipv6,${STD_LONG_OPTIONS}"
+ local short_options="NL:${STD_SHORT_OPTIONS}"
+ local long_options="no-ipv6,location;,${STD_LONG_OPTIONS}"
set +e
tmp=$( getopt -o "${short_options}" --long "${long_options}" -n "${BASE_NAME}" -- "$@" )
NO_IPV6='y'
i=$(( i + 1 ))
;;
+ -L|--location)
+ j=$(( $i + 1 ))
+ LOCATION="${REMAINING_OPTS[$j]}"
+ i=$(( $i + 2 ))
+ ;;
*) echo -e "Internal error - option '${RED}${arg}${NORMAL} was wrong!"
exit 1
;;
}
+#------------------------------------------------------------------------------
+manage_hostname() {
+
+ empty_line
+ info "Setting hostname to '${CYAN}${NODENAME}${NORMAL}' ..."
+
+ local cmd
+
+ cmd="hostnamectl hostname \"${NODENAME}\""
+ if [[ "${SIMULATE}" == "y" ]] ; then
+ info "Simulated excuting: ${cmd}"
+ else
+ debug "Excuting: ${cmd}"
+ eval ${cmd}
+ fi
+
+ if [[ -n "${LOCATION}" ]] ; then
+
+ empty_line
+ info "Setting location to '${CYAN}${LOCATION}${NORMAL}' ..."
+
+ cmd="hostnamectl location \"${LOCATION}\""
+ if [[ "${SIMULATE}" == "y" ]] ; then
+ info "Simulated excuting: ${cmd}"
+ else
+ debug "Excuting: ${cmd}"
+ eval ${cmd}
+ fi
+
+ fi
+
+ if [[ "${QUIET}" != 'y' ]] ; then
+ empty_line
+ info "Current status of hostnamectl:"
+ cmd="hostnamectl status"
+ debug "Excuting: ${cmd}"
+ eval ${cmd}
+ fi
+
+}
+
################################################################################
##
## Main
generate
+ if [[ "${OS_MAJOR_RELEASE}" -ge 9 ]] ; then
+ manage_hostname
+ fi
+
}
main "$@"