-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathtemplate.sh
85 lines (68 loc) · 1.64 KB
/
template.sh
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
show_usage() {
echo "Usage: $0 --appdir <path to AppDir>"
echo
}
while [ "$1" != "" ]; do
case "$1" in
--plugin-api-version)
echo "0"
exit 0
;;
--appdir)
APPDIR="$2"
shift
shift
;;
--help)
show_usage
exit 0
;;
*)
echo "Invalid argument: $1"
echo
show_usage
exit 1
;;
esac
done
if [ "$APPDIR" == "" ]; then
show_usage
exit 1
fi
APPDIR="$(realpath "$APPDIR")"
echo "Installing AppRun hook 'checkrt'"
mkdir -p "$APPDIR/apprun-hooks"
cat > "$APPDIR/apprun-hooks/linuxdeploy-plugin-checkrt.sh" << \EOF
#! /usr/bin/env bash
if [ -z "$APPDIR" ]; then
APPDIR="$(dirname "$(realpath "$0")")"
fi
if [ -x "$APPDIR/checkrt/checkrt" ]; then
CHECKRT_LIBS="$($APPDIR/checkrt/checkrt)"
# prepend to LD_LIBRARY_PATH
if [ -n "$CHECKRT_LIBS" ]; then
export LD_LIBRARY_PATH="${CHECKRT_LIBS}:${LD_LIBRARY_PATH}"
fi
fi
# check for exec.so
if [ -f "$APPDIR/checkrt/exec.so" ]; then
export LD_PRELOAD="$APPDIR/checkrt/exec.so:${LD_PRELOAD}"
fi
# debugging
if [ -n "$CHECKRT_DEBUG" ]; then
echo "CHECKRT>> LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
echo "CHECKRT>> LD_PRELOAD=$LD_PRELOAD"
fi
EOF
mkdir -p "$APPDIR/checkrt"
cd "$APPDIR/checkrt"
save_files
LDFLAGS="-Wl,--as-needed -static-libgcc -ldl -s"
CFLAGS="-O2 -DNDEBUG"
echo "Compiling checkrt"
cc $CFLAGS checkrt.c -o checkrt $LDFLAGS
echo "Compiling exec.so"
cc $CFLAGS -shared -fPIC exec.c -o exec.so $LDFLAGS
rm checkrt.c exec.c
./checkrt --copy
cd "$APPDIR"