Couchmoster's Unified Download DF Linux Easy Script Pack - CUDDLES PackCurrent version: 1.1 Outdated
Isn't it annoying to search for all the stuff you need to play DF?
Don't you hate it when something is missing?
Why bother searching it yourself when a neat script can do it?!
As a project to practice bash coding in linux I made this little handy script.
Feel free to use it, but please keep the comment that it is initially created by me (yes I like it!)
This script assembles all you need to play DF on Linux:
DF (with Phoebus)
DT (with current memory layout)
This script relies on the work of others!
It uses simple linux tools like wget, grep, rsync to find and download current versions of programs others created!
I only take credit for the script to assemble and process those!
1. Copy spoiler code content into file (e.g. df-inst.sh) and move it to the folder you define as INSTALL_DIR (default: "$HOME"/games/dwarf-fortress)
2. Make it executeable
3. Run it! (e.g. ./df-inst.sh)
#!/bin/bash
# Created by Couchmonster bay12forums.com
set -e
#Initialize Variables for if-clause
DL_DF="0"
DL_PHOEBUS="0"
DL_DT="0"
DL_MEM="0"
DL_DFHACK="0"
DF_FOLDER="0"
DL_FOLDER="0"
DT_FOLDER="0"
#Parameter
#URL Storage
DF_SEARCH_URL="http://bay12games.com/dwarves"
DF_DL_URL="http://bay12games.com/dwarves"
DT_DL_URL="https://github.com/splintermind/Dwarf-Therapist.git"
DFFD_SEARCH_URL="http://dffd.wimbli.com/file.php?id="
DFFD_DL_URL="http://dffd.wimbli.com/download.php?id="
PHOEBUS_SEARCH_URL="${DFFD_SEARCH_URL}2430"
PHOEBUS_DL_URL="${DFFD_DL_URL}2430"
DFHACK_SEARCH_URL="${DFFD_SEARCH_URL}9410" # For gcc-4.9.1: 9401; gcc-4.6.3: 9410
DFHACK_DL_URL="${DFFD_DL_URL}9410"
#File Downloads and Games Folder
INSTALL_DIR="$HOME"/games/dwarf-fortress
DL_DIR="${INSTALL_DIR}"/downloads
DT_DIR="${INSTALL_DIR}"/Dwarf-Therapist
check_folder() {
# $1=Folder $2=Marker
if test -d "$1" ; then
echo "0"
echo "Folder \""$1"\" exists. Continue." >&2
else
echo "1"
echo "Folder \""$1"\" not found. Trying to create it later." >&2
fi
}
check_dl_folder() {
# $1=Folder $2=File $3=Marker
if test -e "$1"/"$2" ; then
echo "0"
echo "File \""$1"/"$2"\" exists. Continue" >&2
else
echo "1"
echo "File \""$1"/"$2"\" not found. Trying to download it later." >&2
fi
}
create_folder() {
# $1=Marker $2=Folder
if [ "$1" = "1" ] ; then
echo "Trying to create Folders!"
mkdir -p "$2" || (echo "Folder \""$2"\" could not be created. Exit." ; exit 1)
echo "Folder \""$2"\" created!"
fi
}
download_file() {
# $1=Marker $2=Folder $3=File $4=URL
if [ "$1" = "1" ] ; then
echo "Trying to download ${3}!"
TMP="$(echo "$3" | cut -c 1-3)"
case "$TMP" in
"Pho") wget -O ""$2"/"$3"" ""$4"&f="$3"" || (echo "Download not successful. Exit." ; exit 1) ;;
"df_") wget -O ""$2"/"$3"" ""$4"/"$3"" || (echo "Download not successful. Exit." ; exit 1) ;;
"dfh") wget -O ""$2"/"$3"" ""$4"&f="$3"" || (echo "Download not successful. Exit." ; exit 1) ;;
"Dwa") git clone "$4" || (echo "Download not successful. Exit." ; exit 1) ;;
esac
echo "File \""$3"\" downloaded!"
fi
}
extract_file() {
# $1=Folder $2=File $3=Target
echo "Extracting \""$2"\":"
TMP="$(echo "$2" | cut -c 1-3)"
case "$TMP" in
"Pho") unzip -q -o "$1"/"$2" -d "$3" || (echo "Could not extract file \""$1"/"$2"\" to \""$3"\". Exit." ; exit 1) ;;
"df_") tar xfj "$1"/"$2" -C "$3" || (echo "Could not extract file \""$1"/"$2"\" to \""$3"\". Exit." ; exit 1) ;;
"dfh") tar xfz "$1"/"$2" -C "$3" || (echo " Could not extract file \""$1"/"$2"\" to \""$3"\". Exit." ; exit 1) ;;
esac
echo "Complete. Continue."
}
echo -e "CUDDLES Pack\nCouchmonster's Unified Download DF Linux Easy Script Pack!\n"
#Folder Check
echo -e "\nChecking for game and download folder!"
DF_FOLDER="$(check_folder "${INSTALL_DIR}" "${DF_FOLDER}")"
DL_FOLDER="$(check_folder "${DL_DIR}" "${DL_FOLDER}")"
DT_FOLDER="$(check_folder "${DT_DIR}" "${DT_FOLDER}")"
#DF File Check
echo -e "\nChecking for latest Dwarf-Fortress file online!"
DF=$(wget -q "${DF_SEARCH_URL}" -O - | grep -i "<a href=" | grep -i 'linux' | cut -d \" -f 2) || (echo "Could not connect to Dwarf-Fortress URL. Exit." ; exit 1)
echo "Found file \""${DF}"\". Checking downloads folder!"
DL_DF="$(check_dl_folder "${DL_DIR}" "${DF}" "${DL_DF}")"
CHECK_DF=$(echo "${DF}" | cut -d \_ -f 2,3 | tr '_' '.')
#Phoebus File Check
echo -e "\nChecking for latest Phoebus file!"
FIND_PHOEBUS=$(wget -q "${PHOEBUS_SEARCH_URL}" -O - | grep -i 'download now' | cut -d \" -f 2 | sed "s/\&\;/\&/gi") || (echo "Could not connect to DFFD. Exit." ; exit 1)
PHOEBUS=$(echo "${FIND_PHOEBUS}" | cut -d \= -f 3)
echo "Found file \""${PHOEBUS}"\". Checking downloads folder!"
DL_PHOEBUS="$(check_dl_folder "${DL_DIR}" "${PHOEBUS}" "${DL_PHOEBUS}")"
#DFHack File Check
echo -e "\nChecking for latest DFHack version!"
FIND_DFHACK=$(wget -q "${DFHACK_SEARCH_URL}" -O - | grep -i 'download now' | cut -d \" -f 2 | sed "s/\&\;/\&/gi") || (echo "Could not connect to DFFD. Exit." ; exit 1)
DFHACK=$(echo "${FIND_DFHACK}" | cut -d \= -f 3)
echo "Found file \""${DFHACK}"\". Checking downloads folder!"
CHECK_DFHACK=$(echo ${DFHACK} | cut -d \- -f 2 | cut -d \. -f 2,3)
if [ "${CHECK_DFHACK}" = "${CHECK_DF}" ] ; then
DL_DFHACK="$(check_dl_folder "${DL_DIR}" "${DFHACK}" "${DL_DFHACK}")"
fi
#Create Folders
echo -e "\nCreating folders if necessary!"
create_folder "${DF_FOLDER}" "${INSTALL_DIR}"
create_folder "${DL_FOLDER}" "${DL_DIR}"
#Download Files
echo -e "\nDownloading Files if necessary!"
download_file "${DL_DF}" "${DL_DIR}" "${DF}" "${DF_DL_URL}"
download_file "${DL_PHOEBUS}" "${DL_DIR}" "${PHOEBUS}" "${PHOEBUS_DL_URL}"
download_file "${DL_DFHACK}" "${DL_DIR}" "${DFHACK}" "${DFHACK_DL_URL}"
download_file "${DT_FOLDER}" "" "Dwarf Therapist" "${DT_DL_URL}"
cd "${DT_DIR}"
git pull "${DT_DL_URL}"
cd "${INSTALL_DIR}"
#Extracting Files
echo -e "\nExtracting files!"
extract_file "${DL_DIR}" "${DF}" "${INSTALL_DIR}"
extract_file "${DL_DIR}" "${PHOEBUS}" "${INSTALL_DIR}/df_linux"
if [ "${CHECK_DFHACK}" = "${CHECK_DF}" ] ; then
extract_file "${DL_DIR}" "${DFHACK}" "${INSTALL_DIR}/df_linux"
echo "Fixing DFHack Lib Problem!"
rm "${INSTALL_DIR}"/df_linux/libs/libstdc++.so.6
fi
#Updating Files
echo -e "\nUpdating:"
echo "Updating Dwarf-Fortress to Phoebus!"
cp -f "${INSTALL_DIR}"/df_linux/data/init/phoebus/*.txt "${INSTALL_DIR}"/df_linux/data/init/ || (echo "Could not copy file(s) from \""${INSTALL_DIR}"/df_linux/data/init/phoebus/\" to \""${INSTALL_DIR}"/df_linux/data/init\". Exit." ; exit 1)
rm "${INSTALL_DIR}"/df_linux/*.bat "${INSTALL_DIR}"/df_linux/*.dll "${INSTALL_DIR}"/df_linux/*.exe
echo "Updating Dwarf-Fortress savegames to Phoebus!"
cd "${INSTALL_DIR}"/df_linux
chmod +x df_savegame_updater.sh
./df_savegame_updater.sh || true
echo "Success! Done!"