unifios-utilities/wireguard-go/on_boot.d/20-wireguard.sh

40 lines
1.0 KiB
Bash
Raw Normal View History

2023-02-23 05:44:27 +00:00
#!/bin/bash
# Get DataDir location
DATA_DIR="/data"
case "$(ubnt-device-info firmware || true)" in
1*)
2024-05-14 02:34:28 +00:00
DATA_DIR="/mnt/data"
;;
2* | 3* | 4*)
DATA_DIR="/data"
;;
*)
2024-05-14 02:34:28 +00:00
echo "ERROR: No persistent storage found." 1>&2
exit 1
;;
esac
# Check if the directory exists
if [ ! -d "${DATA_DIR}/wireguard" ]; then
# If it does not exist, create the directory
mkdir -p "${DATA_DIR}/wireguard"
echo "Directory '${DATA_DIR}/wireguard' created."
else
# If it already exists, print a message
echo "Directory '${DATA_DIR}/wireguard' already exists. Moving on."
fi
2020-07-13 07:03:06 +00:00
CONTAINER=wireguard
2020-07-13 05:54:09 +00:00
# Starts a wireguard container that is deleted after it is stopped.
# All configs stored in ${DATA_DIR}/wireguard
2020-07-13 07:03:06 +00:00
if podman container exists ${CONTAINER}; then
podman start ${CONTAINER}
else
podman run -i -d --rm --net=host --name ${CONTAINER} --privileged \
-v ${DATA_DIR}/wireguard:/etc/wireguard \
2020-07-13 05:54:09 +00:00
-v /dev/net/tun:/dev/net/tun \
-e LOG_LEVEL=info -e WG_COLOR_MODE=always \
2021-08-26 14:11:38 +00:00
masipcat/wireguard-go:0.0.20210424
2020-07-13 07:03:06 +00:00
fi