PortableLinuxGames/lgp2appImage

206 lines
5.3 KiB
Bash
Executable File

#!/bin/bash
# Author : Ismael Barros² <ismael@barros2.org>
# 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