97 lines
2.0 KiB
Bash
97 lines
2.0 KiB
Bash
#!/bin/bash
|
|
# set -ex
|
|
|
|
# Update Packages
|
|
apt update
|
|
apt install -y curl wget jq
|
|
|
|
# Install Docker
|
|
curl https://get.docker.com | sh
|
|
|
|
# Install Docker Compose
|
|
COMPOSE_VERSION=$(curl https://api.github.com/repos/docker/compose/releases/latest | grep tag_name | cut -d '"' -f 4)
|
|
wget "https://github.com/docker/compose/releases/download/${COMPOSE_VERSION}/docker-compose-linux-x86_64" -O /usr/bin/docker-compose
|
|
chmod a+x /usr/bin/docker-compose
|
|
|
|
# Craete Folder
|
|
mkdir -p /home/OFVpDeploy/
|
|
cd /home/OFVpDeploy/
|
|
|
|
# Create Compose File
|
|
cat <<EOF > docker-compose.yml
|
|
version: "3.9"
|
|
volumes:
|
|
OFVpData:
|
|
MongoOFVp:
|
|
networks:
|
|
ofvp_network:
|
|
driver: bridge
|
|
services:
|
|
ofvp_mongodb:
|
|
container_name: ofvp_mongodb
|
|
volumes:
|
|
- MongoOFVp:/data/db
|
|
restart: on-failure
|
|
image: mongo
|
|
networks:
|
|
- "ofvp_network"
|
|
environment:
|
|
- PUID=1000
|
|
- PGID=1000
|
|
ofvp_server:
|
|
container_name: ofvp_server
|
|
depends_on:
|
|
- ofvp_mongodb
|
|
image: ghcr.io/ofvp-project/server:${docketag}
|
|
privileged: true
|
|
restart: on-failure
|
|
networks:
|
|
- "ofvp_network"
|
|
ports:
|
|
- 3000:3000/tcp
|
|
- 2222:22/tcp
|
|
- 8081:8081/tcp
|
|
- 80:80/tcp
|
|
- 7300:7300/tcp
|
|
- 10086:10086/udp
|
|
- 10086:10086/tcp
|
|
- 51820:51820/udp
|
|
volumes:
|
|
- /lib/modules/:/lib/modules/
|
|
- OFVpData:/root/OFVpServer
|
|
EOF
|
|
|
|
if [[ "${autoupdate}" == "true" ]];then
|
|
cat <<EOF >> /bin/update_scrip.sh
|
|
#!/bin/bash
|
|
# set -ex
|
|
cd /home/OFVpDeploy/
|
|
SHA=""
|
|
while true; do
|
|
NEW_SHA="$(curl -Ssl https://api.github.com/repos/OFVp-Project/Server/commits | jq -r '.[0].sha')"
|
|
if [[ "$SHA" != "$NEW_SHA" ]]; then
|
|
docker-compose pull
|
|
docker-compose up -d
|
|
SHA="$NEW_SHA"
|
|
fi
|
|
sleep 60
|
|
done
|
|
EOF
|
|
chmod a+x /bin/update_scrip.sh
|
|
cat <<EOF >> /etc/systemd/system/update_scrip.service
|
|
[Unit]
|
|
Description=OFVp Update Script
|
|
After=docker.service
|
|
|
|
[Service]
|
|
Type=simple
|
|
ExecStart=/bin/update_scrip.sh
|
|
Restart=always
|
|
RestartSec=10
|
|
User=root
|
|
EOF
|
|
chmod a+x /etc/systemd/system/update_scrip.service
|
|
systemctl enable update_scrip.service
|
|
fi
|
|
exit 0
|