Skip to content

Commit

Permalink
DEBUG: print all lines before execution (#2096)
Browse files Browse the repository at this point in the history
* DEBUG: print all lines before execution

if var DEBUG is set to anything other than false, each bash script will be run with a set -x. This would ease debugging

* DEBUG: centralize commands in utils.sh
  • Loading branch information
edgd1er authored Dec 4, 2021
1 parent 22f1998 commit af3d905
Show file tree
Hide file tree
Showing 25 changed files with 62 additions and 7 deletions.
8 changes: 8 additions & 0 deletions docs/config-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,11 @@ Once /scripts is mounted you'll need to write your custom code in the following
| /scripts/transmission-post-stop.sh | This shell script will be executed after transmission stop |

Don't forget to include the #!/bin/bash shebang and to make the scripts executable using chmod a+x

### Debugging

By default, commands are not echoed to stdout before being processed. Setting DEBUG to any value other than the string false will trigger command echo (set -x) for all bash scripts.

| Variable | Function |Example|
| ----------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
|DEBUG|Echo all commands to stdout.|DEBUG=true|
2 changes: 2 additions & 0 deletions openvpn/adjustConfigs.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

source /etc/openvpn/utils.sh

bold=$(tput bold)
normal=$(tput sgr0)

Expand Down
4 changes: 3 additions & 1 deletion openvpn/fetch-external-configs.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#! /bin/bash
#!/bin/bash

set -o nounset
set -o errexit
set -o pipefail

source /etc/openvpn/utils.sh

VPN_CONFIG_SOURCE_TYPE="${VPN_CONFIG_SOURCE_TYPE:-github_zip}"

# Set default GitHub config repo
Expand Down
2 changes: 2 additions & 0 deletions openvpn/ipvanish/configure-openvpn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

set -e

source /etc/openvpn/utils.sh

baseURL="https://www.ipvanish.com/software/configs"
CONFIG_BUNDLE="configs.zip"

Expand Down
2 changes: 2 additions & 0 deletions openvpn/modify-openvpn-config.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

source /etc/openvpn/utils.sh

if [ "$#" -ne 1 ]; then
echo "Illegal number of parameters"
exit 1
Expand Down
4 changes: 3 additions & 1 deletion openvpn/nordvpn/configure-openvpn.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#! /bin/bash
#!/bin/bash

source /etc/openvpn/utils.sh

NORDVPN_PROTOCOL=${NORDVPN_PROTOCOL:-UDP}
export NORDVPN_PROTOCOL
Expand Down
1 change: 1 addition & 0 deletions openvpn/nordvpn/updateConfigs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

set -e
TIME_FORMAT=`date "+%Y-%m-%d %H:%M:%S"`
source /etc/openvpn/utils.sh

log() {
printf "${TIME_FORMAT} %b\n" "$*" > /dev/stderr;
Expand Down
1 change: 1 addition & 0 deletions openvpn/persistEnvironment.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

wanted_variables = {
'OPENVPN_PROVIDER',
'DEBUG',
'ENABLE_UFW',
'PUID',
'PGID',
Expand Down
4 changes: 3 additions & 1 deletion openvpn/pia/configure-openvpn.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /bin/bash
#!/bin/bash

set -e

Expand All @@ -8,6 +8,8 @@ set -e
# https://www.privateinternetaccess.com/openvpn/openvpn-tcp.zip
# https://www.privateinternetaccess.com/openvpn/openvpn-strong-tcp.zip

source /etc/openvpn/utils.sh

baseURL="https://www.privateinternetaccess.com/openvpn"
PIA_OPENVPN_CONFIG_BUNDLE=${PIA_OPENVPN_CONFIG_BUNDLE:-"openvpn"}

Expand Down
2 changes: 2 additions & 0 deletions openvpn/pia/update-port.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
## this is an amalgamation of two scripts to keep my PIA working, credit to the main authors, the original scripts linked in the READ.ME
#v0.2

source /etc/openvpn/utils.sh

. /etc/transmission/environment-variables.sh

# Settings
Expand Down
8 changes: 5 additions & 3 deletions openvpn/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
# Get some initial setup out of the way.
##

set -e

source /etc/openvpn/utils.sh

if [[ -n "$REVISION" ]]; then
echo "Starting container with revision: $REVISION"
fi

[[ "${DEBUG}" == "true" ]] && set -x

# If openvpn-pre-start.sh exists, run it
if [[ -x /scripts/openvpn-pre-start.sh ]]; then
echo "Executing /scripts/openvpn-pre-start.sh"
Expand All @@ -32,7 +34,7 @@ if ! nslookup ${HEALTH_CHECK_HOST:-"google.com"} 1>/dev/null 2>&1; then
fi

# If create_tun_device is set, create /dev/net/tun
if [[ "${CREATE_TUN_DEVICE,,}" == "true" ]]; then
if [[ "${CREATE_TUN_DEVICE,,}" == "true" ]] ; then
echo "Creating TUN device /dev/net/tun"
mkdir -p /dev/net
mknod /dev/net/tun c 10 200
Expand Down
4 changes: 4 additions & 0 deletions openvpn/tunnelDown.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/bin/bash
#tunnel is down, restore resolv.conf to previous version
# Source our persisted env variables from container startup
. /etc/transmission/environment-variables.sh
source /etc/openvpn/utils.sh

if ls /etc/resolv.conf-*.sv 1> /dev/null 2>&1; then
cp /etc/resolv.conf-*.sv /etc/resolv.conf
echo "resolv.conf was restored"
Expand Down
2 changes: 2 additions & 0 deletions openvpn/tunnelUp.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash
# Source our persisted env variables from container startup
. /etc/transmission/environment-variables.sh
source /etc/openvpn/utils.sh


if [[ "${PEER_DNS,,}" == "true" ]]; then
NS=
Expand Down
2 changes: 1 addition & 1 deletion openvpn/updateConfigs.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash

set -e
source /etc/openvpn/utils.sh

# Parent script for updating OpenVPN configs

# If the script is called from elsewhere
cd "${0%/*}"

Expand Down
4 changes: 4 additions & 0 deletions openvpn/utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

DEBUG=${DEBUG:-"false"}
[[ ${DEBUG} != "false" ]] && set -x
2 changes: 2 additions & 0 deletions openvpn/vyprvpn/configure-openvpn.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash
# https://support.vyprvpn.com/hc/en-us/articles/360038096131-Where-can-I-find-the-OpenVPN-files-

source /etc/openvpn/utils.sh

if [[ -z "$VPN_PROVIDER_HOME" ]]; then
echo "ERROR: Need to have VPN_PROVIDER_HOME set to call this script" && exit 1
fi
Expand Down
2 changes: 2 additions & 0 deletions plugins/rss/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
# 1. Mount a custom config file to be used
# 2. Use the built in template that supports one feed with regex filter
#
. /etc/transmission/environment-variables.sh
source /etc/openvpn/utils.sh

if [ -f /etc/transmission-rss.conf ] ; then
echo "Found mounted /etc/transmission-rss.conf file"
Expand Down
2 changes: 2 additions & 0 deletions privoxy/scripts/start.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/bin/bash


# Source our persisted env variables from container startup
. /etc/transmission/environment-variables.sh
source /etc/openvpn/utils.sh

set_port()
{
Expand Down
2 changes: 2 additions & 0 deletions privoxy/scripts/stop.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash
# Source our persisted env variables from container startup

. /etc/transmission/environment-variables.sh
source /etc/openvpn/utils.sh

if [[ "${WEBPROXY_ENABLED}" = "true" ]]; then

Expand Down
2 changes: 2 additions & 0 deletions scripts/healthcheck.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

source /etc/openvpn/utils.sh

# Handle SIGTERM
sigterm() {
echo "Received SIGTERM, exiting..."
Expand Down
2 changes: 2 additions & 0 deletions scripts/route-pre-down.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash
# redirect stdout/stderr to a file
source /etc/openvpn/utils.sh

#exec &>>route-pre-down.log

#Print Date
Expand Down
1 change: 1 addition & 0 deletions scripts/selfheal.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash

source /etc/openvpn/utils.sh
SELFHEAL_INTERVAL=${SELFHEAL_INTERVAL:-1m}
SELFHEAL_TIMEOUT=${SELFHEAL_TIMEOUT:-30s}
SELFHEAL_START_PERIOD=${SELFHEAL_START_PERIOD:-0s}
Expand Down
2 changes: 2 additions & 0 deletions transmission/start.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

source /etc/openvpn/utils.sh

# Source our persisted env variables from container startup
. /etc/transmission/environment-variables.sh

Expand Down
3 changes: 3 additions & 0 deletions transmission/stop.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#! /bin/bash

. /etc/transmission/environment-variables.sh
source /etc/openvpn/utils.sh

# If transmission-pre-stop.sh exists, run it
if [[ -x /scripts/transmission-pre-stop.sh ]]
then
Expand Down
1 change: 1 addition & 0 deletions transmission/userSetup.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash

# More/less taken from https://github.com/linuxserver/docker-baseimage-alpine/blob/3eb7146a55b7bff547905e0d3f71a26036448ae6/root/etc/cont-init.d/10-adduser
source /etc/openvpn/utils.sh

RUN_AS=root

Expand Down

0 comments on commit af3d905

Please sign in to comment.