-
Notifications
You must be signed in to change notification settings - Fork 8
/
sommelier
executable file
·227 lines (188 loc) · 8.16 KB
/
sommelier
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/bin/bash
function install_app() {
# Install additional requirements via winetricks here
if [ -n "${TRICKS}" ]; then
for TRICK in ${TRICKS}; do
env WINEARCH="${WINEARCH}" WINEPREFIX="${WINEPREFIX}" "${WINETRICKS}" --gui --unattended ${TRICK}
done
fi
# Modify or remove this as required by your application.
if [ -n "${INSTALL_URL}" ]; then
# Downloads a file with progress using wget and yad
wget "${INSTALL_URL}" -O "${TMPDIR}/${INSTALL_EXE}" 2>&1 | \
perl -p -e '$| = 1; s/^.* +([0-9]+%) +([0-9,.]+[GMKB]) +([0-9hms,.]+).*$/\1\n# Downloading... \2 (\3)/' | \
yad --progress --title="${INSTALL_EXE}" --width=400 --center --no-buttons --auto-close --auto-kill --on-top --no-escape
# Installs the wine application
env WINEARCH="${WINEARCH}" WINEPREFIX="${WINEPREFIX}" "${WINELOADER}" "${TMPDIR}/${INSTALL_EXE}" /silent
# Removes the cached installer
rm -v "${TMPDIR}/${INSTALL_EXE}"
# Launch after install.
launch_app
fi
}
function launch_app() {
# Suppress pop-ups about graphics performance by faking the results
mkdir -p "${WINEPREFIX}/drive_c/users/${USER}/My Documents/TmForever/Config"
touch "${WINEPREFIX}/drive_c/users/${USER}/My Documents/TmForever/Config/GfxDevicePerfs.txt"
# If we don't change into the program directory some assets may not be found
cd "${WINE_DIR}"
# Only use virtual desktop if it has been requested and we're running Xorg
if [ "${XDG_SESSION_TYPE}" == "x11" ] && [ "${VIRTDESKTOP}" == "1" ]; then
# Get the native resolution of the primary display.
# Creating a virtual desktop the same size will eliminate bugs when
# switching from fullscreen to windowed mode.
NATIVE_RES=$(xrandr -q | grep primary | cut -d' ' -f4 | cut -d'+' -f1)
env WINEARCH="${WINEARCH}" WINEPREFIX="${WINEPREFIX}" "${WINELOADER}" explorer /desktop="virtual","${NATIVE_RES}" "${WINE_EXE}"
else
env WINEARCH="${WINEARCH}" WINEPREFIX="${WINEPREFIX}" "${WINELOADER}" "${WINE_EXE}"
fi
}
function prepend_dir() {
local var="$1"
local dir="$2"
if [ -d "$dir" ]; then
eval "export $var=\"\$dir\${$var:+:\$$var}\""
fi
}
function append_dir() {
local var="$1"
local dir="$2"
if [ -d "$dir" ]; then
eval "export $var=\"\${$var:+\$$var:}\$dir\""
fi
}
# Get the executable we're being asked to launch
if [ -n "${1}" ]; then
WINE_EXE="${1}"
WINE_DIR=$(dirname "${WINE_EXE}")
else
echo "ERROR! I need an executable that I should launch. Exitting here."
exit 1
fi
# If we've been given and installer URL derive the filename
if [ -n "${INSTALL_URL}" ]; then
INSTALL_EXE=$(basename "${INSTALL_URL}")
fi
# On Fedora $SNAP is under /var and there is some magic to map it to /snap.
# # We need to handle that case and reset $SNAP
SNAP=`echo $SNAP | sed -e "s|/var/lib/snapd||g"`
NOTICE="The TrackMania Nations Forever snap is experimental, built
with development releases of upstream WINE and may not function as
expected.\n\nIf you encounter issues please report them on the
TrackMania Nations Forever snap issue tracker:
\n\nhttps://github.com/Snapcrafters/tmnationsforever"
export WINEARCH="win32"
if [ "${WINEARCH}" == "win32" ]; then
ARCH="i386-linux-gnu"
else
ARCH="x86_64-linux-gnu"
fi
if [ -n "${DLLOVERRIDES}" ]; then
export WINEDLLOVERRIDES="${DLLOVERRIDES}"
fi
export WINEVERPATH=$SNAP
export WINESERVER=$SNAP/bin/wineserver
export WINELOADER=$SNAP/bin/wine
export WINETRICKS=$SNAP/bin/winetricks
export winepath=$SNAP/bin/winepath
export WINEDLLPATH=$SNAP/lib/wine/fakedlls
export WINEPREFIX="$SNAP_USER_COMMON/.wine"
#export WINEDEBUG=-all
export LD_LIBRARY_PATH="$SNAP/lib:$SNAP/lib/$ARCH:$SNAP/usr/lib:$SNAP/usr/lib/$ARCH:$LD_LIBRARY_PATH"
# XKB config
export XKB_CONFIG_ROOT=$SNAP/usr/share/X11/xkb
# Give XOpenIM a chance to locate locale data.
# This is required for text input to work in SDL2 games.
export XLOCALEDIR=$SNAP/usr/share/X11/locale
# Set XCursors path
export XCURSOR_PATH=$SNAP/usr/share/icons
# Mesa Libs for OpenGL support
append_dir LD_LIBRARY_PATH $SNAP/usr/lib/$ARCH/mesa
append_dir LD_LIBRARY_PATH $SNAP/usr/lib/$ARCH/mesa-egl
# Tell libGL where to find the drivers
export LIBGL_DRIVERS_PATH=$SNAP/usr/lib/$ARCH/dri
append_dir LD_LIBRARY_PATH $LIBGL_DRIVERS_PATH
# Workaround in snapd for proprietary nVidia drivers mounts the drivers in
# /var/lib/snapd/lib/gl that needs to be in LD_LIBRARY_PATH
# Without that OpenGL using apps do not work with the nVidia drivers.
# Ref.: https://bugs.launchpad.net/snappy/+bug/1588192
append_dir LD_LIBRARY_PATH /var/lib/snapd/lib/gl
# Pulseaudio export
append_dir LD_LIBRARY_PATH $SNAP/usr/lib/$ARCH/pulseaudio
# EGL vendor files on glvnd enabled systems
[ -d /var/lib/snapd/lib/glvnd/egl_vendor.d ] && \
append_dir __EGL_VENDOR_LIBRARY_DIRS /var/lib/snapd/lib/glvnd/egl_vendor.d
# Tell GStreamer where to find its plugins
export GST_PLUGIN_PATH=$SNAP/usr/lib/$ARCH/gstreamer-1.0
export GST_PLUGIN_SYSTEM_PATH=$SNAP/usr/lib/$ARCH/gstreamer-1.0
# gst plugin scanner doesn't install in the correct path: https://github.com/ubuntu/snapcraft-desktop-helpers/issues/43
export GST_PLUGIN_SCANNER=$SNAP/usr/lib/$ARCH/gstreamer1.0/gstreamer-1.0/gst-plugin-scanner
# XDG Config
prepend_dir XDG_CONFIG_DIRS $SNAP/etc/xdg
# Define snaps' own data dir
prepend_dir XDG_DATA_DIRS $SNAP/usr/share
prepend_dir XDG_DATA_DIRS $SNAP_USER_COMMON
export HOME=$SNAP_USER_COMMON
# Set XDG_DATA_HOME to local path
export XDG_DATA_HOME=$SNAP_USER_COMMON/.local/share
mkdir -p $XDG_DATA_HOME
# Workaround for GLib < 2.53.2 not searching for schemas in $XDG_DATA_HOME:
# https://bugzilla.gnome.org/show_bug.cgi?id=741335
prepend_dir XDG_DATA_DIRS $XDG_DATA_HOME
# Set cache folder to local path
export XDG_CACHE_HOME=$SNAP_USER_COMMON/.cache
mkdir -p $XDG_CACHE_HOME
# Set config folder to local path
export XDG_CONFIG_HOME=$SNAP_USER_COMMON/.config
mkdir -p $XDG_CONFIG_HOME
# Create $XDG_RUNTIME_DIR if not exists (to be removed when LP: #1656340 is fixed)
[ -n "$XDG_RUNTIME_DIR" ] && mkdir -p $XDG_RUNTIME_DIR -m 700
# Make PulseAudio socket available inside the snap-specific $XDG_RUNTIME_DIR
if [ -n "$XDG_RUNTIME_DIR" ]; then
pulsenative="pulse/native"
pulseaudio_sockpath="$XDG_RUNTIME_DIR/../$pulsenative"
if [ -S "$pulseaudio_sockpath" ]; then
export PULSE_SERVER="unix:${pulseaudio_sockpath}"
fi
fi
# Font Config and themes
export FONTCONFIG_PATH=$SNAP/etc/fonts/conf.d
#export FONTCONFIG_FILE=$XDG_CONFIG_HOME/fontconfig/fonts.conf
# Gdk-pixbuf loaders
export GDK_PIXBUF_MODULE_FILE=$XDG_CACHE_HOME/gdk-pixbuf-loaders.cache
export GDK_PIXBUF_MODULEDIR=$SNAP/usr/lib/$ARCH/gdk-pixbuf-2.0/2.10.0/loaders
if [ -f $SNAP/usr/lib/$ARCH/gdk-pixbuf-2.0/gdk-pixbuf-query-loaders ] && [ ! -f "${GDK_PIXBUF_MODULE_FILE}" ]; then
$SNAP/usr/lib/$ARCH/gdk-pixbuf-2.0/gdk-pixbuf-query-loaders > $GDK_PIXBUF_MODULE_FILE
fi
# Stop wine from updating $WINEPREFIX automatically
if [ -f "${WINEPREFIX}/.update-timestamp" ]; then
chkstmp=$(grep disable "${WINEPREFIX}/.update-timestamp" | wc -l)
if [ $chkstmp -eq 0 ]; then
echo "disable" > "${WINEPREFIX}/.update-timestamp"
fi
fi
# Initialise wine
if [ ! -f "${WINEPREFIX}/drive_c/windows/win.ini" ]; then
# Splash
yad --timeout=15 --timeout-indicator=bottom --text="${NOTICE}" --no-escape --width=460 --center --no-buttons --splash &
# Create the WINE environment
env WINEARCH="${WINEARCH}" WINEPREFIX="${WINEPREFIX}" "${WINELOADER}" wineboot --init 2>&1 | \
yad --progress --title="Preparing Windows environment" --width=400 --center --no-buttons --auto-close --auto-kill --on-top --pulsate
# Opt out of winetricks metrics - we ninja this to avoid dialogs
if [ ! -f "${XDG_CACHE_HOME}/winetricks/track_usage" ]; then
mkdir -p "${XDG_CACHE_HOME}/winetricks"
echo 0 > "${XDG_CACHE_HOME}/winetricks/track_usage"
fi
else
# Notification
notify-send --icon "${SNAP}/meta/gui/tmnationsforever.png" --expire-time=15000 "TrackMania Nations Forever" "${NOTICE}"
fi
# Launch wineboot/winecfg/winetricks if requested.
# If the executable exists then launch it otherwise install it then lauch it.
if [[ ${WINE_EXE} = *"winecfg"* ]] || [[ ${WINE_EXE} = *"wineboot"* ]] || [[ ${WINE_EXE} = *"winetricks"* ]]; then
env WINEARCH="${WINEARCH}" WINEPREFIX="${WINEPREFIX}" "$@"
elif [ -e "${WINE_EXE}" ]; then
launch_app
else
install_app
fi