forked from RazZziel/PortableLinuxGames
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lgp2appImage
executable file
·205 lines (169 loc) · 5.35 KB
/
lgp2appImage
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
#!/bin/bash
# Author : Ismael Barros² <[email protected]>
# License : BSD http://en.wikipedia.org/wiki/BSD_license
pg4l_dir=$(dirname $(readlink -f $0))
. "$pg4l_dir/util.sh"
OIFS=$IFS
NIFS=$'\n'
[ -z "$*" ] && {
echo "Usage: "
echo " $0 <lgp_installer.run> [options]"
echo "Options:"
echo " --skip-extract: Skip extract of the makeself package"
echo " --skip-cleanup: Skip cleanup of temporal directories"
echo " --skip-appimage: Skip creation of AppImage"
echo " --lgp-unpacker: Use lgp installer to extract the package data"
exit
}
EXTRACT=1
CLEANUP=1
APPIMAGE=1
USE_LGP_UNPACKER=
for i in $@; do
case $i in
--skip-extract) EXTRACT=; shift ;;
--skip-cleanup) CLEANUP=; shift ;;
--skip-appimage) APPIMAGE=; shift ;;
--lgp-unpacker) USE_LGP_UNPACKER=1; shift ;;
*) pkg=$i; shift ;;
esac
done
[ -n "$pkg" ] || die "No lgp installer specified"
target="$PWD/${pkg}_uncompressed"
appDirPath="$PWD/${pkg}.AppDir"
installScript=$(sh "$pkg" --info | tail -n2 | head -n1 | trimp)
[ -n "$installScript" ] || die "Could not find 'install script'"
if [ $EXTRACT ]; then
sh "$pkg" --noexec --target "$target" || die "Could not unpack package"
fi
cd "$target" || exit 1
# Removing useless setup.xml's
find -name lgp_update -type d -exec rm -rvf {} +
find -name lgp_uninstall -type d -exec rm -rvf {} +
configFile="$(find -iname setup.xml)"
[ -n "$configFile" ] || die "Could not find config file"
configDir=$(dirname $(dirname $configFile))
cd "$configDir" || die "Directory $configDir doesn't exist"
configFile="$(find -iname setup.xml)"
[ -n "$configFile" ] || die "Could not find setup.xml"
# Find package name
IFS=$NIFS
for configBinLine in $(xml_extract_node "install" "$configFile"); do
configBinLine=$(trim "$configBinLine")
echo _$configBinLine
case "$configBinLine" in
"<install"*)
packageName=$(xml_extract_property desc "$configBinLine")
;;
*) ;;
esac
done
IFS=$OIFS
[ -n "$packageName" ] || die "Could not find package name"
echo "Package name: $packageName"
# Find binaries
binaries=
main=
IFS=$NIFS
for configBinLine in $(xml_extract_node "binary" "$configFile"); do
configBinLine=$(trim "$configBinLine")
case "$configBinLine" in
"<binary"*)
filename=$(xml_extract_property symlink "$configBinLine")
[ $filename ] || continue
play=$(xml_extract_property play "$configBinLine")
if [ "$play" = "yes" ]; then
main=1
binIconName=$(xml_extract_property icon "$configBinLine")
iconPath=$(find -iname "$binIconName" | head -n1)
echo "Main binary: '$filename' with icon '$binIconName'"
fi
;;
"</binary>") ;;
*)
binPath="bin/Linux/x86/$configBinLine"
[ -f "$binPath" ] || die "$binPath does not exist"
echo "Adding binary $binPath"
binaries+=" $configBinLine"
if [ $main ]; then
binFilename="$configBinLine"
main=
fi
;;
esac
done
IFS=$OIFS
[ -n "$binFilename" ] || die "Could not find binary name"
[ -n "$binIconName" ] || die "Could not find icon name"
[ -n "$iconPath" ] || die "Could not find icon path"
if [ $USE_LGP_UNPACKER ]; then
cd "$target"
binDir="$PWD/_BIN_"
option="lololoki"
echo "Running $installScript ..."
./$installScript -v 0 -i "$appDirPath" -b "$binDir" -o "$option"
reset # Just in case lgp installer fucks shit up
else
mkdir -p "$appDirPath"
IFS=$NIFS
for i in $(xml_extract_node "files" "$configFile" | grep -v "<files" | grep -v "</files>"); do
i=$(echo "$i" | sed -e "s/\*//g")
i=$(trim "$i")
echo "Installing file '$i' ..."
case "$i" in
*.tar*)
tar -xvf "$i" -C "$appDirPath" || die "Could not extract $i" || die
;;
*)
if [ -f "$i" ]; then
install -Dv "$i" "$appDirPath/$i" || die "Could not copy $i" || die
elif [ -d "$i" ]; then
mkdir -p "$appDirPath/$i"
cp -a "$i"/* "$appDirPath/$i"/ || die "Could not copy $i" || die
else
die "Don't know what to do with '$i'"
fi
;;
esac
done
IFS=$OIFS
for i in $binaries; do
echo "Installing binary '$i' ..."
install -Dv "bin/Linux/x86/$i" "$appDirPath/$i" || die "Could not copy binary $i" || die
chmod a+x "$appDirPath/$i"
done
fi
#pushd "$appDirPath"
#realBinFilename=$(find -name "$binFilename" -type f -perm /a+x)
#[ -n "$realBinFilename" ] || die "Could not find real binary path for '$binFilename'"
#popd
convert -resize 32x "$iconPath" "$appDirPath"/AppRun.png || die "Could not copy icon"
[ -f "AppRun-0.png" ] && {
mv -v AppRun-0.png AppRun.png
rm -v AppRun-?.png
}
optipng "$appDirPath"/AppRun.png >/dev/null
cd "$appDirPath"
cp $pg4l_dir/data/AppRun.desktop .
Suffix=-lgp
desktopFile_setParameter "AppRun.desktop" "Name" "$packageName r1$Suffix"
desktopFile_setParameter "AppRun.desktop" "X-AppImage-Release" "1"
desktopFile_setParameter "AppRun.desktop" "X-AppImage-SourcePackages" "$(basename "$pkg")"
desktopFile_setParameter "AppRun.desktop" "X-AppImage-Tags" "LGP"
echo "Creating AppRun with Exec='$binFilename'..."
echo '#!/bin/bash' > AppRun
echo 'cd $(dirname "$(readlink -f "$0")")' >> AppRun
#for i in $(for i in $(find -iname *.so*); do dirname "$i"; done | sort | uniq); do
# echo "export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:$i" >> AppRun
#done
echo "./$binFilename" >> AppRun
chmod +x AppRun
if [ $APPIMAGE ]; then
$pg4l_dir/buildAppImage || die "Could not build AppImage"
fi
if [ $CLEANUP ]; then
echo "Removing $target"
rm -rf "$target"
echo "Removing $appDirPath"
rm -rf "$appDirPath"
fi