pretty-hostname: don't cancel script whey trying to remove nonexistent pretty_hostname
This commit is contained in:
parent
2cfa9dad0b
commit
c24cdae830
|
@ -1,15 +1,13 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
case $# in
|
case $# in
|
||||||
0)
|
0)
|
||||||
uci -q get 'system.@system[0].pretty_hostname' || uci get 'system.@system[0].hostname'
|
uci -q get 'system.@system[0].pretty_hostname' || uci get 'system.@system[0].hostname'
|
||||||
;;
|
;;
|
||||||
1)
|
1)
|
||||||
local pretty_hostname="$1"
|
pretty_hostname="$1"
|
||||||
# Remove invalid characters and leading/trailing spaces
|
# 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="${hostname:0:63}"
|
||||||
hostname="$(echo -n "$hostname" | sed -e 's/-$//')"
|
hostname="$(echo -n "$hostname" | sed -e 's/-$//')"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue