pretty-hostname: don't cancel script whey trying to remove nonexistent pretty_hostname

This commit is contained in:
Matthias Schiffer 2016-08-27 21:23:24 +02:00
parent 2cfa9dad0b
commit c24cdae830
1 changed files with 2 additions and 4 deletions

View File

@ -1,15 +1,13 @@
#!/bin/sh
set -e
case $# in
0)
uci -q get 'system.@system[0].pretty_hostname' || uci get 'system.@system[0].hostname'
;;
1)
local pretty_hostname="$1"
pretty_hostname="$1"
# Remove invalid characters and leading/trailing spaces
local hostname="$(echo -n "$pretty_hostname" | sed -r -e 's/[^a-zA-Z0-9-]//g' -e 's/-+/-/g' -e 's/^-//')"
hostname="$(echo -n "$pretty_hostname" | sed -r -e 's/[^a-zA-Z0-9-]//g' -e 's/-+/-/g' -e 's/^-//')"
hostname="${hostname:0:63}"
hostname="$(echo -n "$hostname" | sed -e 's/-$//')"