Skip to content

Instantly share code, notes, and snippets.

@ruario
Last active September 27, 2021 20:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruario/f3ee61f574e2623691c938732aa31b55 to your computer and use it in GitHub Desktop.
Save ruario/f3ee61f574e2623691c938732aa31b55 to your computer and use it in GitHub Desktop.
This script will find the latest Skype for Linux binary package, download it and repackage it into Slackware format.
#!/bin/bash
# latest-skype Version 1.1.2
# This script will find the latest Skype binary package, download it and
# repackage it into Slackware format.
# Copyright 2018 Ruari Oedegaard, Oslo, Norway
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# Check if the user asked for auto-install
if [ "$1" = "-i" -o "$1" = "--install" ]; then
if [ "$UID" = "0" ]; then
AUTO_INSTALL=Y
else
echo "You must be root to auto-install, $1 ignored!" >&2
AUTO_INSTALL=N
fi
else
AUTO_INSTALL=N
fi
# Use the architecture of the current machine or whatever the user has
# set externally
ARCH=${ARCH:-$(uname -m)}
if [ ! "$ARCH" = "x86_64" ]; then
echo "The architecture $ARCH is not supported." >&2
exit 1
fi
# Work out the latest stable Skype if VERSION is unset
VERSION=${VERSION:-$(wget -qO- https://repo.skype.com/latest/skypeforlinux-64.rpm | head -c96 | strings | rev | awk -F"[:-]" '/xunilrofepyks/ { print $2 }' | rev)}
# Error out if $VERISON is unset, e.g. because previous command failed
if [ -z $VERSION ]; then
echo "Could not work out the latest version; exiting" >&2
exit 1
fi
# Don't start repackaging if the same version is already installed
if /bin/ls /var/log/packages/skypeforlinux-$VERSION-* >/dev/null 2>&1 ; then
echo "Skype ($VERSION) is already installed; exiting"
exit 0
fi
CWD="$PWD"
TMP=${TMP:-/tmp}
OUTPUT=${OUTPUT:-/tmp}
BUILD=${BUILD:-1}
TAG=${TAG:-ro}
PKGTYPE=${PKGTYPE:-tgz}
PACKAGE="$OUTPUT/skypeforlinux-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE"
# If the package was made previously, no need to make it again. ;)
if [ -e "$PACKAGE" ]; then
echo "$PACKAGE already exists; exiting"
exit 0
fi
REPACKDIR=$TMP/repackage-skype
# Define this script's name as we will copy into doc directory later on
SCRIPT="${0##*/}"
# This function can be used in place of Slackware's makepkg, with the
# added bonus that it is able to make packages with root owned files
# even when run as a regular user.
mkpkg() {
if [ "$1" = "-n" ]; then
TAROWNER=""
shift 1
else
TAROWNER="--group 0 --owner 0"
fi
if find * -type l | grep -qm1 .; then
mkdir -p install
find * -type l -printf '( cd %h ; rm -rf %f )\n( cd %h ; ln -sf %l %f )\n' -delete > install/symlinks
if [ -f "install/doinst.sh" ]; then
printf '\n' | cat - install/doinst.sh >> install/symlinks
fi
mv install/symlinks install/doinst.sh
fi
case "$1" in
*tbr) cmp="brotli --quality ${BROTLI_QUALITY:-5}" ;; # Experimental support for Brotli compression
*tbz)
if command -v lbzip2 >/dev/null 2>&1; then
cmp=lbzip2
else
cmp=bzip2
fi
;;
*tgz)
if command -v pigz >/dev/null 2>&1; then
cmp=pigz
else
cmp=gzip
fi
;;
*tlz) cmp=lzma ;;
*txz) cmp="xz -T0" ;;
*tz4) cmp=lz4 ;; # Experimental support for lz4 compression
*tzo) cmp=lzop ;; # Experimental support for lzop compression
*) echo "Unknown compression type" >&2 ; exit 1 ;;
esac
if [ -x /bin/tar-1.13 ]; then
tar-1.13 $TAROWNER -cvvf- . | $cmp > "$1"
else
tar cvvf - . --format gnu --xform 'sx^\./\(.\)x\1x' --show-stored-names $TAROWNER | $cmp > "$1"
fi
echo "Slackware package \"$1\" created."
}
# Since packaging is about to begin errors become more important now,
# so exit if things fail.
set -eu
# If the repackage is already present from the past, clear it down
# and re-create it.
if [ -d "$REPACKDIR" ]; then
rm -fr "$REPACKDIR"
fi
mkdir -p "$REPACKDIR"/{pkg/install,src}
# Save a copy if this script but remove execute persmissions as it will
# larer be moved into the doc directory.
install -m 644 "${0}" "$REPACKDIR/src/$SCRIPT"
# Fetch Skype
wget -P "$REPACKDIR/src" https://repo.skype.com/rpm/stable/skypeforlinux_$VERSION-1.x86_64.rpm
# Fetch 'skype-dbus-mock' https://github.com/maelnor/skype-dbus-mock
# More info: https://www.linuxquestions.org/questions/slackware-14/so-no-more-working-skype-for-slackware-15-the-older-versions-crash-because-the-new-glibc-the-newer-ones-needs-systemd-logind-4175638990/
DBUS_MOCK_COMMIT=3a9e2882ac5c0ad6be3c5cb5c7da008b4cfa51da # Setting a specific commit in case this repo changes drastically
wget -P "$REPACKDIR/src" https://github.com/maelnor/skype-dbus-mock/archive/$DBUS_MOCK_COMMIT.zip
# Extract the contents of the skype-dbus-mock package
cd "$REPACKDIR/src"
if [ -x /usr/bin/bsdtar ]; then
bsdtar xf $DBUS_MOCK_COMMIT.zip
elif [ -x /usr/bin/unzip ]; then
unzip -q $DBUS_MOCK_COMMIT.zip
else
echo "Either Libarchive (bsdtar) or InfoZip (unzip) needs to be installed to extract the skype-dbus-mock package" >&2
exit 1
fi
# Now we have all the sources in place, switch to the package directory
# and start setting things up.
cd "$REPACKDIR/pkg"
# Extract the contents of the Skype binary package
if [ -x /usr/bin/bsdtar ]; then
bsdtar xf ../src/skypeforlinux_$VERSION-1.x86_64.rpm
elif [ -x /usr/bin/rpm2cpio ]; then
rpm2cpio ../src/skypeforlinux_$VERSION-1.x86_64.rpm | cpio --quiet -id
else
# Since the user has not installed libarchive or rpm, use a hack to extract the rpm contents
RPMHDRLGTH=$(LANG=X grep -abom1 '.7zXZ\|BZh9\|'$'\037\213\b' ../src/skypeforlinux_$VERSION-1.x86_64.rpm)
case "$RPMHDRLGTH" in
*7zXZ) COMPRESSOR=xz ;;
*BZh9) COMPRESSOR=bzip2 ;;
*) COMPRESSOR=gzip ;;
esac
tail -c+$[${RPMHDRLGTH%:*}+1] ../src/src/skypeforlinux_$VERSION-1.x86_64.rpm | $COMPRESSOR -d | cpio --quiet -id
fi
# Install skype-dbus-mock
install -Dm644 ../src/skype-dbus-mock-$DBUS_MOCK_COMMIT/skype-dbus-mock.conf usr/share/dbus-1/system.d/skype-dbus-mock.conf
install -Dm644 ../src/skype-dbus-mock-$DBUS_MOCK_COMMIT/org.freedesktop.login1.service usr/share/dbus-1/system-services/org.freedesktop.login1.service
install -Dm755 ../src/skype-dbus-mock-$DBUS_MOCK_COMMIT/skype-dbus-mock.py usr/bin/skype-dbus-mock
# Move any doc directory to the correct Slackware location
if [ -d usr/share/doc ]; then
mv usr/share/doc usr/
find usr/doc -maxdepth 1 -type d -name "skypeforlinux*" -exec mv {} usr/doc/tmp \;
fi
mkdir -p usr/doc/tmp
mv usr/doc/tmp usr/doc/skypeforlinux-$VERSION
# Copy this script into the doc directory
cp ../src/$SCRIPT usr/doc/skypeforlinux-$VERSION/$SCRIPT
# Move the LICENSE(s) into place
(
cd usr/share/skypeforlinux
for l in LICENSE*; do
mv $l ../../doc/skypeforlinux-$VERSION
ln -fs ../../doc/skypeforlinux-$VERSION/$l $l
done
)
# Setting up this symlink in a non-standard (for Slackware) directory, so that
# "Help -> Third-Party Notices" works. The path is hardcoded :(
if [ -e "usr/doc/skypeforlinux-$VERSION/third-party_attributions.html" ]; then
mkdir -p usr/share/doc/skypeforlinux
(
cd usr/share/doc/skypeforlinux
ln -fs ../../doc/skypeforlinux-$VERSION/third-party_attributions.html third-party_attributions.html
)
fi
# Now create the post-install to register the desktop file and icons.
cat <<EOS> install/doinst.sh
# Setup menu entries
if command -v update-desktop-database >/dev/null 2>&1; then
update-desktop-database -q usr/share/applications
fi
# Setup icons
touch -c usr/share/icons/hicolor
if command -v gtk-update-icon-cache >/dev/null 2>&1; then
gtk-update-icon-cache -tq usr/share/icons/hicolor
fi
EOS
# Create a description file inside the package.
cat <<EOD> install/slack-desc
|-----handy-ruler------------------------------------------------------|
skypeforlinux: skypeforlinux (an instant messaging app)
skypeforlinux:
skypeforlinux: Skype is an instant messaging app that provides online text message
skypeforlinux: and video chat services. Users may transmit both text and video
skypeforlinux: messages and may exchange digital documents such as images, text, and
skypeforlinux: video. Skype allows video conference calls.
skypeforlinux:
skypeforlinux: Homepage: https://www.skype.com/
skypeforlinux:
skypeforlinux:
skypeforlinux:
EOD
# Make sure the file permissions are ok
# This should work and did before but now apparently fails :(
#chmod -R u+w,go+r-w,a-s .
find -L . \
\( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 \
-o -perm 511 \) -exec chmod 755 {} \; -o \
\( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \
-o -perm 440 -o -perm 400 \) -exec chmod 644 {} \;
# Create the Slackware package
mkpkg "$PACKAGE"
# Install if the user requested it
if [ $AUTO_INSTALL = "Y" ]; then
/sbin/upgradepkg --install-new "$PACKAGE"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment