-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatchv2.sh
More file actions
executable file
·179 lines (162 loc) · 6.47 KB
/
patchv2.sh
File metadata and controls
executable file
·179 lines (162 loc) · 6.47 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/bin/bash
[ -d tmp ] || mkdir tmp
INITDIR="$(pwd)"
WSDIR='tmp/steam/steamapps/workshop/content/211820/'
SBDIR="tmp/steam/"
MODSDIR="mods/"
UPDIR="unpack/"
MODBASE="modBase/"
echo "[INFO]: Initializing directories..."
[ -e "${UPDIR}" ] && rm -r "${UPDIR}"
mkdir "${UPDIR}"
[ -e 'speciesFixes' ] && rm -r 'speciesFixes'
cp -a "$MODBASE" 'speciesFixes'
printf '' > 'tmp/fixCinematic.log'
printf '' > 'tmp/patchChairs.log'
echo "[DBUG]: Initialized."
function logAction {
if [ -z "$1" ] || [ -z "$2" ] || [ -n "$3" ] ; then
echo '[CRIT]: - Malformed call to `logAction`!'
exit 1
fi
MODID="$2"
METAFILE="$(find "${UPDIR}/${MODID}" -maxdepth 1 -type f -iregex '.*/\(\.\|_\)metadata$' | head -n 1)"
NAME="Unknown"
if [ -n "$METAFILE" ] ; then
if grep -qE '"name" *: *"' "$METAFILE" ; then
NAME="$(grep -E '"name" *: *"' "$METAFILE" | sed 's/.*"name" *: *"//' | sed 's/"[^\\]*$//' | sed "s/\\\"/'/g")"
elif grep -qE '"friendlyName" *: *"' "$METAFILE" ; then
NAME="$(grep -E '"friendlyName" *: *"' "$METAFILE" | sed 's/.*"friendlyName" *: *"//' | sed 's/"[^\\]*$//' | sed "s/\\\"/'/g")"
fi
fi
if [[ "$1" == "fixCinematic" ]] ; then
#echo "[DBUG]: - Fixed cinematic in mod '$MODID'"
echo "$MODID $NAME" >> 'tmp/fixCinematic.log'
else
#echo "[DBUG]: - Patched chair in mod '$MODID'"
echo "$MODID $NAME" >> 'tmp/patchChairs.log'
fi
}
function fixCinematics {
if [ -z "$1" ] || [ -n "$2" ] ; then
echo '[CRIT]: - Malformed call to `fixCinematics`!'
exit 1
fi
MODID="$1"
PSPECIESLIST="$(
find "${UPDIR}/${MODID}" -type f -name "universe_server.config.patch" | while read FILE ; do
sed ':a;N;$!ba;s/\n/ /g' "$FILE" | sed 's/,/\n/g' | grep -E '"path" *: *"/speciesShips/' | sed 's;.*"path" *: *"/speciesShips/;;' | sed 's/".*//'
done | sort -u
)"
DSPECIESLIST="$(
find "${UPDIR}/${MODID}" -type f -name "*.species" | while read FILE ; do
grep -E '"kind" *: *"' "$FILE" | sed 's/.*"kind" *: *"//' | sed 's/".*//'
done | sort -u
)"
SPECIESLIST="$(
comm -12 <(echo "$PSPECIESLIST") <(echo "$DSPECIESLIST")
)"
SKIPSPECIES="$(
find "${UPDIR}/${MODID}" -type f -name "deploy_*.cinematic" | while read FILE ; do
echo "$FILE" | sed 's/.*deploy_//' | sed 's/\.cinematic//'
done | sort -u
)"
CINSPECIES="$(comm -23 <(echo "$SPECIESLIST") <(echo "$SKIPSPECIES"))"
if [ -n "$CINSPECIES" ] ; then
echo "$CINSPECIES" | while read SPECIES ; do
cp -a 'deploy_SPECIES.cinematic' "speciesFixes/cinematics/teleport/deploy_${SPECIES}.cinematic"
echo "[INFO]: - Built cinematic for species '$SPECIES'"
done
logAction "fixCinematic" "$MODID"
fi
}
function patchChairs {
if [ -z "$1" ] || [ -n "$2" ] ; then
echo '[CRIT]: - Malformed call to `fixCinematics`!'
exit 1
fi
MODID="$1"
CAPCHAIRLIST="$(
find "${UPDIR}/${MODID}" -type f -name "*.object" | while read FILE ; do
if grep -q 'openCockpitInterface' "$FILE" ; then
echo "$FILE" | sed "s:.*${MODID}/::"
fi
done
)"
if [ -n "$CAPCHAIRLIST" ] ; then
echo "$CAPCHAIRLIST" | while read FILE ; do
mkdir -p "speciesFixes/$(dirname "$FILE")"
cp -a 'captainChair.patch' "speciesFixes/${FILE}.patch"
echo "[INFO]: - Patched outdated captain's chair '$FILE'"
done
logAction "patchChairs" "$MODID"
fi
}
if [[ "$1" == "local" ]] ; then
echo "[INFO]: Using local mods directory $MODSDIR as source. NOTE: Must use proper naming convention!"
ls "$MODSDIR" | while read FILE ; do
MODID="$(echo "$FILE" | sed 's/_.*//')"
if [ -f "${MODSDIR}/${FILE}" ] ; then
"${SBDIR}/linux/asset_unpacker" "${MODSDIR}/${FILE}" "${UPDIR}/${MODID}" >/dev/null 2>&1
else
echo "[INFO]: - File '${MODSDIR}/${FILE}' is not unpackable. Copying to '${UPDIR}/${MODID}"
cp -a "${MODSDIR}/${FILE}" "${UPDIR}/${MODID}"
fi
echo "[INFO]: - Processing mod '$MODID'..."
fixCinematics "$MODID"
patchChairs "$MODID"
rm -r "${UPDIR}/${MODID}"
done
else
echo "[INFO]: Using workshop directory '$WSDIR' as source."
ls "$WSDIR" | while read MODID ; do
ls "${WSDIR}/${MODID}/" | while read FILE ; do
if [ -f "${WSDIR}/${MODID}/${FILE}" ] ; then
if ! "${SBDIR}/linux/asset_unpacker" "${WSDIR}/${MODID}/${FILE}" "${UPDIR}/${MODID}" >/dev/null 2>&1 ; then
echo "[INFO]: - Skipping mod - Failed to unpack."
break # If the unpacker fails, break and jump to the next mod. Usually due to pre-1.0 mods being on the workshop.
fi
else
echo "[INFO]: - File '${WSDIR}/${MODID}/${FILE}' is not unpackable. Copying to '${UPDIR}/${MODID}'..."
cp -a "${WSDIR}/${MODID}/${FILE}" "${UPDIR}/${MODID}"
fi
echo "[INFO]: - Processing mod '$MODID'..."
fixCinematics "$MODID"
patchChairs "$MODID"
rm -r "${UPDIR}/${MODID}"
done
done
fi
read -p "[INFO]: Update version info? [y/N]: " UPRESP
if [[ "$UPRESP" == "Y" ]] || [[ "$UPRESP" == "y" ]] ; then
OLDVER="$(grep '"version"' "${MODBASE}/_metadata" | sed 's/.*version" *: *"//' | sed 's/".*//')"
read -p "[INFO]: - Version number? ['${OLDVER}']: " VERRESP
if [ -z "$VERRESP" ] ; then
NEWVER="$OLDVER"
else
NEWVER="$VERRESP"
fi
read -p "[INFO]: - Changelog entry? ['Full refresh.']: " CLRESP
if [ -z "$CLRESP" ] ; then
CLENTRY="Full refresh."
else
CLENTRY="$CLRESP"
fi
echo "[INFO]: - Updating version from '$OLDVER' to '$NEWVER'"
sed -i "s/\"version\" *: *\".*\"/\"version\": \"${NEWVER}\"/" "${MODBASE}/_metadata"
echo -e "$(date +%Y-%m-%d): ${NEWVER}\t- ${CLENTRY}" >> changelog.txt
cp -a changelog.txt "${MODBASE}/changelog.txt"
fi
"${SBDIR}/linux/asset_packer" 'speciesFixes' 'speciesFixes.pak'
BOTH="$(comm -12 <(cat 'tmp/fixCinematic.log' | sort) <(cat 'tmp/patchChairs.log' | sort) | sort -nk1 | sed 's/\t/ - /')"
CINEMATIC="$(comm -23 <(cat 'tmp/fixCinematic.log' | sort) <(cat 'tmp/patchChairs.log' | sort) | sort -nk1 | sed 's/\t/ - /')"
CHAIR="$(comm -13 <(cat 'tmp/fixCinematic.log' | sort) <(cat 'tmp/patchChairs.log' | sort) | sort -nk1 | sed 's/\t/ - /')"
echo "--- Mods with fixed cinematics and captain's chairs ---" > 'tmp/report_both.txt'
echo "$BOTH" >> 'tmp/report_both.txt'
echo '' >> 'tmp/report_both.txt'
echo "--- Mods with only fixed cinematics ---" > 'tmp/report_cinematic.txt'
echo "$CINEMATIC" >> 'tmp/report_cinematic.txt'
echo '' >> 'tmp/report_cinematic.txt'
echo "--- Mods with only fixed captain's chairs ---" > 'tmp/report_chair.txt'
echo "$CHAIR" >> 'tmp/report_chair.txt'
echo '' >> 'tmp/report_chair.txt'