mirror of
https://github.com/iiab/iiab.git
synced 2025-03-09 15:40:17 +00:00
Properly emulate ./runrole openvpn + comment code
This commit is contained in:
parent
3afc93b5ae
commit
b39ecacde2
1 changed files with 15 additions and 7 deletions
|
@ -1,5 +1,8 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# openvpn_handle is stored in 2 files on disk, one slightly stripped down (from
|
||||||
|
# the other) due to Ansible. So we emulate Ansible's behavior, when reading from
|
||||||
|
# (and later writing to) disk, removing outer cruft as explained on Lines 28-30
|
||||||
handle1=$(grep "^openvpn_handle:" /etc/iiab/local_vars.yml | sed "s/^openvpn_handle:\s*\(['\"]\)\(.*\)\1\s*$/\2/")
|
handle1=$(grep "^openvpn_handle:" /etc/iiab/local_vars.yml | sed "s/^openvpn_handle:\s*\(['\"]\)\(.*\)\1\s*$/\2/")
|
||||||
echo -e "\n/etc/iiab/local_vars.yml source/master copy: $handle1"
|
echo -e "\n/etc/iiab/local_vars.yml source/master copy: $handle1"
|
||||||
if [ -f /etc/iiab/openvpn_handle ]; then
|
if [ -f /etc/iiab/openvpn_handle ]; then
|
||||||
|
@ -11,23 +14,28 @@ fi
|
||||||
|
|
||||||
echo -en "\e[1mPlease type a descriptive OpenVPN machine name (openvpn_handle) such as:\n\n cape-town-school-36-rpi-2019-05-31\n\nOr hit [Enter] to keep the existing name:\e[0m "
|
echo -en "\e[1mPlease type a descriptive OpenVPN machine name (openvpn_handle) such as:\n\n cape-town-school-36-rpi-2019-05-31\n\nOr hit [Enter] to keep the existing name:\e[0m "
|
||||||
read ans < /dev/tty
|
read ans < /dev/tty
|
||||||
ans=$(echo $ans | sed "s/^\s*\(['\"]\)\(.*\)\1\s*$/\2/")
|
|
||||||
|
|
||||||
#if [ "$ans" != "" ] || ( [ "$handle1" = "" ] && [ ! -f /etc/iiab/openvpn_handle ] ); then
|
#if [ "$ans" != "" ] || ( [ "$handle1" = "" ] && [ ! -f /etc/iiab/openvpn_handle ] ); then
|
||||||
if [ "$ans" != "" ] || ( [ "$handle1" = "" ] && [ ! -v handle2 ] ); then # equivalent to above
|
# -v (below) checks if var's defined: equivalent to file existence test above
|
||||||
|
if [ "$ans" != "" ] || ( [ "$handle1" = "" ] && [ ! -v handle2 ] ); then
|
||||||
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
|
||||||
else
|
else
|
||||||
echo "openvpn_handle: $ans" >> /etc/iiab/local_vars.yml
|
echo "openvpn_handle: $ans" >> /etc/iiab/local_vars.yml
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# BEHAVIOR JUST LIKE ANSIBLE'S: create /etc/iiab/openvpn_handle from the
|
||||||
|
# "^openvpn_handle:" line in /etc/iiab/local_vars.yml by (1) removing outer
|
||||||
|
# spacing IF NEC, then (2) removing 1 pair of matching outer quotes IF NEC.
|
||||||
|
ans=$(echo $ans | sed "s/^\s*\(['\"]\)\(.*\)\1\s*$/\2/")
|
||||||
echo $ans > /etc/iiab/openvpn_handle
|
echo $ans > /etc/iiab/openvpn_handle
|
||||||
echo -e "\n\e[1mSAVED: openvpn_handle recorded into both above files.\e[0m\n"
|
echo -e "\n\e[1mSAVED: openvpn_handle recorded into both above files.\e[0m\n"
|
||||||
|
elif [ "$handle1" != "$handle2" ]; then # Sloppily, but conveniently here,
|
||||||
|
# bash treats "$handle2" as "" when var undefined, catching all conflicts!
|
||||||
|
echo -e "\n\e[41mYou MUST specify an OpenVPN machine name (openvpn_handle) to resolve the above\e[0m"
|
||||||
|
echo -e "\e[41mnaming conflict. Please rerun to proceed.\e[0m\n"
|
||||||
|
exit 1
|
||||||
else
|
else
|
||||||
if [ "$handle1" != "$handle2" ]; then # sloppily (but conveniently here) bash treats "$handle2" as "" when var's not defined!
|
|
||||||
echo -e "\n\e[41mYou MUST specify an OpenVPN machine name (openvpn_handle) to resolve the above\e[0m"
|
|
||||||
echo -e "\e[41mnaming conflict. Please rerun to proceed.\e[0m\n"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
echo -e "\n\e[1mWARNING: openvpn_handle remains unchanged in both above files.\e[0m\n"
|
echo -e "\n\e[1mWARNING: openvpn_handle remains unchanged in both above files.\e[0m\n"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue