Skip to content

Instantly share code, notes, and snippets.

@xrogaan
Last active January 23, 2020 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xrogaan/c99347c30ef80399a9ba6e8617ae3503 to your computer and use it in GitHub Desktop.
Save xrogaan/c99347c30ef80399a9ba6e8617ae3503 to your computer and use it in GitHub Desktop.
Update cdda's experimental by copying over data from previous version.
#!/usr/bin/env bash
#
# Copyright 2020 Ludovic Bellière <xrogaan@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
STAGING="$(cd $(dirname $0) && echo $PWD)"
cd "${STAGING}"
OPT="$(cd ../opt/ && echo $PWD)"
FILENAME="cataclysmdda-0.D-Linux_x64-Tiles-@RELEASE@.tar.gz"
FETCH_URL="https://github.com/CleverRaven/Cataclysm-DDA/releases/download/cdda-jenkins-b@RELEASE@/cataclysmdda-0.D-Linux_x64-Tiles-@RELEASE@.tar.gz"
usage() {
echo "Usage: $0 -r releaseInt -s previous_cdda" 1>&2
}
exit_error() {
>&2 echo "$@"
exit 1
}
exit_abnormal() {
usage
exit 1
}
[ $# -eq 0 ] && exit_abnormal
RELEASE=0
while getopts ":r:s:h" opt; do
case "${opt}" in
h)
usage
exit 0
;;
r)
RELEASE=$OPTARG
;;
s)
SOURCE=$OPTARG
if [[ ! -d $SOURCE ]]; then
exit_error "$SOURCE does not exists or isn't a folder."
fi
SOURCE="$(cd $SOURCE && pwd)"
SOURCE_GFX="${SOURCE}/gfx"
;;
:)
echo "Error: -${OPTARG} requires an argument."
exit_abnormal
;;
*)
exit_abnormal
;;
esac
done
if [ $RELEASE -eq 0 ]; then
>&2 echo "Release needs to be defined."
usage
exit 1
fi
FILENAME=$(echo $FILENAME | sed -e "s/@RELEASE@/$RELEASE/")
# Don't redownload an existing file.
if [[ ! -f "$RELEASE/$FILENAME" ]]; then
FETCH_URL=$(echo $FETCH_URL | sed -e "s/@RELEASE@/$RELEASE/g")
echo -ne "Downloading $FETCH_URL...\t"
wget -q --directory-prefix=$RELEASE $(echo $FETCH_URL | sed -e "s/@RELEASE@/$RELEASE/g")
echo "Done."
else
echo "Archive already cached, not downloading..."
fi
echo "Entering $RELEASE/ ..."
# Staging -> 123456
pushd $RELEASE > /dev/null
echo "Unpacking $FILENAME..."
aunpack -q $FILENAME
NEWFOLDER="cataclysmdda-0.D-${RELEASE}"
echo -ne "Rename cataclysmdda-0.D to $NEWFOLDER...\t"
mv "cataclysmdda-0.D" $NEWFOLDER
echo "Done."
echo "Entering cataclysmdda-0.D-$RELEASE/ ..."
# 123456 -> cataclysmdda-123456
pushd "cataclysmdda-0.D-$RELEASE" > /dev/null
echo -ne "Copying old data to new game folder ...\t"
mv --target-directory=. \
"${SOURCE}/config" \
"${SOURCE}/save" \
"${SOURCE}/templates" \
"${SOURCE}/sound"
mv --target-directory=gfx \
"${SOURCE_GFX}/MSX++UnDeadPeopleEdition"
echo "Done."
# cataclysmdda-123456 -> 123456
popd > /dev/null
echo "mv $NEWFOLDER $(cd ../../ && pwd)"
mv $NEWFOLDER ../../
popd > /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment