k8s-deployment/scripts/add_xray_user.sh

52 lines
1.6 KiB
Bash
Raw Permalink Normal View History

2024-10-10 19:12:29 +00:00
#!/usr/bin/env bash
set -e
CONFIG=$(sops -d ./values/badhouseplants/secrets.server-xray-public.yaml | yq '.files.config.entries."config.json".data' | jq)
read -p "Enter fullname (Ivan Ivanov): " FULLNAME
read -p "Enter email (ivan@fakemail.net): " EMAIL
PASS=$(openssl rand -base64 10)
2024-10-11 12:05:12 +00:00
export DOCKER="${CONTAINER_TOOL:-docker}"
echo "Generating UUID, please wait"
UUID=$(${DOCKER} run ghcr.io/xtls/xray-core:main uuid -i "${FULLNAME}")
2024-10-10 19:12:29 +00:00
CONFIG_ENTRY=$(cat <<-EndOfMessage
[
{
"id": "${FULLNAME} ${PASS}",
"flow": "xtls-rprx-vision",
"level": 0,
"email": "${EMAIL}"
}
]
EndOfMessage
)
echo "You're about to add a following entry to the config, is it correct?"
echo "${CONFIG_ENTRY}"
read -p "Type 'YES' to continue " AGREE
if [ "${AGREE}" != "YES" ]; then echo "Alright, goodbye" && exit 1; fi
NEW_CONFIG=$(jq '.inbounds[].settings.clients += '"${CONFIG_ENTRY}"'' <<< "${CONFIG}" | jq)
2024-10-11 12:05:12 +00:00
export NEW_CONFIG
sops -d ./values/badhouseplants/secrets.server-xray-public.yaml | yq '.files.config.entries."config.json".data = strenv(NEW_CONFIG)' > ./values/badhouseplants/secrets.server-xray-public.yaml
sops encrypt -i ./values/badhouseplants/secrets.server-xray-public.yaml
2024-10-10 19:12:29 +00:00
echo "Does the diff looks correct?"
2024-10-11 12:05:12 +00:00
helmfile -e badhouseplants -f ./installations/applications -l name=server-xray-public diff
2024-10-10 19:12:29 +00:00
read -p "Type 'YES' to continue " AGREE
if [ "${AGREE}" != "YES" ]; then echo "Alright, goodbye" && exit 1; fi
2024-10-11 12:05:12 +00:00
export FULLNAME
export BRANCH="add-$(echo $FULLNAME | sed -e 's/ /_/g')-to-xray"
2024-10-10 19:12:29 +00:00
2024-10-11 12:05:12 +00:00
git checkout -b $BRANCH
git add ./values/badhouseplants/secrets.server-xray-public.yaml
git commit -m "xray maintenance: adding ${FULLNAME}"
git push
2024-10-10 19:12:29 +00:00
2024-10-11 12:05:12 +00:00
echo $UUID