summaryrefslogtreecommitdiff
path: root/ntfy/install.sh
diff options
context:
space:
mode:
Diffstat (limited to 'ntfy/install.sh')
-rwxr-xr-xntfy/install.sh34
1 files changed, 34 insertions, 0 deletions
diff --git a/ntfy/install.sh b/ntfy/install.sh
new file mode 100755
index 0000000..f65f867
--- /dev/null
+++ b/ntfy/install.sh
@@ -0,0 +1,34 @@
+#!/usr/bin/env bash
+# 初回セットアップ: コンテナ起動 → 管理ユーザー作成 → status-app 用トークン発行
+set -euo pipefail
+cd "$(dirname "$0")"
+
+USER_NAME="${1:-admin}"
+TOPIC="${NTFY_TOPIC:-status}"
+STATUS_ENV="$(pwd)/../status/.env"
+
+bash ./deploy.sh
+sleep 2
+
+if docker exec ntfy ntfy user list 2>&1 | grep -q "^user $USER_NAME "; then
+ echo "User $USER_NAME already exists"
+else
+ echo "Creating ntfy admin user: $USER_NAME"
+ docker exec -it ntfy ntfy user add --role=admin "$USER_NAME"
+fi
+
+if grep -q '^NTFY_TOKEN=' "$STATUS_ENV" 2>/dev/null; then
+ echo "NTFY_TOKEN already set in $STATUS_ENV"
+else
+ TOKEN=$(docker exec ntfy ntfy token add --label=status-app "$USER_NAME" | grep -o 'tk_[a-z0-9]*')
+ {
+ echo "NTFY_URL=http://ntfy/$TOPIC"
+ echo "NTFY_TOKEN=$TOKEN"
+ } >> "$STATUS_ENV"
+ chmod 600 "$STATUS_ENV"
+ echo "Token written to $STATUS_ENV"
+ bash ../status/deploy.sh
+fi
+
+echo ""
+echo "購読: ntfy アプリで サーバー https://ntfy.yyamashita.com / トピック $TOPIC / ユーザー $USER_NAME でログイン"