|
|
|
#!/bin/sh
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
# A hacky script to generate .t?z files using satellites.
|
|
|
|
# It's a fairly simple wrapper to astronaut, that generates pkgtools packages.
|
|
|
|
|
|
|
|
# This may also serve as an example on how you can wrap astronaut to package in any format.
|
|
|
|
|
|
|
|
# Check whether we'll use fakeroot or not
|
|
|
|
_astronaut_wrapper_fakeroot="$(command -v fakeroot || true)"
|
|
|
|
[ "$_astronaut_wrapper_fakeroot" ] && _astronaut_wrapper_fakeroot='fakeroot'
|
|
|
|
|
|
|
|
if [ ! "$_astronaut_wrapper_fakeroot" -a "$(id -u)" != "0" ]; then
|
|
|
|
echo 'This script has to be run as root, or you need fakeroot installed.' 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Find astronaut
|
|
|
|
_astronaut="$(dirname "$0")/astronaut"
|
|
|
|
[ ! -f "$_astronaut" ] && _astronaut='astronaut'
|
|
|
|
|
|
|
|
# Configuration
|
|
|
|
dir_wrapper_pkgtools="$PWD" # Where the packages should be stored
|
|
|
|
|
|
|
|
# Wrapper functions
|
|
|
|
_astronaut_wrapper_pre() {
|
|
|
|
# Make sure to remove the contents of the install directory before building
|
|
|
|
_astronaut_nuke_install=true
|
|
|
|
}
|
|
|
|
|
|
|
|
_astronaut_wrapper_post() {
|
|
|
|
# Gzip man and info pages
|
|
|
|
if [ -d "$dir_install/$dir_prefix/$dir_man" ]; then
|
|
|
|
find "$dir_install/$dir_prefix/$dir_man" -type f -exec gzip -9 {} \;
|
|
|
|
for i in $(find "$dir_install/$dir_prefix/$dir_man" -type l); do ln -s "$(readlink "$i").gz" "$i.gz"; rm "$i"; done
|
|
|
|
fi
|
|
|
|
if [ -d "$dir_install/$dir_prefix/$dir_info" ]; then
|
|
|
|
rm -f "$dir_install/$dir_prefix/$dir_info/dir"
|
|
|
|
find "$dir_install/$dir_prefix/$dir_info" -type f -name '*.info' -exec gzip -9 '{}' \;
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Strip binaries
|
|
|
|
find "$dir_install" | xargs file | grep -e "executable" -e "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true
|
|
|
|
|
|
|
|
# Generate slack-desc for proper compliance, even if it's completely redundant
|
|
|
|
#mkdir -p "$dir_install/install"
|
|
|
|
#cat > "$dir_install/install/slack-desc" << EOF
|
|
|
|
## HOW TO EDIT THIS FILE:
|
|
|
|
## The "handy ruler" below makes it easier to edit a package description. Line
|
|
|
|
## up the first '|' above the ':' following the base package name, and the '|'
|
|
|
|
## on the right side marks the last column you can put a character in. You must
|
|
|
|
## make exactly 11 lines for the formatting to be correct. It's also
|
|
|
|
## customary to leave one space after the ':'.
|
|
|
|
|
|
|
|
#$(printf %$(printf '%s' "$name_sat" | wc -c)s)|-----handy-ruler------------------------------------------------------|
|
|
|
|
#$name_sat: $name_sat (Generated with astronautpkg)
|
|
|
|
#$name_sat:
|
|
|
|
#$name_sat:
|
|
|
|
#$name_sat:
|
|
|
|
#$name_sat:
|
|
|
|
#$name_sat:
|
|
|
|
#$name_sat:
|
|
|
|
#$name_sat:
|
|
|
|
#$name_sat:
|
|
|
|
#$name_sat:
|
|
|
|
#$name_sat:
|
|
|
|
#EOF
|
|
|
|
|
|
|
|
# Move configuration files to .new and install them for proper compliance.
|
|
|
|
if [ -d "$dir_install/$dir_prefix/$dir_sysconf" ]; then
|
|
|
|
mkdir -p "$dir_install/install"
|
|
|
|
cat >> "$dir_install/install/doinst.sh" << 'EOF'
|
|
|
|
config() {
|
|
|
|
NEW="$1"
|
|
|
|
OLD="$(dirname $NEW)/$(basename $NEW .new)"
|
|
|
|
# If there's no config file by that name, mv it over:
|
|
|
|
if [ ! -r $OLD ]; then
|
|
|
|
mv $NEW $OLD
|
|
|
|
elif [ "$(cat $OLD | md5sum)" = "$(cat $NEW | md5sum)" ]; then # toss the redundant copy
|
|
|
|
rm $NEW
|
|
|
|
fi
|
|
|
|
# Otherwise, we leave the .new copy for the admin to consider...
|
|
|
|
}
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
find "$dir_install/$dir_prefix/$dir_sysconf" -type f -printf '%P\n' | while IFS= read file; do
|
|
|
|
mv "$dir_install/$dir_prefix/$dir_sysconf/$file" "$dir_install/$dir_prefix/$dir_sysconf/$file.new"
|
|
|
|
echo "config '$dir_prefix/$dir_sysconf/$file.new'" >> "$dir_install/install/doinst.sh"
|
|
|
|
done
|
|
|
|
echo >> "$dir_install/install/doinst.sh"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Update desktop database if new files were added
|
|
|
|
if [ -d "$dir_install/$dir_prefix/$dir_data/applications" ]; then
|
|
|
|
mkdir -p "$dir_install/install"
|
|
|
|
cat >> "$dir_install/install/doinst.sh" << EOF
|
|
|
|
if [ -x /$dir_prefix/$dir_bin/update-desktop-database ]; then
|
|
|
|
/$dir_prefix/$dir_bin/update-desktop-database -q $dir_prefix/$dir_data/applications >/dev/null 2>&1
|
|
|
|
fi
|
|
|
|
|
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Update mime database if new files were added
|
|
|
|
if [ -d "$dir_install/$dir_prefix/$dir_data/mime" ]; then
|
|
|
|
mkdir -p "$dir_install/install"
|
|
|
|
cat >> "$dir_install/install/doinst.sh" << EOF
|
|
|
|
if [ -x /$dir_prefix/$dir_bin/update-mime-database ]; then
|
|
|
|
/$dir_prefix/$dir_bin/update-mime-database $dir_prefix/$dir_data/mime >/dev/null 2>&1
|
|
|
|
fi
|
|
|
|
|
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Update icon cache if new files were added
|
|
|
|
if [ -d "$dir_install/$dir_prefix/$dir_data/icons/hicolor" ]; then
|
|
|
|
mkdir -p "$dir_install/install"
|
|
|
|
cat >> "$dir_install/install/doinst.sh" << EOF
|
|
|
|
if [ -e $dir_prefix/$dir_data/icons/hicolor/icon-theme.cache ]; then
|
|
|
|
if [ -x /$dir_prefix/$dir_bin/gtk-update-icon-cache ]; then
|
|
|
|
/$dir_prefix/$dir_bin/gtk-update-icon-cache -f $dir_prefix/$dir_data/icons/hicolor >/dev/null 2>&1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Compile schemas if new files were added
|
|
|
|
if [ -d "$dir_install/$dir_prefix/$dir_data/glib-2.0/schemas" ]; then
|
|
|
|
mkdir -p "$dir_install/install"
|
|
|
|
cat >> "$dir_install/install/doinst.sh" << EOF
|
|
|
|
if [ -e $dir_prefix/$dir_data/glib-2.0/schemas ]; then
|
|
|
|
if [ -x /$dir_prefix/$dir_bin/glib-compile-schemas ]; then
|
|
|
|
/$dir_prefix/$dir_bin/glib-compile-schemas $dir_prefix/$dir_data/glib-2.0/schemas >/dev/null 2>&1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Query gio modules if new files were added
|
|
|
|
if [ -d "$dir_install/$dir_prefix/$dir_lib/gio/modules" ]; then
|
|
|
|
mkdir -p "$dir_install/install"
|
|
|
|
cat >> "$dir_install/install/doinst.sh" << EOF
|
|
|
|
chroot . /$dir_prefix/$dir_bin/gio-querymodules $dir_prefix/$dir_lib/gio/modules/ 1> /dev/null 2> /dev/null
|
|
|
|
|
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Install new info files if they were added
|
|
|
|
if [ -d "$dir_install/$dir_prefix/$dir_info" ]; then
|
|
|
|
mkdir -p "$dir_install/install"
|
|
|
|
echo "if [ -x /$dir_prefix/$dir_bin/install-info ]; then" >> "$dir_install/install/doinst.sh"
|
|
|
|
find "$dir_install/$dir_prefix/$dir_info" -type f -name '*.info.gz' -printf '%P\0' | while read -d '' -r file; do
|
|
|
|
echo " chroot . /$dir_prefix/$dir_bin/install-info --info-dir=/$dir_prefix/$dir_info /$file 2> /dev/null" >> "$dir_install/install/doinst.sh"
|
|
|
|
done
|
|
|
|
echo 'fi' >> "$dir_install/install/doinst.sh"
|
|
|
|
echo >> "$dir_install/install/doinst.sh"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Create the package
|
|
|
|
cd "$dir_install"
|
|
|
|
mkdir -p "$dir_wrapper_pkgtools"
|
|
|
|
PATH="$PATH:/sbin" $_astronaut_wrapper_fakeroot makepkg -l y -c n "$dir_wrapper_pkgtools/$name_sat-$(echo "$version" | tr - _)-$(uname -m)-astro.txz"
|
|
|
|
}
|
|
|
|
|
|
|
|
. "$_astronaut"
|