Skip to content

Optimize pqap.sh script #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 25 additions & 47 deletions pqap/package/pqap.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ function pqap_stop(){
}

# Exit if the specified interface is not present
function ensure_interface_up(){

function check_and_ensure_interface_up(){
ifconfig $1 up

local output=`ifconfig |grep -o $1`;
Expand All @@ -71,18 +70,6 @@ function ensure_interface_up(){
fi
}

# Return 1 if the interface is present, 0 otherwise
function is_interface_up(){

local output=`ifconfig |grep -o $1`;
if [ "$output" == "$1" ] ; then
echo 1;
else
echo 0;
fi
}


function start_openvpn(){

echo "Starting OpenVPN"
Expand Down Expand Up @@ -110,32 +97,6 @@ function start_openvpn(){

function pqap_restart(){
pqap_stop
pqap_start
}

function check_deps(){
if [ ! -e "$OPENSSL_LIB_PATH/libssl.so" ] ; then
echo "Missing $OPENSSL_LIB_PATH/libssl.so, is it installed?"
exit
fi
if [ ! -e "$OPENSSL_LIB_PATH/libcrypto.so" ] ; then
echo "Missing $OPENSSL_LIB_PATH/libcrypto.so, is it installed?"
exit
fi

if [ ! -e "$BASE_PATH/log/openvpn.log" ] ; then
# Run ldconfig on first boot to make sure the OQS fork of OpenSSL is
# by OpenVPN
ldconfig $OPENSSL_LIB_PATH
fi

# Make sure the system's instance of dnsmasq is not running; otherwise we
# can't start ours
systemctl stop dnsmasq
sleep 2
}

function pqap_start(){

check_deps

Expand All @@ -145,7 +106,7 @@ function pqap_start(){


# If the tunnel is up, we'll route traffic too
have_tunnel=$(is_interface_up $INET_DEVICE)
have_tunnel=$(check_and_ensure_interface_up $INET_DEVICE)

# make sure iptables is not fowarding
iptables --flush
Expand All @@ -162,7 +123,7 @@ function pqap_start(){
# disconnect anyone that might be using the web UI
if ! (pgrep -x "hostapd" > /dev/null) ; then
# We need the AP device to start the hotspot
ensure_interface_up $AP_DEVICE
check_and_ensure_interface_up $AP_DEVICE
hostapd $HOSTAPD_CONFIG -B -f $HOSTAPD_LOG
fi
# Note if hostapd is already started, and changes to the interface are made,
Expand All @@ -186,6 +147,27 @@ function pqap_start(){
fi
}

function check_deps(){
if [ ! -e "$OPENSSL_LIB_PATH/libssl.so" ] ; then
echo "Missing $OPENSSL_LIB_PATH/libssl.so, is it installed?"
exit
fi
if [ ! -e "$OPENSSL_LIB_PATH/libcrypto.so" ] ; then
echo "Missing $OPENSSL_LIB_PATH/libcrypto.so, is it installed?"
exit
fi

if [ ! -e "$BASE_PATH/log/openvpn.log" ] ; then
# Run ldconfig on first boot to make sure the OQS fork of OpenSSL is
# by OpenVPN
ldconfig $OPENSSL_LIB_PATH
fi

# Make sure the system's instance of dnsmasq is not running; otherwise we
# can't start ours
systemctl stop dnsmasq
sleep 2
}

#### main() ####

Expand All @@ -197,7 +179,7 @@ if [ "$1" = "stop" ] ; then

elif [ "$1" = "start" ] ; then

pqap_start
pqap_restart

elif [ "$1" = "restart" ] ; then
pqap_restart
Expand All @@ -208,7 +190,3 @@ else
echo "Usage:"
echo " $0 start|stop|restart"
fi