PortableLinuxGames/pacman2appDir

255 lines
6.6 KiB
Plaintext
Raw Normal View History

2012-11-26 12:04:59 -08:00
#!/bin/bash
2012-12-22 01:54:04 -08:00
pg4l_dir=$(dirname $(readlink -f $0))
2012-12-22 01:14:34 -08:00
2013-02-21 16:00:44 -08:00
shopt -s extglob # Enable extended globs
2012-11-26 12:04:59 -08:00
case $(cat /etc/issue | head -n 1) in
Arch*)
find_dependencies_package() { pacman -Si $1 | egrep "Depends On" | grep -v None | cut -d: -f2; }
find_dependencies_file() { pacman -Qip $1 | egrep "Depends On" | grep -v None | cut -d: -f2; }
2013-02-20 16:13:31 -08:00
find_version_file() { v=$(pacman -Qip $1 | egrep "Version" | grep -v None | cut -d: -f2); echo ${v%-*}; }
2013-02-21 16:00:44 -08:00
find_file_for_package() { ls -1t /var/cache/pacman/pkg/$1-+([^-])-+([0-9])-+([^.]).pkg.tar.xz 2>/dev/null| head -n1; }
2012-11-26 12:04:59 -08:00
uncompress_package_file() { tar -xf $1; }
download_packages() { sudo pacman -Sw --noconfirm $@; }
;;
Ubuntu* | Debian*)
find_dependencies_package() { apt-get info $1; }
find_dependencies_file() { dpkg info $1; }
2013-02-20 16:13:31 -08:00
find_version_file() { v=$(pacman -Qip $1 | egrep "Version" | grep -v None | cut -d: -f2); echo ${v%-*}; }
2013-02-21 16:00:44 -08:00
find_file_for_package() { ls -1t /var/cache/pacman/pkg/$1-+([^-])-+([0-9])-+([^.]).pkg.tar.xz 2>/dev/null| head -n1; }
2012-11-26 12:04:59 -08:00
uncompress_package_file() { dpkg -d $1; }
download_packages() { apt-get download $@; }
;;
*)
echo "Distro not supported"
exit 1
;;
esac
2013-02-20 16:13:31 -08:00
DOWNLOAD=1
UNPACK=1
CLEANUP=1
BRINGUP=1
2012-11-26 12:04:59 -08:00
2013-02-20 16:13:31 -08:00
AUTOCOPYLIBS=
MainPackageExec=
MainPackageVersion=
pkgs=
files=
ignore="hicolor-icon-theme"
# Recolect list of packages
2012-11-26 12:04:59 -08:00
for i in $@; do
case $i in
2013-02-20 16:13:31 -08:00
--skip-download) DOWNLOAD=; shift ;;
--skip-unpack) UNPACK=; shift ;;
--skip-cleanup) CLEANUP=; shift ;;
--skip-bringup) BRINGUP=; shift ;;
--auto-copy-libs) AUTOCOPYLIBS=1; shift ;;
-*)
ignore+=" ${i#*-}"
2012-11-26 12:04:59 -08:00
;;
2013-02-20 16:13:31 -08:00
*)
if [ -f $i ]; then
# Argument is a file
files+=" $i"
pkgs+=" $(find_dependencies_file $i)"
else
# Argument is the name of a package
pkgs+=" $i"
pkgs+=" $(find_dependencies_package $i)"
fi
2012-11-26 12:04:59 -08:00
;;
esac
done
# Download and unpack packages
2013-02-20 16:13:31 -08:00
[ "$pkgs" -o "$files" ] || {
echo "Nothing to do";
exit 1;
}
2012-11-26 12:04:59 -08:00
[ "$files" ] && {
echo "These files will be included:"
for i in $files; do
echo " $i"
done
}
2013-02-23 08:26:25 -08:00
pkgs+=" xdg-utils"
2013-02-21 16:00:44 -08:00
[ "$pkgs" ] && {
for i in $ignore; do
echo "Ignoring $i..."
pkgs=${pkgs//$i/}
done
2013-02-20 16:13:31 -08:00
2013-02-21 16:00:44 -08:00
for i in $pkgs; do
pkgs=${pkgs//$i/${i%%[<>=]*}}
done
2013-02-20 16:13:31 -08:00
2013-02-21 16:00:44 -08:00
echo "These packages will be included:"
2013-02-20 16:13:31 -08:00
2013-02-21 16:00:44 -08:00
for i in $pkgs; do
echo " $i"
done
}
2012-11-26 12:04:59 -08:00
2013-02-21 16:00:44 -08:00
if [ "$DOWNLOAD" ]; then
2012-11-26 12:04:59 -08:00
# Make sure all packages are downloaded
download_packages $pkgs || exit
2013-02-21 16:00:44 -08:00
else
2013-02-20 16:13:31 -08:00
echo "Skipping download"
2013-02-21 16:00:44 -08:00
fi
2012-11-26 12:04:59 -08:00
2013-02-20 16:13:31 -08:00
# Find the file corresponding with each package
for i in $pkgs; do
f=$(find_file_for_package $i)
if [ -f "$f" ]; then
files+=" $f"
else
echo "!! Could not find file for package '$i'"
fi
done
[ "$files" ] || {
echo "!! No files found";
exit 1;
2012-11-26 12:04:59 -08:00
}
2013-02-20 16:13:31 -08:00
for i in $files; do
[ "$MainPackageVersion" ] || {
MainPackageVersion=$(find_version_file $i)
echo "Assuming main package is $i with version $MainPackageVersion"
}
done
2013-02-21 16:00:44 -08:00
if [ "$UNPACK" ]; then
2012-11-26 12:04:59 -08:00
for i in $files; do
echo "Uncompressing $i..."
uncompress_package_file $i
done
2013-02-21 16:00:44 -08:00
else
2013-02-20 16:13:31 -08:00
echo "Skipping unpack"
2013-02-21 16:00:44 -08:00
fi
2013-02-20 16:13:31 -08:00
2012-11-26 12:04:59 -08:00
2013-02-20 16:13:31 -08:00
[ "$BRINGUP" ] && {
2012-11-26 12:04:59 -08:00
for i in $(ls -1 usr/share/applications/*.desktop 2>/dev/null); do
2013-02-20 16:13:31 -08:00
PackageName=$(egrep Name $i | head -n1 | cut -d= -f2)
PackageExec=$(egrep Exec $i | head -n1 | cut -d= -f2)
PackageIcon=$(egrep Icon $i | head -n1 | cut -d= -f2)
2013-02-21 16:00:44 -08:00
echo "Found .desktop file '$PackageName' ($PackageExec)"
2013-02-20 16:13:31 -08:00
[ "$MainPackageExec" ] || {
2013-02-21 16:00:44 -08:00
echo " Using it as main program"
2013-02-23 08:26:25 -08:00
MainPackageExec=$(basename $PackageExec)
2013-02-20 16:13:31 -08:00
IconFile="./$PackageIcon"
[ -f "$IconFile" ] || IconFile=usr/share/pixmaps/$PackageIcon
2013-02-21 16:00:44 -08:00
[ -f "$IconFile" ] || IconFile=usr/share/icons/$PackageIcon
2013-02-23 08:26:25 -08:00
[ -f "$IconFile" ] || IconFile=$(ls -1 usr/share/pixmaps/${PackageIcon}.png 2>/dev/null | head -n1)
[ -f "$IconFile" ] || IconFile=$(ls -1 usr/share/icons/${PackageIcon}.png 2>/dev/null | head -n1)
[ -f "$IconFile" ] || IconFile=$(ls -1 usr/share/pixmaps/${PackageIcon}.* 2>/dev/null | head -n1)
[ -f "$IconFile" ] || IconFile=$(ls -1 usr/share/icons/${PackageIcon}.* 2>/dev/null | head -n1)
2013-02-21 16:00:44 -08:00
if [ -f "$IconFile" ]; then
2013-02-20 16:13:31 -08:00
echo "Using icon on $IconFile"
convert -resize 48x "$IconFile" AppRun.png
2013-02-23 08:26:25 -08:00
[ -f "AppRun-0.png" ] && {
mv -v AppRun-0.png AppRun.png
rm -v AppRun-?.png
}
2013-02-20 16:13:31 -08:00
optipng AppRun.png 2>/dev/null
2013-02-21 16:00:44 -08:00
else
2013-02-23 08:26:25 -08:00
echo "! Icon $PackageIcon not found" >&2
echo "usr/share/pixmaps:" >&2
find usr/share/pixmaps >&2
2013-02-21 16:00:44 -08:00
fi
2013-02-20 16:13:31 -08:00
}
[ -f "./$PackageExec" ] && {
echo "Patching absolute paths in ./$PackageExec"
sed -e "s/\/usr\//\.\/..\//g" ./$PackageExec -i
sed -e "s/\/opt\//\.\/..\//g" ./$PackageExec -i
}
[ -f AppRun.desktop ] || {
2013-02-23 08:26:25 -08:00
[ "$MainPackageVersion" ] || {
"! Main package version not found, using _VERSION_" >&2
MainPackageVersion=_VERSION_
}
2013-02-20 16:13:31 -08:00
echo "Creating AppRun.desktop from '$PackageName $MainPackageVersion' ($i, Exec=$PackageExec)..."
cp $pg4l_dir/AppRun.desktop .
sed -e"s/Name=.*/Name=$PackageName $MainPackageVersion-r1/" AppRun.desktop -i
}
2012-11-26 12:04:59 -08:00
done
2013-02-20 16:13:31 -08:00
[ -f AppRun ] || {
2013-02-23 08:26:25 -08:00
[ "$MainPackageExec" ] || {
echo "! Main package executable not found, using _BINARY_"
MainPackageExec="_BINARY_"
}
2013-02-20 16:13:31 -08:00
echo "Creating AppRun with Exec='${MainPackageExec}'..."
cp $pg4l_dir/AppRun .
sed -e"s/_BINARY_/$MainPackageExec/g" AppRun -i
chmod +x AppRun
}
rm -vf usr/bin/{ar,as,nm,gprof,elfedit,ld,ld.*,objcopy,objdump,makehrtf,c++filt,addr2line,curl,*-config,*-info,png2pnm,pnm2png,ranlib,readelf,size,strings,strip,wxrc*,xml2-config,xmlcatalog,xmllint,glewinfo,visualinfo,cjpeg,desktop-file-*,djpeg,jpegtran,lua,luac,rdjpgcom,update-desktop-database,wrjpgcom}
# Actually, patch'em all, for good measure.
sed -e "s/\/usr\//\.\/..\//g" usr/bin/* -i
sed -e "s/\/opt\//\.\/..\//g" usr/bin/* -i
echo "Possible missing libraries: (use --auto-copy-libs to copy them into usr/lib/)"
for i in $(LD_LIBRARY_PATH=$PWD/usr/lib/ ldd usr/bin/* \
| grep -v "$PWD" \
| grep -v "usr/bin/" \
| grep -v "not a dynamic executable" \
| grep -v "linux-gate.so" \
| grep -v "ld-linux.so" \
| grep -v "libc.so" \
| grep -v "libgcc_s.so" \
| grep -v "libstdc++.so" \
| grep -v "libm.so" \
| grep -v "libdl.so" \
| grep -v "librt.so" \
| grep -v "libdrm.so" \
| grep -v "libpthread.so" \
| grep -v "libxcb" \
| grep -v "libX" \
| cut -d" " -f3 | sort | uniq)
do
[ $AUTOCOPYLIBS ] && cp -v $i usr/lib/ || echo " $i"
done
} || {
echo "Skipping bringup"
2012-11-26 12:04:59 -08:00
}
2013-02-21 16:00:44 -08:00
if [ "$CLEANUP" ]; then
2013-02-23 08:26:25 -08:00
rubbish="etc usr/include usr/share/applications usr/share/desktop-directories usr/share/pixmaps usr/share/icons usr/share/man usr/share/info usr/share/doc usr/share/mime usr/share/aclocal usr/lib/pkgconfig usr/lib/*.a .INSTALL .PKGINFO"
2013-02-20 16:13:31 -08:00
for i in $rubbish; do
[ -e "$i" ] && {
echo "Deleting $i..."
rm -rf "$i"
}
done
2013-02-21 16:00:44 -08:00
else
2013-02-20 16:13:31 -08:00
echo "Skipping cleanup"
2013-02-21 16:00:44 -08:00
fi