Skip to content

Commit 473b334

Browse files
authored
Merge pull request #72 from SQLJames/feature/factorio-mod-downloader
adding factorio mods downloader tool
2 parents bb2848e + d44d2cf commit 473b334

File tree

5 files changed

+40
-102
lines changed

5 files changed

+40
-102
lines changed

Diff for: CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
## Changelog
22

3+
### V2.5.0
4+
5+
#### Breaking Changes
6+
7+
- Reformatted the mods section to allow users to specify a mod version so it wont try to pull the latest if you don't want it too. This refactor introduces a custom tool [factorio-mod-downloader](https://github.com/SQLJames/factorio-mod-downloader) as an image, which is a simple golang tool, which simplifies the script and improves logging.
8+
39
### V2.4.1
410

511
#### Non-Breaking Changes

Diff for: charts/factorio-server-charts/Chart.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ sources:
2020
# This is the chart version. This version number should be incremented each time you make changes
2121
# to the chart and its templates, including the app version.
2222
# Versions are expected to follow Semantic Versioning (https://semver.org/)
23-
version: 2.4.1
23+
version: 2.5.0
2424

2525
# This is the version number of the application being deployed. This version number should be
2626
# incremented each time you make changes to the application. Versions are not expected to

Diff for: charts/factorio-server-charts/templates/deployment.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ spec:
3939
- -ec
4040
- |
4141
mkdir -p /factorio/configs
42+
mkdir -p /factorio/mods
4243
mkdir -p /factorio/config
44+
echo $VERSION > /factorio/mods/factorioVersion
4345
cp --verbose /deployed-configs/* /factorio/configs
4446
if [ -f "/rcon-pw/rconpw" ]; then
4547
cp --verbose /rcon-pw/rconpw /factorio/configs/rconpw
@@ -82,14 +84,12 @@ spec:
8284
{{- end }}
8385
{{- if .Values.mods.enabled }}
8486
- name: download-factorio-mods
85-
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
86-
imagePullPolicy: {{ .Values.image.pullPolicy }}
87+
image: "{{ .Values.mods.image.repository }}:{{ .Values.mods.image.tag }}"
88+
imagePullPolicy: {{ .Values.mods.image.pullPolicy }}
8789
command:
8890
- /bin/bash
8991
- -ecx
9092
- |
91-
mkdir -p /factorio/mods
92-
ls -alth /scripts
9393
echo "Running mod-downloader.sh script..."
9494
bash /scripts/mod-downloader.sh
9595
echo "Finished mod-downloader.sh script"

Diff for: charts/factorio-server-charts/templates/mod-downloader-configmap.yaml

+19-94
Original file line numberDiff line numberDiff line change
@@ -19,103 +19,28 @@ data:
1919
exit 0
2020
fi
2121
modDir=/factorio/mods
22-
MOD_BASE_URL="https://mods.factorio.com"
23-
declare -a officialMods
24-
officialMods=(
25-
{{- range .Values.mods.portal }}
26-
{{ . }}
27-
{{- end }}
28-
)
29-
declare -A unofficialMods
30-
{{- range .Values.mods.unofficial }}
31-
unofficialMods[{{ .name | quote}}]={{ .url | quote}}
32-
{{- end }}
33-
function print_step()
34-
{
35-
echo "$1"
36-
}
37-
function print_success()
38-
{
39-
echo "$1"
40-
}
41-
function print_failure()
42-
{
43-
echo "$1"
44-
}
45-
function downloadUnofficial() {
46-
cd $modDir;curl -L -o $2 $1
47-
}
48-
function downloadofficial() {
49-
MOD_NAME="$1"
50-
MOD_NAME_ENCODED="${1// /%20}"
51-
if [[ -z ${USERNAME:-} ]]; then
52-
USERNAME="$(cat /account/username)"
53-
fi
54-
55-
if [[ -z ${TOKEN:-} ]]; then
56-
TOKEN="$(cat /account/token)"
57-
fi
58-
59-
if [[ -z ${USERNAME:-} ]]; then
60-
echo "You need to provide your Factorio username to update mods."
61-
fi
62-
63-
if [[ -z ${TOKEN:-} ]]; then
64-
echo "You need to provide your Factorio token to update mods."
65-
fi
66-
MOD_INFO_URL="$MOD_BASE_URL/api/mods/$MOD_NAME_ENCODED"
67-
MOD_INFO_JSON=$(curl --silent "$MOD_INFO_URL")
68-
# echo "$MOD_INFO_URL $MOD_INFO_JSON"
69-
if ! echo "$MOD_INFO_JSON" | jq -e .name >/dev/null; then
70-
print_success " Custom mod not on $MOD_BASE_URL, skipped."
71-
return 0
72-
fi
73-
MOD_INFO=$(echo "$MOD_INFO_JSON" | jq -j --arg version "$VERSION" ".releases|reverse|map(select(.info_json.factorio_version as \$mod_version | \$version | startswith(\$mod_version)))[0]|.file_name, \";\", .download_url, \";\", .sha1")
74-
echo $MOD_INFO
75-
MOD_FILENAME=$(echo "$MOD_INFO" | cut -f1 -d";")
76-
MOD_URL=$(echo "$MOD_INFO" | cut -f2 -d";")
77-
MOD_SHA1=$(echo "$MOD_INFO" | cut -f3 -d";")
78-
if [[ $MOD_FILENAME == null ]]; then
79-
print_failure " Not compatible with version"
80-
return 0
81-
fi
82-
print_step "Downloading..."
83-
FULL_URL="$MOD_BASE_URL$MOD_URL?username=$USERNAME&token=$TOKEN"
84-
echo $FULL_URL
85-
HTTP_STATUS=$(curl --silent -L -w "%{http_code}" -o "$modDir/$MOD_FILENAME" "$FULL_URL")
86-
87-
if [[ $HTTP_STATUS != 200 ]]; then
88-
print_failure " Download failed: Code $HTTP_STATUS."
89-
rm -f "$modDir/$MOD_FILENAME"
90-
return 1
91-
fi
92-
93-
if [[ ! -f $modDir/$MOD_FILENAME ]]; then
94-
print_failure " Downloaded file missing!"
95-
return 1
96-
fi
22+
FACTORIOVERSION="$(cat /factorio/mods/factorioVersion)"
23+
USERNAME="$(cat /account/username)"
24+
TOKEN="$(cat /account/token)"
25+
if [[ -z ${USERNAME:-} ]]; then
26+
echo "You need to provide your Factorio username to update mods."
27+
fi
9728
98-
if ! [[ $(sha1sum "$modDir/$MOD_FILENAME") =~ $MOD_SHA1 ]]; then
99-
print_failure " SHA1 mismatch!"
100-
rm -f "$modDir/$MOD_FILENAME"
101-
return 1
29+
if [[ -z ${TOKEN:-} ]]; then
30+
echo "You need to provide your Factorio token to update mods."
31+
fi
32+
{{- range .Values.mods.portal }}
33+
if [ -z {{ .version | quote }} ]; then
34+
/usr/local/bin/factorio-mod-downloader download official --name {{ .name | quote}} --destination $modDir --factorioVersion $FACTORIOVERSION --user $USERNAME --token $TOKEN
35+
else
36+
/usr/local/bin/factorio-mod-downloader download official --name {{ .name | quote}} --destination $modDir --factorioVersion $FACTORIOVERSION --user $USERNAME --token $TOKEN --version {{ .version | quote}}
10237
fi
38+
{{- end }}
39+
40+
{{- range .Values.mods.unofficial }}
41+
/usr/local/bin/factorio-mod-downloader download unofficial --url {{ .url | quote}} --name {{ .name | quote}} --destination $modDir
42+
{{- end }}
10343
104-
print_success " Download complete."
105-
}
106-
mkdir -p $modDir
107-
for key in "${!unofficialMods[@]}"; do
108-
downloadUnofficial "${unofficialMods[$key]}" $key
109-
done
110-
111-
if [ -f "/account/username" ]; then
112-
if [ -f "/account/token" ]; then
113-
echo "server is running version $VERSION"
114-
for officialMod in ${officialMods[*]}; do
115-
downloadofficial $officialMod $USERNAME $TOKEN
116-
done
117-
fi
118-
fi
11944
# Mark the update as complete by creating the flag file
12045
touch "$FLAG_FILE"
12146
echo "Mod update completed."

Diff for: charts/factorio-server-charts/values.yaml

+10-3
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,19 @@ persistence:
147147
## @param mods.portal List of official mods to be downloaded from Factorio Mod Portal
148148
## @param mods.unofficial List of unofficial mods name and url to download into the mods folder
149149
mods:
150+
image:
151+
repository: "ghcr.io/sqljames/factorio-mod-downloader"
152+
## Container image pull policy
153+
pullPolicy: Always
154+
## Overrides the image tag whose default is the chart appVersion.
155+
tag: "1.0.1"
156+
## You should set an fix version, i.e.:
157+
# tag: "1.1.37"
150158
enabled: false
151159
# in order to use the mods portal you will need to specify the username and token in the server_settings.
152160
portal: []
153-
# - Krastorio2
154-
# - StorageTank2_Updated
155-
# - early-robots
161+
# - name: factorissimo-2-notnotmelon
162+
# version: 3.5.11
156163
# unofficial section is meant to just allow you to download and place folders into the mods folder.
157164
# we will not check version compatibility automatically with these downloads.
158165
# you can encounter an error if the file names dont match what the mod is expecting for example

0 commit comments

Comments
 (0)