Link updates

pull/18/head
schizza 2024-04-28 16:33:33 +02:00
parent 69909e228c
commit 5dc35ec7ad
1 changed files with 31 additions and 9 deletions

View File

@ -9,7 +9,7 @@ NO_COLOR='\033[0m'
ST_PORT=80 ST_PORT=80
LINK="" LINK="https://raw.githubusercontent.com/schizza/SWS-12500-custom-component/main/iptables_redirect.sh"
P_HA=true P_HA=true
P_ST=true P_ST=true
@ -55,8 +55,8 @@ function validate_num() {
} }
function validate_dest() { function validate_dest() {
echo "Validating host '$1' ... " echo "Validating host '$2' ... "
if ping -c 4; then if ping -c 4 2>/dev/null; then
info "OK" info "OK"
true true
else else
@ -93,17 +93,17 @@ check "sed"
check "ping" false && { PING=true; } || { PING=false; } check "ping" false && { PING=true; } || { PING=false; }
echo -n "Trying to find Home Assitant ... " echo -n "Trying to find Home Assitant ... "
for PATH in "${HA_PATHS[@]}"; do for _PATH in "${HA_PATHS[@]}"; do
if [ -n "$HA_PATH" ]; then if [ -n "$HA_PATH" ]; then
break break
fi fi
if [ -f "$PATH/.HA_VERSION" ]; then if [ -f "$_PATH/.HA_VERSION" ]; then
HA_PATH="$PATH" HA_PATH="$_PATH"
fi fi
done done
#[ -z $HA_PATH ] && { error "Home Assistant not found!"; } [ -z $HA_PATH ] && { error "Home Assistant not found!"; }
info "found at $HA_PATH" info "found at $HA_PATH"
while true; do while true; do
@ -128,8 +128,28 @@ while true; do
done done
if $PING; then if $PING; then
validate_dest $HA_IP || { cont "Home Assistant host is unreachable."; P_HA=false; } validate_dest $HA_IP || {
validate_dest $ST_IP || { cont "Station is unreachable."; P_ST=false; } cont "Home Assistant host is unreachable."
P_HA=false
}
validate_dest $ST_IP || {
cont "Station is unreachable."
P_ST=false
}
fi
echo -n "Downloading 'iptables_redirect.sh' ... "
wget -q -O - "$LINK" | sed -e "s/\[_STATION_IP_\]/$ST_IP/" \
-e "s/\[_HA_\]/$HA_IP/" \
-e "s/\[_SRC_PORT_\]/$ST_PORT/" \
-e "s/\[_DST_PORT_\]/$HA_PORT/" >./iptables_redirect.sh
EXIT_STATUS=$?
if [ $EXIT_STATUS -ne 0 ]; then
warn "wget exited with error: $EXIT_STATUS"
error "Could not download 'iptables_redirect.sh'."
else
info "iptables_redirect.sh downloaded succeffully."
fi fi
info "\nYour configuration:" info "\nYour configuration:"
@ -146,3 +166,5 @@ if $PING; then
else else
error " (not tested)" false error " (not tested)" false
fi fi
/bin/bash ./iptables_redirect.sh