-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
165 lines (139 loc) · 5.08 KB
/
setup.sh
File metadata and controls
165 lines (139 loc) · 5.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/bin/bash
# Quartermaster .NET - Unix Setup Script (Linux/macOS)
# Supports: Ubuntu, Debian, CentOS, Fedora, Arch, and macOS (Homebrew)
set -e
echo "========================================="
echo " Quartermaster .NET - Unix Setup"
echo "========================================="
# Detect OS
OS="$(uname -s)"
case "${OS}" in
Linux*) DISTRO=$(lsb_release -i | cut -f 2- 2>/dev/null || echo "Linux");;
Darwin*) DISTRO="macOS";;
*) DISTRO="UNKNOWN"
esac
echo "Detected OS: ${OS} (${DISTRO})"
# 1. Install .NET SDK if missing
if ! command -v dotnet &> /dev/null; then
echo ".NET SDK not found. Attempting to install..."
if [[ "$OS" == "Darwin" ]]; then
if ! command -v brew &> /dev/null; then
echo "Homebrew not found. Please install it or manually install .NET SDK from: https://dotnet.microsoft.com/download"
exit 1
fi
brew install --cask dotnet-sdk
else
# Linux detection and installation
if [ -f /etc/os-release ]; then
. /etc/os-release
case "$ID" in
ubuntu|debian)
sudo apt-get update && sudo apt-get install -y dotnet-sdk-10.0
;;
fedora)
sudo dnf install -y dotnet-sdk-10.0
;;
centos|rhel)
sudo yum install -y dotnet-sdk-10.0
;;
arch)
sudo pacman -S --noconfirm dotnet-sdk
;;
*)
echo "Unsupported Linux distro. Please install .NET SDK manually: https://learn.microsoft.com/en-us/dotnet/core/install/linux"
exit 1
;;
esac
fi
fi
else
echo ".NET SDK is already installed: $(dotnet --version)"
fi
# 2. Build and Publish
echo "Restoring and publishing Quartermaster..."
dotnet publish Quartermaster.Bot/Quartermaster.Bot.csproj --configuration Release --output ./publish
dotnet publish Quartermaster.Web/Quartermaster.Web.csproj --configuration Release --output ./publish
# 3. Configuration Phase
echo ""
echo "--- Configuration Phase ---"
echo "You will need your Discord Application credentials."
echo "Get them here: https://discord.com/developers/applications"
echo ""
read -p "Enter your Discord Bot Token: " bot_token
read -p "Enter your Client ID (Application ID): " client_id
read -p "Enter your Client Secret: " client_secret
read -p "Enter your Dashboard URL (Default: http://localhost:3000): " dashboard_url
read -p "Enter your Dashboard Port (Default: 3000): " port
read -p "Enter your Database Path (Default: ./bot.db): " db_path
# Use python3 to update JSON safely without jq dependency
python3 -c "
import json, sys
with open('appsettings.json', 'r') as f:
config = json.load(f)
if '$bot_token': config['Bot']['Token'] = '$bot_token'
if '$client_id': config['Discord']['ClientId'] = '$client_id'
if '$client_secret': config['Discord']['ClientSecret'] = '$client_secret'
if '$dashboard_url':
config['Discord']['DashboardUrl'] = '$dashboard_url'
else:
config['Discord']['DashboardUrl'] = 'http://localhost:3000'
if '$port':
config['Discord']['Port'] = int('$port')
else:
config['Discord']['Port'] = 3000
if '$db_path':
config['Bot']['DatabasePath'] = '$db_path'
else:
config['Bot']['DatabasePath'] = './bot.db'
# Auto-set CallbackUrl
config['Discord']['CallbackUrl'] = config['Discord']['DashboardUrl'].rstrip('/') + '/callback'
with open('appsettings.json', 'w') as f:
json.dump(config, f, indent=2)
"
echo "✅ Configuration saved to appsettings.json"
# 4. Optional: Install as systemd service (Linux only)
if [[ "$OS" == "Linux" ]]; then
read -p "Would you like to install Quartermaster as a systemd service? (Y/N): " install_service
if [[ "$install_service" == "Y" || "$install_service" == "y" ]]; then
USER_NAME=$(whoami)
CUR_DIR=$(pwd)
echo "Creating systemd service files..."
# Bot Service
cat <<EOF | sudo tee /etc/systemd/system/quartermaster-bot.service
[Unit]
Description=Quartermaster Discord Bot
After=network.target
[Service]
Type=notify
WorkingDirectory=$CUR_DIR/publish
ExecStart=$CUR_DIR/publish/Quartermaster.Bot --contentRoot $CUR_DIR
User=$USER_NAME
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
EOF
# Web Service
cat <<EOF | sudo tee /etc/systemd/system/quartermaster-web.service
[Unit]
Description=Quartermaster Web Dashboard
After=network.target
[Service]
Type=notify
WorkingDirectory=$CUR_DIR/publish
ExecStart=$CUR_DIR/publish/Quartermaster.Web --contentRoot $CUR_DIR
User=$USER_NAME
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
echo "✅ systemd services created. Use 'sudo systemctl start quartermaster-bot' to launch."
fi
fi
echo "========================================="
echo " Setup Complete!"
echo " 1. Edit 'appsettings.json' with your tokens."
echo " 2. Run './start.sh' to launch manually or use systemctl."
echo "========================================="