Skip to content

Commit e61221b

Browse files
authored
Starbound/OpenStarbound: update mod scripts (#1561)
1 parent 46c538e commit e61221b

4 files changed

Lines changed: 80 additions & 46 deletions

File tree

openstarboundmanagemods.ps1

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,32 @@ Set-Location -Path "./openstarbound/server/mods"
33
$workshopDir = "../../211820/steamapps/workshop/content/211820"
44

55
if (Test-Path $workshopDir) {
6-
Write-Output "Copying mods"
6+
Write-Output "Copying mods"
77

8-
Get-ChildItem -Path $workshopDir -Directory | ForEach-Object {
9-
$modID = $_.Name
10-
$modPath = Join-Path -Path $workshopDir -ChildPath $modID
8+
Get-ChildItem -Path $workshopDir -Directory | ForEach-Object {
9+
$modID = $_.Name
10+
$modPath = Join-Path -Path $workshopDir -ChildPath $modID
1111

12-
$pakFile = Get-ChildItem -Path $modPath -Filter *.pak -File -ErrorAction SilentlyContinue | Select-Object -First 1
12+
$pakFiles = Get-ChildItem -Path $modPath -Filter *.pak -File -ErrorAction SilentlyContinue
1313

14-
if ($pakFile) {
15-
$copyPath = "./$modID.pak"
16-
Copy-Item -Path $pakFile.FullName -Destination $copyPath -Force | Out-Null
17-
} else {
18-
Write-Output "No .pak file in $modID, skipping"
14+
if ($pakFiles.Count -eq 0) {
15+
Write-Output "No .pak file in $modID, skipping"
16+
return
17+
}
18+
19+
for ($i = 0; $i -lt $pakFiles.Count; $i++) {
20+
if ($i -eq 0) {
21+
$targetName = "$modID.pak"
22+
} else {
23+
$suffix = $i + 1
24+
$targetName = "${modID}_$suffix.pak"
25+
}
26+
27+
Copy-Item -Path $pakFiles[$i].FullName -Destination "./$targetName" -Force | Out-Null
28+
}
1929
}
20-
}
2130
} else {
22-
Write-Output "No mods to copy"
31+
Write-Output "No mods to copy"
2332
}
2433

2534
exit 0

openstarboundmanagemods.sh

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,28 @@ cd ./openstarbound/server/mods
55
workshopDir="../../211820/steamapps/workshop/content/211820"
66

77
if [ -d "$workshopDir" ]; then
8-
echo "Linking mods"
8+
echo "Linking mods"
99

10-
find "$workshopDir" -maxdepth 1 -mindepth 1 -type d | while read -r modDir; do
11-
modID=$(basename "$modDir")
12-
pakFile=$(find "$modDir" -maxdepth 1 -type f -name '*.pak' | head -n 1)
10+
find "$workshopDir" -maxdepth 1 -mindepth 1 -type d | while read -r modDir; do
11+
modID=$(basename "$modDir")
12+
mapfile -t pakFiles < <(find "$modDir" -maxdepth 1 -type f -name '*.pak')
1313

14-
if [ -n "$pakFile" ]; then
15-
ln -sf "$pakFile" "./$modID.pak"
16-
else
17-
echo "No .pak file in $modID, skipping"
18-
fi
19-
done
14+
if [ "${#pakFiles[@]}" -eq 0 ]; then
15+
echo "No .pak file in $modID, skipping"
16+
continue
17+
fi
18+
19+
for i in "${!pakFiles[@]}"; do
20+
if [ "$i" -eq 0 ]; then
21+
ln -sf "${pakFiles[$i]}" "./$modID.pak"
22+
else
23+
suffix=$((i+1))
24+
ln -sf "${pakFiles[$i]}" "./${modID}_$suffix.pak"
25+
fi
26+
done
27+
done
2028
else
21-
echo "No mods to link"
29+
echo "No mods to link"
2230
fi
2331

2432
exit 0

starboundmanagemods.ps1

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,32 @@ Set-Location -Path "./starbound/211820/mods"
33
$workshopDir = "../steamapps/workshop/content/211820"
44

55
if (Test-Path $workshopDir) {
6-
Write-Output "Copying mods"
6+
Write-Output "Copying mods"
77

8-
Get-ChildItem -Path $workshopDir -Directory | ForEach-Object {
9-
$modID = $_.Name
10-
$modPath = Join-Path -Path $workshopDir -ChildPath $modID
8+
Get-ChildItem -Path $workshopDir -Directory | ForEach-Object {
9+
$modID = $_.Name
10+
$modPath = Join-Path -Path $workshopDir -ChildPath $modID
1111

12-
$pakFile = Get-ChildItem -Path $modPath -Filter *.pak -File -ErrorAction SilentlyContinue | Select-Object -First 1
12+
$pakFiles = Get-ChildItem -Path $modPath -Filter *.pak -File -ErrorAction SilentlyContinue
1313

14-
if ($pakFile) {
15-
$copyPath = "./$modID.pak"
16-
Copy-Item -Path $pakFile.FullName -Destination $copyPath -Force | Out-Null
17-
} else {
18-
Write-Output "No .pak file in $modID, skipping"
14+
if ($pakFiles.Count -eq 0) {
15+
Write-Output "No .pak file in $modID, skipping"
16+
return
17+
}
18+
19+
for ($i = 0; $i -lt $pakFiles.Count; $i++) {
20+
if ($i -eq 0) {
21+
$targetName = "$modID.pak"
22+
} else {
23+
$suffix = $i + 1
24+
$targetName = "${modID}_$suffix.pak"
25+
}
26+
27+
Copy-Item -Path $pakFiles[$i].FullName -Destination "./$targetName" -Force | Out-Null
28+
}
1929
}
20-
}
2130
} else {
22-
Write-Output "No mods to copy"
31+
Write-Output "No mods to copy"
2332
}
2433

2534
exit 0

starboundmanagemods.sh

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,28 @@ cd ./starbound/211820/mods
55
workshopDir="../steamapps/workshop/content/211820"
66

77
if [ -d "$workshopDir" ]; then
8-
echo "Linking mods"
8+
echo "Linking mods"
99

10-
find "$workshopDir" -maxdepth 1 -mindepth 1 -type d | while read -r modDir; do
11-
modID=$(basename "$modDir")
12-
pakFile=$(find "$modDir" -maxdepth 1 -type f -name '*.pak' | head -n 1)
10+
find "$workshopDir" -maxdepth 1 -mindepth 1 -type d | while read -r modDir; do
11+
modID=$(basename "$modDir")
12+
mapfile -t pakFiles < <(find "$modDir" -maxdepth 1 -type f -name '*.pak')
1313

14-
if [ -n "$pakFile" ]; then
15-
ln -sf "$pakFile" "./$modID.pak"
16-
else
17-
echo "No .pak file in $modID, skipping"
18-
fi
19-
done
14+
if [ "${#pakFiles[@]}" -eq 0 ]; then
15+
echo "No .pak file in $modID, skipping"
16+
continue
17+
fi
18+
19+
for i in "${!pakFiles[@]}"; do
20+
if [ "$i" -eq 0 ]; then
21+
ln -sf "${pakFiles[$i]}" "./$modID.pak"
22+
else
23+
suffix=$((i+1))
24+
ln -sf "${pakFiles[$i]}" "./${modID}_$suffix.pak"
25+
fi
26+
done
27+
done
2028
else
21-
echo "No mods to link"
29+
echo "No mods to link"
2230
fi
2331

2432
exit 0

0 commit comments

Comments
 (0)