-
Notifications
You must be signed in to change notification settings - Fork 9
/
nix2appImage
executable file
·131 lines (103 loc) · 3.83 KB
/
nix2appImage
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
#!/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 " --no-lgp-unpacker: Don't use nix installer to extract the package data"
exit
}
EXTRACT=1
CLEANUP=1
APPIMAGE=1
USE_NIX_UNPACKER=1
for i in $@; do
case $i in
--skip-extract) EXTRACT=; shift ;;
--skip-cleanup) CLEANUP=; shift ;;
--skip-appimage) APPIMAGE=; shift ;;
--lgp-unpacker) USE_NIX_UNPACKER=; shift ;;
*) pkg=$i; shift ;;
esac
done
[ -n "$pkg" ] || die "No lgp installer specified"
target="$PWD/${pkg}_uncompressed"
appDirPath="$PWD/${pkg}.AppDir"
if [ "$USE_NIX_UNPACKER" ]; then
if [ $EXTRACT ]; then
echo "Installing $pkg on $appDirPath ..."
sh "$pkg" -u --accept-license -d "$appDirPath" || die "Could not extract package"
fi
cd "$appDirPath" || exit 1
# Find package name and version
uninstallScript="$(find -iname uninstall.sh)"
packageName=$(desktopFile_getParameter "$uninstallScript" PROGNAME)
packageVersion=$(desktopFile_getParameter "$uninstallScript" PROGVER)
else
if [ $EXTRACT ]; then
sh "$pkg" --noexec --target "$target" || die "Could not unpack package"
fi
cd "$target" || exit 1
configFile="$(find -iname config.lua)"
[ -n "$configFile" ] || die "Could not find config file"
# Find package name and version
packageName=$(desktopFile_getParameter ??? "$configFile")
packageVersion=$(desktopFile_getParameter ??? "$configFile")
mkdir -p "$appDirPath"
for i in instarchive_all instarchive_all_x86; do
echo "Unpacking file '$i' ..."
tar -xJvf "$i" -C "$appDirPath" || die "Could not extract $i" || die
done
fi
cd "$appDirPath" || exit 1
[ -n "$packageName" ] || die "Could not find package name"
[ -n "$packageVersion" ] || die "Could not find package version"
echo "Package: $packageName $packageVersion"
desktopFile="$(find -iname "*.desktop" | grep -v AppRun.desktop | grep -v Manual | head -n1)"
echo $desktopFile
[ -n "$desktopFile" ] || die "Could not find desktop file"
binFilename=$(desktopFile_getParameter "$desktopFile" Exec)
[ -n "$binFilename" ] && binFilename=$(find -name $(basename $binFilename))
[ -n "$binFilename" ] || die "Could not find binary name"
iconPath=$(desktopFile_getParameter "$desktopFile" Icon)
[ -n "$iconPath" ] || die "Could not find icon path"
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 .
cp $pg4l_dir/util.sh .
Suffix=-nix
desktopFile_setParameter "AppRun.desktop" "Name" "$packageName r1$Suffix"
desktopFile_setParameter "AppRun.desktop" "X-AppImage-Version" "$packageVersion"
desktopFile_setParameter "AppRun.desktop" "X-AppImage-Release" "1"
desktopFile_setParameter "AppRun.desktop" "X-AppImage-SourcePackages" "$(basename "$pkg")"
desktopFile_setParameter "AppRun.desktop" "X-AppImage-Tags" "NIX"
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