Repository navigation
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·55 lines (44 loc) · 2.41 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·55 lines (44 loc) · 2.41 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
#!/bin/bash
# SuperNETs Gitea Deployment - Developed by acidvegas (https://git.supernets.org/supernets/gitea)
# gitea/setup.sh
# Load environment variables
[ -f .env ] && source .env || { echo "Error: .env file not found"; exit 1; }
# Set xtrace, exit on error, & verbose mode (after loading environment variables)
set -xev
# Remove existing docker container if it exists
docker rm -f gitea 2>/dev/null || true
# Generate secret key using the Gitea binary itself
if [ -z "${GITEA_SECRET_KEY}" ]; then
GITEA_SECRET_KEY=$(docker run --rm gitea/gitea:latest gitea generate secret SECRET_KEY)
if grep -q "GITEA_SECRET_KEY" .env; then
sed -i "s|GITEA_SECRET_KEY=.*|GITEA_SECRET_KEY=${GITEA_SECRET_KEY}|g" .env
else
echo "GITEA_SECRET_KEY=${GITEA_SECRET_KEY}" >> .env
fi
fi
# Generate internal token using the Gitea binary itself
if [ -z "${GITEA_INTERNAL_TOKEN}" ]; then
GITEA_INTERNAL_TOKEN=$(docker run --rm gitea/gitea:latest gitea generate secret INTERNAL_TOKEN)
if grep -q "GITEA_INTERNAL_TOKEN" .env; then
sed -i "s|GITEA_INTERNAL_TOKEN=.*|GITEA_INTERNAL_TOKEN=${GITEA_INTERNAL_TOKEN}|g" .env
else
echo "GITEA_INTERNAL_TOKEN=${GITEA_INTERNAL_TOKEN}" >> .env
fi
fi
# Create directories for Gitea data
mkdir -p /opt/container-storage/gitea/data/gitea/conf
# Copy custom templates and assets into GITEA_CUSTOM (/data/gitea/)
cp -r custom/* /opt/container-storage/gitea/data/gitea/
# Copy app.ini to where Gitea actually reads it and fill in secrets
cp app.ini /opt/container-storage/gitea/data/gitea/conf/app.ini
sed -i "s|__SECRET_KEY__|${GITEA_SECRET_KEY}|g" /opt/container-storage/gitea/data/gitea/conf/app.ini
sed -i "s|__INTERNAL_TOKEN__|${GITEA_INTERNAL_TOKEN}|g" /opt/container-storage/gitea/data/gitea/conf/app.ini
sed -i "s|__WEBHOOK_ALLOWED_HOST__|${GITEA_WEBHOOK_ALLOWED_HOST}|g" /opt/container-storage/gitea/data/gitea/conf/app.ini
# Run the Gitea container with restart policy
docker run -d --restart unless-stopped --name gitea -e USER_UID=$(id -u) -e USER_GID=$(id -g) -p 127.0.0.1:3000:3000 -p 2222:2222 -v /opt/container-storage/gitea/data:/data gitea/gitea:latest
# Generate a random password for the admin user
ADMIN_PASSWORD=$(openssl rand -base64 12)
# Wait for Gitea to be ready, then create admin user
sleep 5
docker exec --user git gitea gitea admin user create --admin --username acidvegas --password ${ADMIN_PASSWORD} --email acid.vegas@acid.vegas
echo "Admin password: ${ADMIN_PASSWORD}"