-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·66 lines (45 loc) · 1.53 KB
/
install.sh
File metadata and controls
executable file
·66 lines (45 loc) · 1.53 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
#! /bin/bash
VERSION="1.1.101"
URL="https://factorio.com/get-download/$VERSION/headless/linux64"
LOGFILE=/var/log/factorioctl.log
function log(){
echo "$1" | tee -a "$LOGFILE"
}
echo "Installing on $(date)"
USER=$(whoami)
if [ "$USER" != "root" ]; then
echo "Must run as root"
exit 1
fi
log "Downloading Factorio headless v $VERSION"
if [ ! -f "factorio.tar.gz" ]; then
wget $URL -O factorio.tar.gz
fi
mkdir -p /srv/factorio
log "Extracting to /srv/factorio"
tar -xf factorio.tar.gz -C /srv
ln -s /srv/factorio/bin/x64/factorio /srv/factorio/factorio
log "Adding user"
adduser --disabled-login --no-create-home --gecos factorio factorio
log "Copying settings"
cp /srv/factorio/data/server-settings.example.json /srv/factorio/data/server-settings.json
cp /srv/factorio/data/map-gen-settings.example.json /srv/factorio/data/map-gen-settings.json
log "Generating map"
/srv/factorio/factorio --create /srv/factorio/saves/map.zip --map-gen-settings /srv/factorio/data/map-gen-settings.json
log "Creating systemd service and starting"
sudo chown -R factorio:factorio /srv/factorio
cat > /etc/systemd/system/factorio.service <<- EOF
[Unit]
Description=Factorio Headless Server
[Service]
Type=simple
User=factorio
ExecStart=-/srv/factorio/factorio --start-server /srv/factorio/saves/map.zip --server-settings /srv/factorio/data/server-settings.json
[Install]
WantedBy=multi-user.target
EOF
systemctl enable --now factorio.service
log "Creating factorioctl tool"
cp factorioctl /sbin/factorioctl
chmod +x /sbin/factorioctl
rm factorio.tar.gz