Bash install script (Linux/Unix)

Discuss Daggerfall Unity and Daggerfall Tools for Unity.
Post Reply
User avatar
pango
Posts: 175
Joined: Wed Jul 18, 2018 6:14 pm
Location: France
Contact:

Bash install script (Linux/Unix)

Post by pango » Sun Aug 19, 2018 12:00 pm

Hi all,
I created a small script for my own use to (re)deploy Daggerfall Unity and the mods I use into a directory (why to by hand what can be automated?), so I thought I could just as well share it. It does not take care of downloading the archives, since I don't think it can be fully automated for now: the archives must be present in the script's directory.

Beside simplifying upgrades, it can be useful for testing a problem with a different set of mods. Just comment the definitions of variables for mods archive names you don't want, and optionally deploy in a new directory.

Beware, if you redeploy over an old installation it will reinstall from scratch (as recommended); And it currently does not backup mods settings (*.json files)
Comments and improvements welcome :)

Repository: https://github.com/petchema/deploy_DFU

Code: Select all

#!/bin/bash
# Deploy Dagggerfall Unity and mods

# Stop if anything goes wrong
set -e

self=$(basename "$0")
version="1.1"

fatal() {
    echo "$self: $1" 1>&2
    exit 1
}

usage() {
    echo "Usage: $self [install directory]" 1>&2
    exit 1
}

[[ "$1" = "-h" || "$1" = "--help" ]] && usage

owndir=$(dirname "$0")
owndir=$(cd "$owndir" && pwd)
[ -z "$owndir" ] && fatal "can't find my own directory"

# Set defaults
SOURCEDIR="$owndir"

[ -n "$1" ] || usage
TARGETDIR="$1"

# --------------------------------------------------------------------

# By default this script will look for archives in its directory; Feel free to override here
#SOURCEDIR="$HOME/Downloads/Daggerfall Unity"


# Base game https://www.dfworkshop.net/projects/daggerfall-unity/live-builds/
ARC_BASEGAME=interkarma-daggerfall-unity-daggerfallunity_linux_universal-127.zip


# Mods https://forums.dfworkshop.net/viewforum.php?f=27

# Eye candy

# Daggerfall Remaster 3.0 https://forums.dfworkshop.net/viewtopic.php?f=27&t=1168
ARC_REMASTER30=Textures_3.0.rar
# Handpainted Models https://forums.dfworkshop.net/viewtopic.php?f=27&t=583
#ARC_HANDPAINTEDMODELS="Handpainted models v142b.zip"
# Enhanced Sky https://forums.dfworkshop.net/viewtopic.php?f=14&t=29&start=50
ARC_ENHANCEDSKY=EnhancedSky_2.1.0.zip
# Distant Terrain https://forums.dfworkshop.net/viewtopic.php?f=27&t=10
ARC_DISTANTTERRAIN=DistantTerrain_2.4.2.zip
# Mountains and Hills https://forums.dfworkshop.net/viewtopic.php?f=27&t=1008
#ARC_MOUNTAINSHILLS="Mountain And Hills 1.01.zip"
# Real Grass 2 https://forums.dfworkshop.net/viewtopic.php?f=27&t=964
ARC_REALGRASS=RealGrass_2.2.7z
# Vibrant Wind https://forums.dfworkshop.net/viewtopic.php?f=14&t=532
ARC_VIBRANTWIND=VibrantWind_v0.5_.7z
# Realtime Reflections https://forums.dfworkshop.net/viewtopic.php?f=27&t=122
ARC_REALTIMEREFLECTIONS=RealtimeReflections_2.2.0.zip
# Villager Immersion Overhaul https://forums.dfworkshop.net/viewtopic.php?f=27&t=924
ARC_VILLAGERIMMERSION=VIO-V2.rar
# Post Processing Effects https://forums.dfworkshop.net/viewtopic.php?f=27&t=694
ARC_POSTPROCESSING=PostProcessing_0.3.1a_.7z
# Convenient Clock https://forums.dfworkshop.net/viewtopic.php?f=27&t=1021
ARC_CONVENIENTCLOCK="Convenient Clock 1.02.zip"
# Loading Screen https://forums.dfworkshop.net/viewtopic.php?f=27&t=469
ARC_LOADINGSCREEN=LoadingScreen_2.2_.7z
ARC_LOADINGSCREENOBLIVION=OblivionStyledLoadScreensV2.rar

# Gameplay

# Warm Ashes: Dangerous Dungeon Exteriors https://forums.dfworkshop.net/viewtopic.php?f=27&t=1087
ARC_WARMASHES=WarmAshesV1.1.rar
# DFU Quest Pack #1 https://forums.dfworkshop.net/viewtopic.php?f=27&t=924
ARC_QUESTPACK1GUILD=Quest_Pack_1_Guild.zip
ARC_QUESTPACK1NONGUILD=Quest_Pack_1_NonGuild.1.zip
ARC_QUESTPACK1PERPETUALS="Quest Pack 1 Perpetuals.zip"
# Archeologists guild https://forums.dfworkshop.net/viewtopic.php?f=27&t=888&hilit=archeologists&start=80
ARC_ARCHEOLOGISTSGUILD=ArchaeologistsGuild-0.2.zip

# Allow workarounds for known issues between mods
USE_HACKS=1

# --------------------------------------------------------------------

# -- preflight checks

check_available() {
    command -v "$1" > /dev/null 2>&1 || fatal "\`$1' command not found"
}

# Use 7z for everything?
check_available unzip
check_available unrar
check_available 7z

for archive in ${!ARC_*}; do
    if [ "${!archive}" ]; then
	echo "Testing \`${!archive}' presence..."
	[ -e "$SOURCEDIR/${!archive}" ] || fatal "archive \`$SOURCEDIR/${!archive}' not found, aborting"
    fi
done

# -- Let's go

SIGNATUREFILE="$TARGETDIR/.deploy_DFU"
if [ -d "$TARGETDIR" ]; then
    [ -e "$SIGNATUREFILE" ] || fatal "not replacing \`$TARGETDIR' we didn't create"
    rm -rf "$TARGETDIR"
fi
mkdir -p "$TARGETDIR"
echo "Install script: $self $version" > "$SIGNATUREFILE"

unzip "$SOURCEDIR/$ARC_BASEGAME" -d "$TARGETDIR"
echo "Base game: $ARC_BASEGAME" >> "$SIGNATUREFILE"
echo "Options: USE_HACKS=$USE_HACKS" >> "$SIGNATUREFILE"
assets="$TARGETDIR"/DaggerfallUnity_Data/StreamingAssets

# -- Eye candy

if [ "$ARC_REMASTER30" ]; then
    unrar x "$SOURCEDIR/$ARC_REMASTER30" "$assets"/
    echo "Mod: $ARC_REMASTER30" >> "$SIGNATUREFILE"
fi

if [ "$ARC_HANDPAINTEDMODELS" ]; then
    unzip -j "$ARC_HANDPAINTEDMODELS" -d "$assets"/Mods "${ARC_HANDPAINTEDMODELS%.zip}/StandaloneLinux/*.dfmod"
    echo "Mod: $ARC_HANDPAINTEDMODELS" >> "$SIGNATUREFILE"
fi

if [ "$ARC_ENHANCEDSKY" ]; then
    unzip -j "$SOURCEDIR/$ARC_ENHANCEDSKY" -d "$assets"/Mods "StandaloneLinux/enhanced sky.dfmod"
    echo "Mod: $ARC_ENHANCEDSKY" >> "$SIGNATUREFILE"
fi

if [ "$ARC_DISTANTTERRAIN" ]; then
    unzip -j "$SOURCEDIR/$ARC_DISTANTTERRAIN" -d "$assets"/Mods "StandaloneLinux/distant terrain.dfmod"
    echo "Mod: $ARC_DISTANTTERRAIN" >> "$SIGNATUREFILE"
fi

if [ "$ARC_MOUNTAINSHILLS" ]; then
    unzip -j "$SOURCEDIR/$ARC_MOUNTAINSHILLS" -d "$assets"/Mods "StandaloneLinux/mountains and hills.dfmod"
    echo "Mod: $ARC_MOUNTAINSHILLS" >> "$SIGNATUREFILE"
fi

if [ "$ARC_REALGRASS" ]; then
    7z e "$SOURCEDIR/$ARC_REALGRASS" "${ARC_REALGRASS%.7z}"/Mod/Linux/realgrass.dfmod -o"$assets"/Mods/
    echo "Mod: $ARC_REALGRASS" >> "$SIGNATUREFILE"
fi

if [ "$ARC_VIBRANTWIND" ]; then
    7z e "$SOURCEDIR/$ARC_VIBRANTWIND" "${ARC_VIBRANTWIND%.7z}"/Linux/vibrantwind.dfmod -o"$assets"/Mods/
    echo "Mod: $ARC_VIBRANTWIND" >> "$SIGNATUREFILE"
fi

if [ "$ARC_REALTIMEREFLECTIONS" ]; then
    unzip -j "$SOURCEDIR/$ARC_REALTIMEREFLECTIONS" -d "$assets"/Mods "StandaloneLinux/realtime reflections.dfmod" 
    unzip -o "$SOURCEDIR/$ARC_REALTIMEREFLECTIONS" -d /tmp RealtimeReflections_textures.zip
    unzip /tmp/RealtimeReflections_textures.zip -d "$assets"/Textures
    echo "Mod: $ARC_REALTIMEREFLECTIONS" >> "$SIGNATUREFILE"
fi

if [ "$ARC_VILLAGERIMMERSION" ]; then
    unrar x -y "$SOURCEDIR/$ARC_VILLAGERIMMERSION" "$assets"/Textures/
    echo "Mod: $ARC_VILLAGERIMMERSION" >> "$SIGNATUREFILE"
fi

if [ "$ARC_POSTPROCESSING" ]; then
    7z e "$SOURCEDIR/$ARC_POSTPROCESSING" "${ARC_POSTPROCESSING%.7z}"/Linux/postprocessing.dfmod -o"$assets"/Mods/
    echo "Mod: $ARC_POSTPROCESSING" >> "$SIGNATUREFILE"
fi

if [ "$ARC_CONVENIENTCLOCK" ]; then
    unzip -j "$SOURCEDIR/$ARC_CONVENIENTCLOCK" -d "$assets"/Mods "StandaloneLinux/convenient clock.dfmod"
    echo "Mod: $ARC_CONVENIENTCLOCK" >> "$SIGNATUREFILE"
fi

if [ "$ARC_LOADINGSCREEN" ]; then
    7z x "$SOURCEDIR/$ARC_LOADINGSCREEN" -o/tmp "${ARC_LOADINGSCREEN%.7z}"/StreamingAssets/Mods/LoadingScreen
    mv /tmp/"${ARC_LOADINGSCREEN%.7z}"/StreamingAssets/Mods/LoadingScreen "$assets"/Mods/
    7z e "$SOURCEDIR/$ARC_LOADINGSCREEN" -o"$assets"/Mods/LoadingScreen/ "${ARC_LOADINGSCREEN%.7z}"/OS-specific/Linux/loadingscreen.dfmod
    echo "Mod: $ARC_LOADINGSCREEN" >> "$SIGNATUREFILE"

    if [ "$ARC_LOADINGSCREENOBLIVION" ]; then
	unrar x -y "$SOURCEDIR/$ARC_LOADINGSCREENOBLIVION" "$assets"/Mods/LoadingScreen/Images/
	echo "Mod: $ARC_LOADINGSCREENOBLIVION" >> "$SIGNATUREFILE"
    fi
fi

# -- Gameplay

if [ "$ARC_WARMASHES" ]; then
    unrar x "$SOURCEDIR/$ARC_WARMASHES" -o "$assets"/Quests/ WAQ01.txt WAQ02.txt WAQ03.txt WAQ04.txt
    unrar x "$SOURCEDIR/$ARC_WARMASHES" -o "$assets"/QuestPacks/ WAQ00.txt
    echo "Mod: $ARC_WARMASHES" >> "$SIGNATUREFILE"
fi

if [ "$ARC_QUESTPACK1GUILD" ]; then
    unzip -o "$SOURCEDIR/$ARC_QUESTPACK1GUILD" -d "$assets"/QuestPacks # Should only unpack JH subdir & contents, oh well
    echo "Mod: $ARC_QUESTPACK1GUILD" >> "$SIGNATUREFILE"
fi
if [ "$ARC_QUESTPACK1NONGUILD" ]; then
    unzip -o "$SOURCEDIR/$ARC_QUESTPACK1NONGUILD" -d "$assets"/QuestPacks # Should only unpack JH subdir & contents, oh well
    echo "Mod: $ARC_QUESTPACK1NONGUILD" >> "$SIGNATUREFILE"
fi
if [ "$ARC_QUESTPACK1PERPETUALS" ]; then
    unzip -o "$SOURCEDIR/$ARC_QUESTPACK1PERPETUALS" -d "$assets"/QuestPacks
    echo "Mod: $ARC_QUESTPACK1PERPETUALS" >> "$SIGNATUREFILE"
fi

if [ "$ARC_ARCHEOLOGISTSGUILD" ]; then
    unzip -j "$SOURCEDIR/$ARC_ARCHEOLOGISTSGUILD" -d "$assets"/Mods/ StandaloneLinux/archaeologists.dfmod
    echo "Mod: $ARC_ARCHEOLOGISTSGUILD" >> "$SIGNATUREFILE"
fi

if [ "$USE_HACKS" = "1" ]; then
    # https://forums.dfworkshop.net/viewtopic.php?f=27&t=1021&p=14696#p14696
    if [ "$ARC_CONVENIENTCLOCK" ]; then
	# Keep original compass
	for compassfile in "$assets"/Textures/Img/COMP{ASS,BOX}.IMG.{png,xml}; do
	    [ -e "$compassfile" ] && mv "$compassfile" "$compassfile.disabled"
	done
    fi
fi

echo "Installation: successful" >> "$SIGNATUREFILE"
echo "Installed successfully under \`$TARGETDIR'"
exit 0
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart

Post Reply