summarylogtreecommitdiffstats
path: root/factorio-headless.install
blob: 02246c37c16b181e32453e7e4ac215b4eb708ba0 (plain)
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
post_install() {
    systemd-sysusers factorio.conf
    [[ -d /var/lib/factorio ]] || install -dm 770 -o factorio -g games /var/lib/factorio
    chown factorio:games /etc/factorio/*
}

pre_upgrade() {
    (( $(vercmp $2 '0.15.31-1') >= 0 )) || {
        if systemctl is-active -q factorio.service; then
            echo Stopping factorio.service...
            systemctl stop factorio.service &>/dev/null
        fi
    }
}

post_upgrade() {
    (( $(vercmp $2 '0.15.31-1') >= 0 )) || {
        # Source previous settings (or default setting if the config file was untouched)
        local old_path=/var/lib/factorio/.factorio/saves/factorio-service-save.zip
        local new_path=/var/lib/factorio/factorio-service-save.zip

        if [[ -f $old_path ]]; then
            if [[ -f $new_path ]]; then
                echo "The default save file location was changed from '$old_path' to '$new_path' but this file already exists so it won't be overwritten."
            else
                echo "The default save file location was changed. Copying the old file to the new location."
                cp -v $old_path $new_path
            fi
            echo
        fi

        if [[ -f /etc/conf.d/factorio.pacnew ]]; then
            source /etc/conf.d/factorio
            if [[ -z $SAVE_FILE || $SAVE_FILE == $old_path ]]; then
                SAVE_FILE=$new_path
            fi

            SAVE_NAME=$(cd /var/lib/factorio; realpath "$SAVE_FILE" --relative-base /var/lib/factorio/)
            SAVE_NAME=${SAVE_NAME%%.zip}

            echo "The SAVE_FILE setting has been replaced by the SAVE_NAME setting which doesn't include the .zip suffix anymore"
            echo "Based on your current settings, you should set (in /etc/conf.d/factorio):"
            echo "SAVE_NAME=$SAVE_NAME"
            echo
        fi

        echo "The systemd service file has been updated, don't forget to run 'systemctl daemon-reload' before restarting factorio."

        post_install $1
        chmod 600 /etc/factorio/server-settings.json
    }

    (( $(vercmp $2 '0.16.36-2') >= 0 )) || {
        chown factorio:games /etc/factorio/*
    }
}