-
Notifications
You must be signed in to change notification settings - Fork 13
/
setup-env
executable file
·82 lines (69 loc) · 3.71 KB
/
setup-env
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
#!/bin/sh
if [ "$SNAP_ARCH" = "amd64" ]; then
ARCH="x86_64-linux-gnu"
elif [ "$SNAP_ARCH" = "armhf" ]; then
ARCH="arm-linux-gnueabihf"
elif [ "$SNAP_ARCH" = "arm64" ]; then
ARCH="aarch64-linux-gnu"
else
ARCH="$SNAP_ARCH-linux-gnu"
fi
GDK_CACHE_DIR="$SNAP_USER_COMMON/.cache"
[ ! -d "$GDK_CACHE_DIR" ] && mkdir -p "$GDK_CACHE_DIR"
# Export Gio modules so can be used by Gdk-pixbuf loaders below
export GIO_MODULE_DIR="$SNAP/usr/lib/$ARCH/gio/modules"
# Gdk-pixbuf loaders
export GDK_PIXBUF_MODULE_FILE="$GDK_CACHE_DIR/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" ]; then
"$SNAP/usr/lib/$ARCH/gdk-pixbuf-2.0/gdk-pixbuf-query-loaders" > "$GDK_PIXBUF_MODULE_FILE"
fi
# setup fontconfig cache to avoid the system cache
FONTCONFIG_CACHE_DIR="$SNAP_USER_COMMON/.cache/fontconfig"
[ ! -d "$FONTCONFIG_CACHE_DIR" ] && mkdir -p "$FONTCONFIG_CACHE_DIR"
# create a fontconfig file which specifies only our cache
export FONTCONFIG_FILE="$SNAP_USER_COMMON/fonts.conf"
# always recreate this to ensure we overwrite an old one which may have
# come from a different base snap version etc in a previous release of the
# emacs snap
cp "$SNAP/etc/fonts/fonts.conf" "$FONTCONFIG_FILE"
# there are usually multiple cachedir's listed - one under /var, one in
# home etc - we only want one and we want it to be specific for the snap so
# we don't encounter cache files created by a different version of
# fontconfig - so replace *all* with ours
sed -i "s|<cachedir.*/cachedir>|<cachedir>$FONTCONFIG_CACHE_DIR</cachedir>|" "$FONTCONFIG_FILE"
# immodule cache
GTK_IM_MODULE_DIR="$GDK_CACHE_DIR/immodules"
[ ! -d "$GTK_IM_MODULE_DIR" ] && mkdir -p "$GTK_IM_MODULE_DIR"
export GTK_IM_MODULE_FILE="$GTK_IM_MODULE_DIR/immodules.cache"
if [ -f "$SNAP/usr/lib/$ARCH/libgtk-3-0/gtk-query-immodules-3.0" ]; then
"$SNAP/usr/lib/$ARCH/libgtk-3-0/gtk-query-immodules-3.0" "$SNAP/usr/lib/$ARCH/gtk-3.0/3.0.0/immodules/"im-*.so > "$GTK_IM_MODULE_FILE"
fi
# The version of gtk that we ship references a gsetting that is now deprecated
# so recompile the hosts gsettings schema to reenable this just for the emacs
# snap
if grep -q org.gnome.settings-daemon.plugins.xsettings.deprecated /usr/share/glib-2.0/schemas/org.gnome.settings-daemon.plugins.xsettings.gschema.xml 2>/dev/null; then
export GSETTINGS_SCHEMA_DIR="$SNAP_USER_COMMON/.local/share/glib-2.0/schemas"
[ ! -d "$GSETTINGS_SCHEMA_DIR" ] && mkdir -p "$GSETTINGS_SCHEMA_DIR"
if [ ! -f "$GSETTINGS_SCHEMA_DIR/gschemas.compiled" ]; then
cp /usr/share/glib-2.0/schemas/*.xml "$GSETTINGS_SCHEMA_DIR"
# remove the deprecated schema entry so that keys are now in the main schema
sed -i "/org.gnome.settings-daemon.plugins.xsettings.deprecated/d" "$GSETTINGS_SCHEMA_DIR/org.gnome.settings-daemon.plugins.xsettings.gschema.xml"
sed -i "0,/<\/schema>/{//d;}" "$GSETTINGS_SCHEMA_DIR/org.gnome.settings-daemon.plugins.xsettings.gschema.xml"
# recompile
$SNAP/usr/bin/glib-compile-schemas "$GSETTINGS_SCHEMA_DIR"
fi
fi
export XDG_DATA_DIRS="$SNAP/usr/share:$XDG_DATA_DIRS"
# native comp needs to find as etc and this comes from within the snap
# itself
export PATH="$PATH:/snap/emacs/current/usr/bin"
# finally break out of AppArmor confinement to avoid issues like
# https://github.com/alexmurray/emacs-snap/issues/36 - we are a classic
# snap so snapd runs us under a complain mode profile anyway (which in
# general doesn't restrict anything) but it does cause some applications to
# get confused like the GNOME/Ubuntu dock
if grep -q "^snap.emacs.[a-z-]\+ (complain)" /proc/self/attr/current 2>/dev/null; then
echo -n "changeprofile unconfined" > /proc/self/attr/current 2>/dev/null
fi
exec "$@"