1
0
Fork 0
mirror of https://github.com/iiab/iiab.git synced 2025-03-09 15:40:17 +00:00

iiab-support output more vivid: ANSI/VT100 colors/highlighting

This commit is contained in:
root 2021-08-19 02:02:24 -04:00
parent c1e5052722
commit c8a8dd85bc

View file

@ -30,8 +30,8 @@ read ans < /dev/tty
# BEHAVIOR LIKE ANSIBLE'S parsing of vars from .yml: # BEHAVIOR LIKE ANSIBLE'S parsing of vars from .yml:
# (0) No need to remove hash/comments b/c it's live input here, unlike above. # (0) No need to remove hash/comments b/c it's live input here, unlike above.
# (1) sed: Remove outer spacing IF NEC, then... # (1) sed: Trim outer spacing IF NEC, then...
# (2) sed: Remove 1 pair of matching outer quotes (IF NEC) # (2) sed: Trim 1 pair of matching outer quotes (IF NEC)
# (3) Ansible vars can have non-string value null. SEE /opt/iiab/iiab/test.yml # (3) Ansible vars can have non-string value null. SEE /opt/iiab/iiab/test.yml
# Here in bash, we focus only on string values e.g. "" empty string if nec. # Here in bash, we focus only on string values e.g. "" empty string if nec.
# (4) When writing to disk, we aggressively overwrite such null var lines, e.g. # (4) When writing to disk, we aggressively overwrite such null var lines, e.g.
@ -39,9 +39,10 @@ read ans < /dev/tty
ans=$(echo $ans | sed "s/^\s*//; s/\s*$//; s/^\(['\"]\)\(.*\)\1$/\2/") ans=$(echo $ans | sed "s/^\s*//; s/\s*$//; s/^\(['\"]\)\(.*\)\1$/\2/")
# if ( [ "$ans" = "$handle" ] || [ "$ans" = "" ] ) && [ "$handle" != "" ]; then # Overkill if [ "$ans" = "" ]; then # (A) Simple! Writes to local_vars.yml a bit more than nec.
if [ "$ans" = "" ] || [ "$ans" = "$handle" ]; then # if [ "$ans" = "" ] || [ "$ans" = "$handle" ]; then # (B) Only write to disk when nec?
echo -e "\n\e[1mWARNING: openvpn_handle remains unchanged in /etc/iiab/local_vars.yml\e[0m\n" # if ( [ "$ans" = "" ] || [ "$ans" = "$handle" ] ) && [ "$handle" != "" ]; then # (C) Overkill
echo -e "\n \e[100mopenvpn_handle REMAINS UNCHANGED IN /etc/iiab/local_vars.yml\e[0m\n"
else else
if grep -q '^openvpn_handle:' /etc/iiab/local_vars.yml; then if grep -q '^openvpn_handle:' /etc/iiab/local_vars.yml; then
sed -i "s/^openvpn_handle:.*/openvpn_handle: $ans/" /etc/iiab/local_vars.yml sed -i "s/^openvpn_handle:.*/openvpn_handle: $ans/" /etc/iiab/local_vars.yml
@ -49,7 +50,7 @@ else
echo "openvpn_handle: $ans" >> /etc/iiab/local_vars.yml echo "openvpn_handle: $ans" >> /etc/iiab/local_vars.yml
fi fi
echo -e "\n\e[1mSAVED YOUR NEW openvpn_handle to /etc/iiab/local_vars.yml\e[0m\n" echo -e "\n \e[7mSAVED TO: /etc/iiab/local_vars.yml\e[0m\n"
handle=$ans; # For display at bottom handle=$ans; # For display at bottom
fi fi
@ -121,6 +122,6 @@ vpnip=$(ip a | grep tun0$ | awk '{print $2}')
if [ "$vpnip" != "" ]; then if [ "$vpnip" != "" ]; then
echo -e "\nYour OpenVPN IP address (which can change) is: \e[32m$vpnip\e[0m\n" echo -e "\nYour OpenVPN IP address (which can change) is: \e[32m$vpnip\e[0m\n"
else else
echo -e "\n \e[41m ERROR: OpenVPN IP address not ready - PLEASE TRY THE ABOVE TIPS \e[0m\n" echo -e "\n\n \e[41m ERROR: OpenVPN IP address not ready - PLEASE TRY THE ABOVE TIPS \e[0m\n"
exit 1 exit 1
fi fi