Skip to content

Instantly share code, notes, and snippets.

@masato9000
Last active April 18, 2021 05:07
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save masato9000/be7f217a11b657e458f07e9801f146ee to your computer and use it in GitHub Desktop.
Save masato9000/be7f217a11b657e458f07e9801f146ee to your computer and use it in GitHub Desktop.
[OBSOLETE] Downloader/packager of flash plugins for XBPS-based systems (Void Linux)
#!/bin/sh
_bsdl='
Copyright (c) 2017, masato9000@users.noreply.github.com
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
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 OWNER OR CONTRIBUTORS 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.
'
adobeURL=https://fpdownload.adobe.com/pub/flashplayer/pdc/
conf_file=/var/db/flash-plugin-xbps/conf
build_dir="/var/tmp/flash-plugin-xbps.build"
# Filenames to download from adobe.com
arch=$(xbps-uhelper arch)
dl_n=flash_player_npapi_linux.$(echo $arch | sed 's/i686/i386/').tar.gz
dl_p=flash_player_ppapi_linux.$(echo $arch | sed 's/i686/i386/').tar.gz
# Locally-created package names
pkg_n=adobe-flash-local
pkg_p=pepper-flash-local
usage() {
if [ "$1"X = insX ]; then
echo "ERROR: Must be root to install packages"
exit 2
fi
[ "$1"X = unkX ] && echo "ERROR: Unknown options"
[ "$1"X = incX ] && echo "ERROR: Incompatible option combination"
echo "Usage:\t$_e OPTIONS"
echo "Download and package Adobe's Flash plugin for the XBPS Package Manager"
echo "\nOPTIONS:"
echo " -c\tCheck for current version and update the version config file"
echo "\tRequires write permissions to version config file"
echo "\tCannot be combined with -n, -p, or -i"
echo " -N\tUse with -c. If an update is available, send a notification to"
echo "\tto all users in Xorg sessions (requires libnotify)"
echo "\tUseful for running checks in a cron job"
echo " -P\tUse with -c. If an update is available, send a notification to"
echo "\tto all active console (TTY) and terminal (PTS/*) sessions"
echo "\tUseful for running checks in a cron job"
echo " -n\tDownload and package the NPAPI flash plugin matching the version"
echo "\tlisted in the version config file. (Mozilla-compatible browsers)"
echo "\tCannot be used with -p"
echo " -p\tDownload and package the PPAPI flash plugin matching the version"
echo "\tlisted in the version config file. (Chrome-compatible browsers)"
echo "\tCannot be used with -n"
echo " -i\tInstall the package after creation (requires root)"
exit 1
}
find_config() {
if [ -f $conf_file ]; then
if [ -w $conf_file ]; then
return 0
else
return 1
fi
else
return 255
fi
}
no_config() {
if [ "$1"X = roX ]; then
echo "ERROR: cannot write version config: $config_file"
echo "Please rerun as root"
exit 2
else
echo "ERROR: version config %s does not exist\n" "$config_file"
echo "Please run \"$_e -c\" to generate it"
exit 4
fi
}
gen_config() {
local _tempconf=
if [ $1X = 0X ]; then
_tmpconf=$(mktemp)
printf "npapi_ver=1.0.0\nppapi_ver=1.0.0%s" > $_tmpconf
install -D -m 644 $_tmpconf $conf_file
if [ $? -ne 0 ]; then
echo "ERROR: Failed to create version config file"
echo "\tMake sure you are root, or have write access to ${conf_file%/*}"
rm $_tmpconf
exit 2
fi
rm $_tmpconf
else
printf "npapi_ver=%s\nppapi_ver=%s\n" "$npapi_ver" "$ppapi_ver" > $conf_file
fi
return 0
}
check_ver() {
local _checkurl="https://get.adobe.com/flashplayer/about/" \
_npapi_upstr= _ppapi_upstr= _npapi_inst= _ppapi_inst= \
_updconf=0 _confexists= _versions=
find_config
_confexists=$?
# Initialize config if nonexistent
[ $_confexists -eq 255 ] && gen_config 0
# Complain and abort if we lack permission
[ $_confexists -eq 1 ] && no_config ro
. $conf_file
# Magic! if Adobe's "about" page changes, we'll need a new spell
_versions="$(curl "$_checkurl" 2>/dev/null |
awk '/^\s*$/{next}
/<td rowspan="3"><strong>Linux/{do_process=1; next}
/<td><strong>ChromeOS/{do_process=0}
/Firefox/{if (do_process == 1) {
do_npparse=1; next}
}
/Opera/{if (do_process == 1) {
do_ppparse=1; next}
}
{if (do_npparse == 1) {
do_npparse=0
split($0,a,"</*td>")
print a[2]}
}
{if (do_ppparse == 1) {
do_ppparse=0
split($0,a,"</*td>")
print a[2]}
}')"
if [ -z "$_versions" ]; then
echo "ERROR: Something is wrong with Flash \"About\" URL:\n$_checkurl"
echo "Please confirm URL, and if necessary, rewrite black magic"
exit 128
fi
_npapi_upstr=$(echo $_versions | awk '{print $1}')
_ppapi_upstr=$(echo $_versions | awk '{print $2}')
# Compare version config file and see if it needs updatint
xbps-uhelper cmpver $npapi_ver $_npapi_upstr
if [ $? -eq 255 ]; then
_updconf=1
npapi_ver=$_npapi_upstr
fi
xbps-uhelper cmpver $ppapi_ver $_ppapi_upstr
if [ $? -eq 255 ]; then
_updconf=1
ppapi_ver=$_ppapi_upstr
fi
[ $_updconf -eq 1 ] && gen_config
# Get installed versions for comparison
_npapi_inst=$(xbps-query -p pkgver $pkg_n |
sed 's/adobe-flash-local-//;s/_.*//')
[ -z "$_npapi_inst" ] && _npapi_inst=0
_ppapi_inst=$(xbps-query -p pkgver $pkg_p |
sed 's/pepper-flash-local-//;s/_.*//')
[ -z "$_ppapi_inst" ] && _ppapi_inst=0
xbps-uhelper cmpver $_npapi_inst $_npapi_upstr
if [ $? -eq 255 ]; then
if [ $_npapi_inst != 0 ]; then
np_upmsg="Adobe Flash Plugin (NPAPI): New version $_npapi_upstr available for download"
else
np_upmsg=
fi
fi
xbps-uhelper cmpver $_ppapi_inst $_ppapi_upstr
if [ $? -eq 255 ]; then
if [ $_ppapi_inst != 0 ]; then
pp_upmsg="Adobe Flash Plugin (PPAPI): New version $_ppapi_upstr available for download"
else
pp_upmsg=
fi
fi
if [ -n "$np_upmsg" ]; then
echo "$np_upmsg"
else
echo "NPAPI Flash: upstream version $_npapi_upstr"
fi
if [ -n "$pp_upmsg" ]; then
echo "$pp_upmsg"
else
echo "PPAPI Flash: upstream version $_ppapi_upstr"
fi
# Only use notification if there's an upgrade
if [ -n "$np_upmsg" -o -n "$pp_upmsg" ]; then
[ -n "$_optN" ] && notify_lnotify
[ -n "$_optP" ] && notify_console
fi
exit 0
}
notify_console() {
local _upmsg="\nBroadcast message from $(whoami)@$(hostname) ($(date))"
# wall for all TTY logins
echo "$np_upmsg\n$pp_upmsg" | wall
# print to all /dev/pts for terminal emulator windows without utmp
ls /dev/pts/[0-9]* | while read _pt; do
# Don't send to pts/x that are in utmp
who | grep pts/$(basename $_pt) > /dev/null && continue
echo "$_upmsg\n\n$np_upmsg\n$pp_upmsg" > $_pt
done
}
notify_lnotify() {
local _options="-i dialog-information -t 30000" _upmsg=
_upmsg="$(echo "Adobe Flash:\n\n$np_upmsg\n\n$pp_upmsg")"
who | grep \(:[0-9]*\) | sed 's/[()]//g' | awk '{print $1, $NF}' |
while read _user _display; do
DISPLAY=$_display su $_user -c "notify-send $_options \"$_upmsg\""
done
}
# Download and package
dl_flash() {
mkdir -p "$build_dir"
(
cd "$build_dir"
xbps-uhelper fetch "$adobeURL$ver/$dl>$pkg.tar.gz"
zcat "$pkg.tar.gz" | tar -x --no-same-owner
) || {
echo Error while extracting;
rm -r $build_dir;
exit 8;
}
}
mkflash() {
local _confexists= _flavor=$1
find_config
_confexists=$?
[ $_confexists -eq 255 ] && no_config
. $conf_file
if [ "$_flavor"X = npapiX ]; then
pkg=$pkg_n
ver=$npapi_ver
dl=$dl_n
desc="$desc_n"
conflicts="$conflicts_n"
elif [ "$_flavor"X = ppapiX ]; then
pkg=$pkg_p
ver=$ppapi_ver
dl=$dl_p
desc="$desc_p"
conflicts="$conflicts_p"
fi
destdir="$build_dir/$pkg"
dl_flash
if [ "$_flavor"X = npapiX ]; then
inst_flash_n
elif [ "$_flavor"X = ppapiX ]; then
inst_flash_p
fi
pkg_flash
}
inst_flash_n() {
echo "Installing files to $destdir.."
mkdir -p "$destdir"
install -D -m 755 -t $destdir/usr/lib/mozilla/plugins \
$build_dir/libflashplayer.so
install -D -m 755 -t $destdir/usr/bin \
$build_dir/usr/bin/flash-player-properties
install -D -m 644 -t $destdir/usr/share/applications \
$build_dir/usr/share/applications/flash-player-properties.desktop
install -D -m 644 -t $destdir/usr/share/kde4/services \
$build_dir/usr/share/kde4/services/kcm_adobe_flash_player.desktop
install -D -m 644 -t $destdir/usr/share/licenses/$pkg \
$build_dir/license.pdf
for _i in 16x16 22x22 24x24 32x32 48x48; do
install -D -m 644 -t $destdir/usr/share/icons/hicolor/$_i/apps \
$build_dir/usr/share/icons/hicolor/$_i/apps/flash-player-properties.png
done
if [ "$arch"X = x86_64X ]; then
install -D -m 755 -t $destdir/usr/lib/kde4 \
$build_dir/usr/lib64/kde4/kcm_adobe_flash_player.so
else
install -D -m 755 -t $destdir/usr/lib/kde4 \
$build_dir/usr/lib/kde4/kcm_adobe_flash_player.so
fi
}
inst_flash_p() {
local _export_line="export CHROME_FLAGS=\"--ppapi-flash-path=/usr/lib/pepper-flash-local/libpepflashplayer.so --ppapi-flash-version=${ver}\"\n"
echo "Installing files to $destdir.."
mkdir -p "$destdir"
install -D -m 644 -t $destdir/usr/lib/$pkg \
$build_dir/libpepflashplayer.so
install -D -m 644 -t $destdir/usr/lib/$pkg \
$build_dir/manifest.json
install -D -m 644 -t $destdir/usr/share/licenses/$pkg \
$build_dir/license.pdf
ln -s /usr/lib/$pkg/ $destdir/usr/lib/PepperFlash
printf "$_export_line" > $build_dir/pepper-flash.sh
install -D -m 644 -t $destdir/etc/profile.d \
$build_dir/pepper-flash.sh
}
pkg_flash() {
echo "Packaging: ${pkg}-${ver}_1.${arch}.xbps.."
# Prepare install message
printf -- "$nodistribute" | sed "s/PKGNAME/$pkg/g" > $destdir/INSTALL.msg
xbps-create --architecture $arch \
--homepage "$homepage" \
--license "$license" \
--maintainer "$maintainer" \
--desc "$desc" \
--pkgver "${pkg}-${ver}_1" \
--conflicts "$conflicts" \
--compression xz \
--quiet $destdir
rm -r $build_dir
if [ -n "$_opti" ]; then
echo y | xdowngrade ${pkg}-${ver}_1.${arch}.xbps
fi
echo ..Done
exit 0
}
_e=${0##*/}
nodistribute="-The Adobe Flashplayer plugin is licensed software.
\tYou MUST read and agree to the license stored in
\t/usr/share/licenses/PKGNAME/license.pdf
\tbefore using it.
\tYou MUST NOT REDISTRIBUTE the PKGNAME package
\texcept in compliance with the provisions set forth in
\tthe aforementioned license.
"
desc_n="Adobe Flash Player plugin (NPAPI) for Mozilla-compatible browsers"
desc_p="Adobe Flash Player plugin (PPAPI) for Chromium-based browsers"
homepage="https://www.adobe.com/products/flashplayer.html"
license="Adobe License (non free)"
maintainer="Local <root@$(hostname)>"
conflicts_n="freshplayerplugin adobe-flash-plugin"
conflicts_p="chromium-pepper-flash"
# parse args
unset optc optN optP optn optp opti
while getopts cNPnpi _opts 2>/dev/null; do
case $_opts in
c) # Check for new version
_optc=check
;;
N) # Notify via libnotify
_optN=notify
_optc=check
;;
P) # Notify TTY/PTS
_optP=notify
_optc=check
;;
n) # Build NPAPI package
_optn=npapi
;;
p) # Build PPAPI package
_optp=ppapi
;;
i) # Install after build
_opti=install
;;
*)
usage unk
;;
esac
done
# Select actions based on arguments
if [ -n "$_optc" ]; then
# Check does not combine with any other option
[ -n "$_optn" -o -n "$_optp" -o -n "$_opti" ] && usage inc
check_ver
fi
if [ -n "$_opti" ]; then
_id=$(id -u)
# Nonroot can't install packages
[ $_id -ne 0 ] && usage ins
fi
if [ -n "$_optn" ]; then
# Build one or the other
[ -n "$_optp" ] && usage inc
mkflash $_optn
elif [ -n "$_optp" ]; then
mkflash $_optp
fi
# fallthrough - no action selected
usage
@masato9000
Copy link
Author

flash-plugin-xbps

script to download and package Adobe's flash plugin for xbps-based systems (Void Linux)

Features

  • Supports downloading and packaging of both NPAPI and PPAPI varieties
  • Checks Adobe's website for new versions and can send notifications of available updates to console sessions as well as X sessions (through libnotify). This allows it to be useful as a scheduled job to automatically check for updates.
  • Much, much more (not really, that's about it)

Requirements

  • Xbps-based Linux system (duh).
  • Adobe's flash plugin is only available for glibc-based x86 architectures (32- and 64-bit).
  • libnotify and a running dbus instance is needed for support of sending notifications to X sessions.

@masato9000
Copy link
Author

bugfix (20170618)

  • install option didn't work due to typo (bad variable name in test)
  • libnotify didn't work from cron due to bad assumption about the output of who

@masato9000
Copy link
Author

bugfix (20171031)

  • fixed hardcoded version number in shell snippet... duh

@masato9000
Copy link
Author

Requiem Aeternam
It fought the good fight and now deserves peace.

Goodbye Flash. (and don't let the door hit your...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment