Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
124 lines (104 loc) · 5.67 KB
/
Copy pathinstall.sh
File metadata and controls
124 lines (104 loc) · 5.67 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
#!/usr/bin/env bash
set -euo pipefail
# ─────────────────────────────────────────────────────────────────
# MailGo One-Line Installer
# Usage: curl -fsSL https://raw.githubusercontent.com/MengMengCode/MailGo/main/install.sh | bash
# ─────────────────────────────────────────────────────────────────
REPO="MengMengCode/MailGo"
BASE_URL="https://raw.githubusercontent.com/${REPO}/main"
INSTALL_DIR="${MAILGO_DIR:-$HOME/mailgo}"
CYAN='\033[0;36m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
info() { echo -e "${CYAN}[info]${NC} $*"; }
ok() { echo -e "${GREEN}[ok]${NC} $*"; }
warn() { echo -e "${YELLOW}[warn]${NC} $*"; }
die() { echo -e "${RED}[error]${NC} $*" >&2; exit 1; }
# ── Check prerequisites ─────────────────────────────────────────
command -v docker >/dev/null 2>&1 || die "Docker is not installed. https://docs.docker.com/get-docker/"
if docker compose version >/dev/null 2>&1; then
COMPOSE="docker compose"
elif command -v docker-compose >/dev/null 2>&1; then
COMPOSE="docker-compose"
else
die "Docker Compose is not installed. https://docs.docker.com/compose/install/"
fi
# ── Create install directory ─────────────────────────────────────
mkdir -p "$INSTALL_DIR"
cd "$INSTALL_DIR"
info "Installing to $INSTALL_DIR ..."
# ── Download docker-compose.yml ──────────────────────────────────
info "Downloading docker-compose.yml ..."
if command -v curl >/dev/null 2>&1; then
curl -fsSL "${BASE_URL}/docker-compose.yml" -o docker-compose.yml
elif command -v wget >/dev/null 2>&1; then
wget -qO docker-compose.yml "${BASE_URL}/docker-compose.yml"
else
die "Neither curl nor wget is available."
fi
# ── Generate .env ────────────────────────────────────────────────
if [ -f .env ]; then
warn ".env already exists — keeping existing config."
else
info "Generating .env ..."
ENC_KEY=$(openssl rand -hex 32 2>/dev/null || head -c 64 /dev/urandom | od -An -tx1 | tr -d ' \n')
MYSQL_ROOT_PW=$(openssl rand -base64 18 2>/dev/null || head -c 18 /dev/urandom | base64 | head -c 24)
MYSQL_PW=$(openssl rand -base64 18 2>/dev/null || head -c 18 /dev/urandom | base64 | head -c 24)
cat > .env <<EOF
# Auto-generated by install.sh on $(date -u +"%Y-%m-%d %H:%M:%S UTC")
ENCRYPTION_KEY=${ENC_KEY}
SERVER_PORT=8080
MAILGO_IMAGE_TAG=latest
TRUSTED_PROXIES=
MYSQL_USER=mailgo
MYSQL_PASSWORD=${MYSQL_PW}
MYSQL_HOST=mysql
MYSQL_PORT=3306
MYSQL_DATABASE=mailgo
MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PW}
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_PASSWORD=
REDIS_DB=0
EOF
ok ".env created."
fi
# ── Pull images and start ────────────────────────────────────────
info "Pulling images and starting MailGo ..."
$COMPOSE pull
$COMPOSE up -d
# ── Wait for services ────────────────────────────────────────────
info "Waiting for services to be ready ..."
for i in $(seq 1 90); do
STATUS=$(docker inspect --format='{{.State.Status}}' mailgo 2>/dev/null || echo "starting")
if [ "$STATUS" = "running" ]; then
break
fi
sleep 2
done
# ── Print initial password ───────────────────────────────────────
echo ""
echo "╔══════════════════════════════════════════════════════════════════╗"
echo "║ MailGo is ready! ║"
echo "╠══════════════════════════════════════════════════════════════════╣"
INIT_PW=$(docker logs mailgo 2>/dev/null | grep -oP 'Web Login Password:\s+\K\S+' || echo "")
if [ -n "$INIT_PW" ]; then
printf "║ Initial Password: %-44s ║\n" "$INIT_PW"
else
printf "║ Check logs: docker logs mailgo | grep Password ║\n"
fi
echo "║ ║"
printf "║ Open: http://localhost:%-40s ║\n" "${SERVER_PORT:-8080}"
echo "║ ║"
echo "║ Install dir: ${INSTALL_DIR} "
echo "║ ║"
echo "║ Reset password: docker exec mailgo /app/mailgo -reset-password ║"
echo "║ Change password: Settings > Security > Change Password ║"
echo "║ View logs: docker logs -f mailgo ║"
echo "║ Stop: cd ${INSTALL_DIR} && docker compose down "
echo "║ Update: cd ${INSTALL_DIR} && docker compose pull && docker compose up -d"
echo "║ ║"
echo "╚══════════════════════════════════════════════════════════════════╝"
echo ""