-
Notifications
You must be signed in to change notification settings - Fork 1
/
install_start.sh
executable file
·118 lines (99 loc) · 4 KB
/
install_start.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
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
#!/bin/bash
# generated by ll-helper
echo Setting Application Entrypoint
PATCH_APP_PATH="s#/opt/apps/\S+/files#${PREFIX}#g"
PATCH_USR_PATH="s#/usr#$PREFIX#g"
for deb_file in linglong/sources/*.deb; do
if [[ -f "$deb_file" ]]; then
pkg_name=$(dpkg-deb --info "$deb_file" | grep -m 1 "Package:" | awk '{print $2}')
if [ "$pkg_name" == "$LINGLONG_RAW_ID" ]; then
echo "Found package: $pkg_name in $deb_file"
DESKTOP_LIST=$(dpkg --contents $deb_file | grep -oP "[^\/]+.desktop$" | paste -sd :)
fi
fi
done
rm -f error.log
function log_error() {
echo -ne "\033[31m"
echo $@ | tee -a error.log
echo -ne "\033[0m"
}
while read FILE; do
NAME=$(basename "$FILE")
DIR=$(dirname "$FILE")
NAME_NO_EXT=${NAME%.*}
if [[ ! ":$DESKTOP_LIST:" == *":$NAME:"* ]]; then
rm -v "$FILE"
continue
fi
TO="$PREFIX/share/applications/${LINGLONG_APP_ID}_$NAME_NO_EXT.desktop"
mv -v "$FILE" "$TO"
done <<<$(find "$PREFIX/share/applications/" -name "*.desktop")
STARTUP=$(cat $PREFIX/share/applications/*.desktop | grep '^Exec=' | head -n 1 | sed 's/^Exec=//g' | xargs -n 1 echo 2>/dev/null | head -n 1)
REBASED_STARTUP=$(echo $STARTUP | sed -E -e "$PATCH_APP_PATH" -e "$PATCH_USR_PATH")
REBASED_STARTUP_RAW=$REBASED_STARTUP
PATCH_STARTUP="s#$REBASED_STARTUP#$LINGLONG_COMMAND#"
if [ ! -e "$REBASED_STARTUP" ]; then
if [ -e "$PREFIX/$REBASED_STARTUP" ]; then
REBASED_STARTUP="$PREFIX/$REBASED_STARTUP"
echo "Try $REBASED_STARTUP"
fi
if [ ! -e "$REBASED_STARTUP" ]; then
REBASED_STARTUP=$(find $PREFIX -type f -executable -name "$(basename "$REBASED_STARTUP")" | head -n1)
echo "Try $REBASED_STARTUP"
fi
if [ ! -e "$REBASED_STARTUP" ]; then
echo -e "\033[31mError: '$REBASED_STARTUP' does not exists." >&2
if [ -e "$STARTUP" ]; then
REBASED_STARTUP=$STARTUP
elif [ -e "/bin/$(basename $STARTUP)" ]; then
REBASED_STARTUP="/bin/$(basename $STARTUP)"
else
REBASED_STARTUP=$REBASED_STARTUP_RAW
fi
echo -e "\033[31mFallback '$REBASED_STARTUP' \033[0m"
fi
fi
if [ -z "$NO_PATCH_EXEC" ] && [ -z "$ENABLE_INSERT_EXEC_PTACH" ]; then
DESKTOP_NUM=$(ls $PREFIX/share/applications/*.desktop | wc -l)
if [ "$DESKTOP_NUM" -gt 1 ]; then
NO_PATCH_EXEC=1
ENABLE_INSERT_EXEC_PTACH=1
fi
fi
echo STARTUP: ${STARTUP}
echo REBASED_STARTUP: ${REBASED_STARTUP}
echo BOOT: ${LINGLONG_COMMAND}
sed -i -E $PREFIX/share/applications/*.desktop -e "/Exec=/ $PATCH_APP_PATH" -e "/Exec=/ $PATCH_USR_PATH" -e '/^\s*$/d' -e '/^#.*$/d' -e 's#^\s+##g' -e 's#\s*=\s*#=#'
if [ -z "$NO_PATCH_EXEC" ]; then
sed -i -E $PREFIX/share/applications/*.desktop -e "/Exec=/ $PATCH_STARTUP"
fi
if [ -n "$ENABLE_INSERT_EXEC_PTACH" ]; then
SHELL_CMD="${SHELL_CMD:- }"
sed -i -E $PREFIX/share/applications/*.desktop -e "/Exec=/ s#Exec=#Exec=$LINGLONG_COMMAND #g"
fi
perl -pe "s#/opt/(?!apps)#$PREFIX/opt/#g" -i $PREFIX/share/applications/*.desktop
if [ "$STARTUP" != "sh" ]; then
if od "$REBASED_STARTUP" -An -N2 -tx2 | grep -q "2123"; then
echo Patch Script: ${STARTUP}
sed -i -E -e "$PATCH_APP_PATH" "$REBASED_STARTUP"
perl -pe "s#/opt/(?!apps)#$PREFIX/opt/#g" -i "$REBASED_STARTUP"
if [ -n "$ENABLE_USR_PATCH" ]; then
sed -i -E -e "$PATCH_USR_PATH" "$REBASED_STARTUP"
fi
fi
fi
SHELL_CMD=${SHELL_CMD:-${REBASED_STARTUP}}
SHELL_EXEC=${SHELL_EXEC:-exec}
echo SHELL_CMD: $SHELL_CMD
echo SHELL_EXEC: $SHELL_EXEC
echo "${SHELL_EXEC:-exec} ${SHELL_CMD} \$@" >>$LINGLONG_COMMAND
chmod -v +x $LINGLONG_COMMAND
while read desktop; do
while read icon; do
found=$(find "$PREFIX/share/icons" -path "$PREFIX/share/icons/*/apps/*" \( -name "${icon}.png" -o -name "${icon}.svg" \) -print -quit)
if [ ! -e "$found" ]; then
log_error "$desktop: Icon not found: $icon"
fi
done <<<$(grep -oP "^Icon.*?=\K.*$" "$desktop")
done <<<$(find "$PREFIX/share/applications" -name "*.desktop")