summarylogtreecommitdiffstats
path: root/evesetup.shlib
blob: 19198963822c4852aa2933da329929554ed9ff59 (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
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
#!/bin/sh

# evelauncher fixed values

CONFDIR="$HOME/.config/CCP"
EVECONF="$CONFDIR/EVE.conf"

# default value if not set

SHAREDIR="$HOME/.eve"

# evesetup shared functions

check_elv() {
	ELBIN=$(getdate $LAUNCHER/evelauncher)
	ELBIN=$(expr $ELBIN / 180 \* 180)
	ELARC=$(getdate $SETUPDIR/lib/evelauncher-$ELVER.tar.?z)
	ELARC=$(expr $ELARC / 180 \* 180)
	if [ "$ELBIN" -lt "$ELARC" ] ;then
	    if [ -d "$LAUNCHER" ] ;then
		rm -rf $LAUNCHER
		desktop_msg "Update EVE Launcher binaries"
	    fi
	    tar xf $SETUPDIR/lib/evelauncher-$ELVER.tar.?z -C $EVEDIR
	    mv $EVEDIR/evelauncher $LAUNCHER
	    if [ -f "$HOME/.config/devilspie2/evelauncher.lua" ] ;then
		sed -i 2\ s,[0-9].*\",$ELVER\", \
		    $HOME/.config/devilspie2/evelauncher.lua
	    fi
	fi
}

check_env() {
    if [ -d "$CONFDIR" ] ;then
	if [ -r "$EVECONF" ] ;then
	    SHAREDIR=$(getval SharedCacheFolder)
	fi
    fi
    [ ! -d "$SHAREDIR" ] && SHAREDIR=""
    if [ "x$SHAREDIR" != "x$EVEDIR/SharedCache/" ] ;then
	desktop_msg "Please wait, preparing environment in $EVEDIR"
	mkdir -p $CONFDIR
	echo "[General]" >$EVECONF
	echo "SharedCacheFolder=$EVEDIR/SharedCache/" >>$EVECONF
	echo "UseCustomWine=true" >>$EVECONF
	echo "CustomWinePath=$WINEPATH/wine" >>$EVECONF
	mkdir -p $EVEDIR/SharedCache
	if [ -d "$SHAREDIR/ResFiles/" ] ;then
	    mv $SHAREDIR/ResFiles/ $EVEDIR/SharedCache/
	    mv $SHAREDIR/*.txt $EVEDIR/SharedCache/
	    rm -rf $SHAREDIR
	fi
    fi
}

check_steam() {
    if [ ! -r "$LAUNCHER/steam_appid.txt" -a -x "$(which steam 2>/dev/null)" ] ;then
	echo "8500" >$LAUNCHER/steam_appid.txt
    fi
}

check_wine() {
    CUSTOMWP=$(getval CustomWinePath)
    SHAREDIR=$(getval SharedCacheFolder)
    UCW=$(getval UseCustomWine)
    WINEPREFIX=${SHAREDIR}wineenv
    if [ "x$UCW" = "xtrue" ] ;then
	WINEPATH=${CUSTOMWP%/*}
	[ -d "${SHAREDIR}wine" ] && rm -rf ${SHAREDIR}wine
    else
	CUSTOMWP=${SHAREDIR}wine
	WINEPATH=${SHAREDIR}wine/bin
    fi
    if [ ! -x "$WINEPATH/wine" ] ;then
	desktop_msg "ERROR: \"$CUSTOMWP\" not found!"
	exit 1
    fi
    INSTWINE=$(cat $WINEPREFIX/.update-timestamp 2>/dev/null | tr -dc [:digit:]) || true
    WINEINFP=$(readlink -f $CUSTOMWP)
    WINECONF=$(find ${WINEINFP%bin*}share/wine* -name 'wine.inf')
    WINEDATE=$(getdate $WINECONF)
    if [ "x$WINEDATE" != "x$INSTWINE" ] ;then
	desktop_msg "Preparing wine in $WINEPREFIX"
	env WINEPREFIX=$WINEPREFIX \
	    WINEDEBUG=-all \
	    WINEDLLOVERRIDES="mscoree,mshtml=d" \
	    $WINEPATH/wine wineboot
	env WINEPREFIX=$WINEPREFIX \
	    $WINEPATH/wine reg add \
	    'HKCU\Software\Wine\FileOpenAssociations' \
	    /v Enable /d N /f >/dev/null
    fi
    if [ "x$(grep -csw winemenubuilder $WINEPREFIX/system.reg)" != "x0" ] ;then
	if [ -x "$WINEPATH/wine64" ] ;then
	    WINE=$WINEPATH/wine64
	else
	    WINE=$WINEPATH/wine
	fi
	env WINEPREFIX=$WINEPREFIX \
	    $WINE reg delete \
	    'HKLM\Software\Microsoft\Windows\CurrentVersion\RunServices' \
	    /v winemenubuilder /f >/dev/null
    fi
}

desktop_msg() {
    if [ -x "$(which notify-send 2>/dev/null)" ] ;then
	notify-send -i eve $(basename $0) "$@"
    fi
    printf "$(basename $0): $@\n"
}

getdate() {
    printf $(ls -l --time-style=+%s $1 2>/dev/null | cut -d' ' -f6) \
	2>/dev/null || printf 180
}

getval() {
    if [ ! -r "$EVECONF" ] ;then
	desktop_msg "ERROR: EVE Configuration not found!"
	exit 1
    fi
    printf $(grep "$1" $EVECONF | cut -d= -f2)
}