summarylogtreecommitdiffstats
path: root/doukutsu
blob: 942dcbecccbfb3eba9b10de7e8e60e897f87068c (plain)
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
#!/usr/bin/env bash

# This script replicates the Doukutsu working folder in a specified directory
# (defaults to ~/.doukutsu) by creating symbolic links to the installed
# files. This allows the game to store saves and configuration files
# without write permissions in the install folder and lets every user on 
# system keep their own saves/settings. It then launches the game or
# configuration tool.

INSTALLDIR=/opt/doukutsu
USERDATADIR=$HOME/.doukutsu

function create_structure {
    mkdir -p $USERDATADIR
    ln -s -t $USERDATADIR $INSTALLDIR/{doukutsu,doukutsu.bin,DoConfigure,data,doc} 
    cp $INSTALLDIR/Config.dat $USERDATADIR
    cd $USERDATADIR
}

function integrity_check {
    USERFILECOUNT=`find $USERDATADIR -maxdepth 1 | grep -v Profile.dat | grep -v error.log | wc -l`
    SYSTEMFILECOUNT=`find $INSTALLDIR -maxdepth 1 | grep -v Profile.dat | grep -v error.log | wc -l` 
    if [ $USERFILECOUNT != $SYSTEMFILECOUNT ]; 
      then create_structure;
    fi
}

while getopts "ch" options; do
    case $options in
        c)
            integrity_check
            cd $USERDATADIR
            ./DoConfigure
            exit 0;;
        h|*)
            printf "Usage: doukutsu [-h] [-c]\n"
            exit 0;;
    esac
done

if [ -d $USERDATADIR ]; then
    integrity_check

    cd $USERDATADIR
    exec ./doukutsu $@
else
    create_structure

    exec ./doukutsu $@
fi