Skip to content

Instantly share code, notes, and snippets.

@ruario
Last active November 29, 2018 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruario/adb98d5cb269bbe8b71c33882f76ef32 to your computer and use it in GitHub Desktop.
Save ruario/adb98d5cb269bbe8b71c33882f76ef32 to your computer and use it in GitHub Desktop.
These scripts convert SpiderOak One and Semaphor deb packages into XZ compressed tar archives suitable for installing on any Linux distribution. The created packages include detailed instructions for both install and uninstall.

Scripts to make SpiderOak tar packages

These scripts convert SpiderOak One and Semaphor deb packages into XZ compressed tar archives suitable for installing on any Linux distribution. The created packages include detailed instructions for both install and uninstall.

Usage

Run the scripts by typing ./$scriptname followed by a version number (e.g. ./make_spideroakone_tar.sh 7.3.0 or ./make_semaphor_tar.sh 2.2.0).

Note: A .deb of the same version will need to be present in the working directory. In the case of ./make_spideroakone_tar.sh, the script will attempt to fetch the .deb from the public spideroakone apt repository, if it is not present locally.

Background

These scripts were created because the original “Slackware” package provided by SpiderOak for its One backup application was entirely unsuitable for Slackware. It was not a valid Slackware package due to the fact that it was not made by Slackware's own makepkg, which has tradtionally used a dedicated version of tar (with its own quirks). The package was also incorrectly named, contained no Slackware packaging meta data, and used the wrong paths for both doc and man page directories—Slackware uses “/usr/{doc,man}”, while other distributions conform to the FHS defined “/usr/share/man” and defacto standard “/usr/share/doc”. Attempting to install that package on Slackware would cause various “issues”. Furthermore users of other non-rpm/deb distributions believed it to be a generic install package but had no idea how to cleanly install and remove it.

The scripts provide a way to offer an alternative tar package for SpiderOak One and a brand new package for Semaphor (which did not provide a “Slackware package” previously). They do not attempt to be valid Slackware packages. Instead they are simply generic, distribution agnostic packages that can be used to cleanly install, upgrade and uninstall SpiderOak One or Semaphor, for use on non-deb/rpm distributions. Detailed instructions as to how to install, upgrade and remove SpiderOak One and Semaphor are included within their respective tar packages.

#!/bin/sh -eu
available () {
command -v "$1" >/dev/null 2>&1
}
# Take the version number as the first argument of the script
if [ -n "${1:-}" ]; then
VERSION="${1:-}"
else
# Try to work out the version number automatically based on most recent
# Semaphor .deb in the working directory
echo "No version number was supplied, we shall attempt to guess it" >&2
VERSION="$(ls -1 semaphor_*_1_amd64.deb 2>/dev/null | sort -V | tail -n 1 | cut -d_ -f2)"
fi
if [ -z "${VERSION:-}" ]; then
cat << VERROR >&2
A version number was not supplied and could not be guessed by looking for a
local Semaphor Debian package.
Supply the version number as the first argument to this script and save the
equivalent deb in the working directory.
VERROR
exit 1
fi
DEBNAME="semaphor_${VERSION}_1_amd64.deb"
DIRNAME="semaphor-$VERSION-x64"
TARNAME="$DIRNAME.tar.xz"
STAGING="semaphor-staging-$VERSION"
INSTALL_INSTRUCTIONS="INSTALL.txt"
UNINSTALL_INSTRUCTIONS="UNINSTALL.txt"
FILELIST="contents.bin"
INCDIRS="usr"
# If a local deb isn't present, exit
if [ ! -e "$DEBNAME" ]; then
echo "$DEBNAME is not present locally" >&2
exit 1
fi
if [ -d "$STAGING" ]; then
rm -r "$STAGING"
fi
mkdir -p "$STAGING/$DIRNAME"
echo "Extracting $DEBNAME ..."
# Check for 'ar' from binutils, if not available use a hack to open the .deb
if available ar; then
ar p "$DEBNAME" data.tar.xz | tar JxC "$STAGING/$DIRNAME"
else
tail -c+"$(grep -Fabom1 7zXZ "$DEBNAME" | cut -d: -f1)" "$DEBNAME" | tar JxC "$STAGING/$DIRNAME"
fi
cd "$STAGING/$DIRNAME"
DOCDIR="$(find usr/share/doc -maxdepth 1 -type d -iname semaphor)"
if [ -z "$DOCDIR" ]; then
echo "Could not find the Semaphor doc directory; exiting" >&2
exit 1
fi
# Remove this debian specific dirctory, if present
rm -fr usr/share/lintian
SEMAPHOR_DIRS="$(find usr -iname semaphor -type d -printf '\042/%p\042 ')"
cat <<END > "$INSTALL_INSTRUCTIONS"
To install, start a terminal in the directory containing this file and issue:
sudo cpio --owner root: -p0md / < $FILELIST
You may need to re-login to your desktop environment before Semaphor is
detected.
NOTE: Uninstall of the previous package should be performed before upgrading
to a newer version.
Uninstall directions: "/$DOCDIR/$UNINSTALL_INSTRUCTIONS"
---
This is a complete list of all the files included within this package:
END
cat <<END > "$DOCDIR/$UNINSTALL_INSTRUCTIONS"
To remove all installed 'files', issue the following command:
sudo xargs -0 rm -v < "/$DOCDIR/$FILELIST"
NOTE: Uninstall of the previous package should be performed before upgrading
to a newer version.
---
To completely remove any empty Semaphor specific directories following
uninstall, issue the following:
sudo find $SEMAPHOR_DIRS-depth -type d -empty -exec rmdir -v {} \;
END
find $INCDIRS ! -type d -printf '/%p\0' > "$FILELIST"
# make sure $FILELIST is the last item uninstalled
printf "/$DOCDIR/$FILELIST\0" >> "$FILELIST"
install -m644 "$FILELIST" "$DOCDIR/$FILELIST"
find $INCDIRS ! -type d -printf '/%p\n' >> "$INSTALL_INSTRUCTIONS"
# Overwrite $FILELIST with one suitable for install
find $INCDIRS ! -type d -print0 > "$FILELIST"
echo "Compressing $TARNAME ..."
cd ..
tar --owner 0 --group 0 -caf ../"$TARNAME" "$DIRNAME"
cd ..
rm -r "$STAGING"
#!/bin/sh -eu
available () {
command -v "$1" >/dev/null 2>&1
}
# Check if we have Wget or cURL
if available wget; then
SCRAPE="wget -qO-"; DOWNLOAD="wget"
elif available curl; then
SCRAPE="curl -s"; DOWNLOAD="curl -O"
else
SCRAPE="NONE"; DOWNLOAD="NONE"
fi
# Take the version number as the first argument of the script, or if not provided work it out from the apt repo.
if [ -n "${1:-}" ]; then
VERSION="${1:-}"
elif [ "$SCRAPE" != "NONE" ]; then
echo "No version number was supplied, we shall attempt to guess it" >&2
VERSION="$($SCRAPE https://apt.spideroak.com/ubuntu-spideroak-hardy/dists/release/restricted/binary-amd64/Packages.gz | zcat | grep -A1 -x 'Package: spideroakone' | sed -n 's/^Version: [0-9]\+:\(.*\)/\1/p' | sort -V)"
else
echo "Neither Wget nor cURL is installed, please supply the version as the first argument to this script." >&2
fi
if [ -z "${VERSION:-}" ]; then
echo "Version not supplied and could not be guessed by checking the apt repository; exiting" >&2
exit 1
fi
if [ -e "SpiderOakONE_${VERSION}_1_amd64.deb" ]; then
DEBNAME="SpiderOakONE_${VERSION}_1_amd64.deb"
else
DEBNAME="spideroakone_${VERSION}_amd64.deb"
fi
DIRNAME="spideroakone-$VERSION-x64"
TARNAME="$DIRNAME.tar.xz"
STAGING="spideroakone-staging-$VERSION"
INSTALL_INSTRUCTIONS="INSTALL.txt"
UNINSTALL_INSTRUCTIONS="UNINSTALL.txt"
FILELIST="contents.bin"
INCDIRS="etc/xdg opt usr"
# If a local deb isn't present, fetch it from the apt repo
if [ ! -e "$DEBNAME" ] && [ "$DOWNLOAD" != "NONE" ]; then
$DOWNLOAD "https://apt.spideroak.com/ubuntu-spideroak-hardy/pool/restricted/s/spideroakone/$DEBNAME"
elif [ ! -e "$DEBNAME" ]; then
echo "$DEBNAME is not present locally and could not be fetched because neither Wget nor cURL is installed" >&2
echo "Download https://apt.spideroak.com/ubuntu-spideroak-hardy/pool/restricted/s/spideroakone/$DEBNAME and re-run the script from the download location" >&2
exit 1
fi
if [ -d "$STAGING" ]; then
rm -r "$STAGING"
fi
mkdir -p "$STAGING/$DIRNAME"
echo "Extracting $DEBNAME ..."
# Check for 'ar' from binutils, if not available use a hack to open the .deb
if available ar; then
ar p "$DEBNAME" data.tar.xz | tar JxC "$STAGING/$DIRNAME"
else
tail -c+"$(grep -Fabom1 7zXZ "$DEBNAME" | cut -d: -f1)" "$DEBNAME" | tar JxC "$STAGING/$DIRNAME"
fi
cd "$STAGING/$DIRNAME"
DOCDIR="$(find usr/share/doc -maxdepth 1 -type d -iname spideroakone)"
if [ -z "$DOCDIR" ]; then
echo "Could not find the doc directory; exiting" >&2
exit 1
fi
SODIRS="$(find usr opt -iname spideroakone -type d -printf '\042/%p\042 ')"
cat <<END > "$INSTALL_INSTRUCTIONS"
To install, start a terminal in the directory containing this file and issue:
sudo cpio --owner root: -p0md / < $FILELIST
You may need to re-login to your desktop environment before Spider Oak One
is detected.
NOTE: Uninstall of the previous package should be performed before upgrading
to a newer version.
Uninstall directions: "/$DOCDIR/$UNINSTALL_INSTRUCTIONS"
---
This is a complete list of all the files included within this package:
END
cat <<END > "$DOCDIR/$UNINSTALL_INSTRUCTIONS"
To remove all installed 'files', issue the following command:
sudo xargs -0 rm -v < "/$DOCDIR/$FILELIST"
NOTE: Uninstall of the previous package should be performed before upgrading
to a newer version.
---
To completely remove any empty SpiderOak One specific directories following
uninstall, issue the following:
sudo find $SODIRS-depth -type d -empty -exec rmdir -v {} \;
END
find $INCDIRS ! -type d -printf '/%p\0' > "$FILELIST"
# make sure $FILELIST is the last item uninstalled
printf "/$DOCDIR/$FILELIST\0" >> "$FILELIST"
install -m644 "$FILELIST" "$DOCDIR/$FILELIST"
find $INCDIRS ! -type d -printf '/%p\n' >> "$INSTALL_INSTRUCTIONS"
# Overwrite $FILELIST with one suitable for install
find $INCDIRS ! -type d -print0 > "$FILELIST"
echo "Compressing $TARNAME ..."
cd ..
tar --owner 0 --group 0 -caf ../"$TARNAME" "$DIRNAME"
cd ..
rm -r "$STAGING"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment