2023-02-23 05:44:27 +00:00
|
|
|
#!/bin/bash
|
2023-02-22 16:49:54 +00:00
|
|
|
|
|
|
|
# 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"
|
|
|
|
;;
|
2023-02-22 16:49:54 +00:00
|
|
|
*)
|
2024-05-14 02:34:28 +00:00
|
|
|
echo "ERROR: No persistent storage found." 1>&2
|
|
|
|
exit 1
|
|
|
|
;;
|
2023-02-22 16:49:54 +00:00
|
|
|
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.
|
2023-02-22 16:49:54 +00:00
|
|
|
# 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 \
|
2023-02-22 16:49:54 +00:00
|
|
|
-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
|