-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstaller.sh
More file actions
129 lines (107 loc) · 3.03 KB
/
installer.sh
File metadata and controls
129 lines (107 loc) · 3.03 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
#!/usr/bin/env bash
set -e
# -------------------------------
# DockShip Installer
# -------------------------------
clear
echo "\x1b[34m"
cat public/ascii.txt
echo "\x1b[0m\n\n"
echo "Welcome to the DockShip installer!"
if [ -f .env ]; then
echo "\x1b[31m'.env' file already exists\x1b[0m"
exit
fi
# Prompt for Lite Mode
read -p "Do you want to enable Lite Mode? (API only, no UI) [y/N]: " lite_mode
if [[ "$lite_mode" =~ ^([yY][eE][sS]|[yY])$ ]]; then
echo "DOCKSHIP_LITE=true" > .env
else
echo "DOCKSHIP_LITE=false" > .env
fi
# Prompt for port
read -p "Enter the port DockShip should run on [3000]: " PORT
PORT=${PORT:-3000}
echo "PORT=$PORT" >> .env
# Prompt for ORIGIN type
echo ""
echo "Choose the origin IP for DockShip:"
echo "1) Local IP (Recommended)"
echo "2) Public IP (Unsafe)"
read -p "Enter choice [1/2]: " ip_choice
if [[ "$ip_choice" == "1" ]]; then
# Get local IP (first non-loopback IP)
LOCAL_IP=$(hostname -I | awk '{print $1}')
ORIGIN="http://$LOCAL_IP:$PORT"
elif [[ "$ip_choice" == "2" ]]; then
# Get public IP via external service
PUBLIC_IP=$(curl -s https://api.ipify.org)
ORIGIN="http://$PUBLIC_IP:$PORT"
else
echo "\x1b[31mInvalid choice. Exiting.\x1b[0m"
exit 1
fi
# Append ORIGIN to .env
echo "ORIGIN=$ORIGIN" >> .env
echo "Set ORIGIN to $ORIGIN"
# Display GitHub OAuth info
BASE_URL=$ORIGIN
REDIRECT_URL="$BASE_URL/api/auth/callback/github"
echo ""
echo "To integrate with GitHub, create a GitHub OAuth App here:"
echo " https://github.com/settings/applications/new"
echo ""
echo "Use the following URLs:"
echo " Base URL: $BASE_URL"
echo " Redirect URL: $REDIRECT_URL"
echo ""
# Prompt for GitHub Client ID and Secret
read -p "Enter your GitHub Client ID: " GITHUB_CLIENT_ID
read -p "Enter your GitHub Client Secret: " GITHUB_CLIENT_SECRET
# Append to .env
echo "GITHUB_CLIENT_ID=$GITHUB_CLIENT_ID" >> .env
echo "GITHUB_CLIENT_SECRET=$GITHUB_CLIENT_SECRET" >> .env
# Install dependencies
echo ""
echo "Installing npm dependencies..."
npm install
# Build the app
echo ""
echo "Building DockShip..."
npm run build
# Create systemd service
SERVICE_FILE="/etc/systemd/system/dockship.service"
INSTALL_DIR=$(pwd)
NODE_PATH=$(which node)
USER_NAME=$(whoami)
echo ""
echo "Creating systemd service at $SERVICE_FILE..."
sudo tee $SERVICE_FILE > /dev/null <<EOL
[Unit]
Description=DockShip Control Service
After=network.target
[Service]
Type=simple
WorkingDirectory=$INSTALL_DIR
ExecStart=$(which npm) run start
Restart=always
RestartSec=5
EnvironmentFile=$INSTALL_DIR/.env
Environment=PATH=$(dirname $NODE_PATH):/usr/bin:/bin
User=$USER_NAME
Group=$USER_NAME
[Install]
WantedBy=multi-user.target
EOL
# Enable and start the service
echo ""
echo "Enabling and starting DockShip service..."
sudo systemctl daemon-reload
sudo systemctl enable dockship
sudo systemctl start dockship
echo ""
echo "DockShip installation complete!"
echo "You can check logs with: sudo journalctl -u dockship -f"
echo "Lite Mode: $(grep DOCKSHIP_LITE .env)"
echo "Origin: $(grep ORIGIN .env)"
echo "You can edit .env later to update configuration."