s243a

pepperflashplugin-nonfree_1.3

Apr 17th, 2016
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 8.43 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # Copyright (C) 2006-2013 Bart Martens <bartm@knars.be>
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17.  
  18. set -e
  19.  
  20. return_0() {
  21.     return 0
  22. }
  23.  
  24. trap "return_0" 0
  25.  
  26. die_hard() {
  27.     echo "ERROR: $1" >&2
  28.     echo "More information might be available at:" >&2
  29.     echo "  http://wiki.debian.org/PepperFlashPlayer" >&2
  30.     exit 1
  31. }
  32.  
  33. [ `whoami` = "root" ] || die_hard "must be root"
  34.  
  35. show_usage() {
  36.     echo "Usage:"
  37.     echo "  update-pepperflashplugin-nonfree --install"
  38.     echo "  update-pepperflashplugin-nonfree --uninstall"
  39.     echo "  update-pepperflashplugin-nonfree --status"
  40.     echo "Additional options:"
  41.     echo "  --verbose"
  42.     echo "  --quiet"
  43.     exit 1
  44. }
  45.  
  46. getopt_temp=`getopt -o iusfvq --long install,uninstall,status,fast,verbose,quiet,beta,unstable,unverified \
  47.     -n 'update-pepperflashplugin-nonfree' -- "$@"` || show_usage
  48. eval set -- "$getopt_temp" || show_usage
  49.  
  50. ACTION=none
  51. fast=no
  52. verbose=no
  53. quiet=no
  54. variant=stable
  55. verified=yes
  56.  
  57. while [ true ]
  58. do
  59.     case "$1" in
  60.         -i|--install)
  61.             ACTION="--install"
  62.             shift
  63.             ;;
  64.         -u|--uninstall)
  65.             ACTION="--uninstall"
  66.             shift
  67.             ;;
  68.         -s|--status)
  69.             ACTION="--status"
  70.             shift
  71.             ;;
  72.         -f|--fast)
  73.             fast=yes
  74.             shift
  75.             ;;
  76.         -v|--verbose)
  77.             verbose=yes
  78.             shift
  79.             ;;
  80.         -q|--quiet)
  81.             quiet=yes
  82.             shift
  83.             ;;
  84.         --beta)
  85.             variant=beta
  86.             shift
  87.             ;;
  88.         --unstable)
  89.             variant=unstable
  90.             shift
  91.             ;;
  92.         --unverified)
  93.             verified=no
  94.             shift
  95.             ;;
  96.         --)
  97.             shift
  98.             break
  99.             ;;
  100.         *)
  101.             echo "Internal error!"
  102.             exit 1
  103.             ;;
  104.     esac
  105. done
  106.  
  107. [ "$ACTION" != "none" -a $# -eq 0 ] || show_usage
  108. [ "$quiet" != "yes" ] || verbose=no
  109.  
  110. [ "$verbose" != "yes" ] || echo "options : $getopt_temp"
  111.  
  112. latestfile=latest-$variant-verified.txt
  113. [ "$verified" != "no" ] || latestfile=latest-$variant.txt
  114.  
  115. UNPACKDIR=`mktemp -d /tmp/pepperflashplugin-nonfree.XXXXXXXXXX` || die_hard "mktemp failed"
  116. echo "$UNPACKDIR" | grep -q "^/tmp/pepperflashplugin-nonfree\." || die_hard "paranoia"
  117. cd "$UNPACKDIR" || die_hard "cd failed"
  118.  
  119. [ "$verbose" != "yes" ] || echo "temporary directory: $UNPACKDIR"
  120.  
  121. do_cleanup() {
  122.     [ "$verbose" != "yes" ] || echo "cleaning up temporary directory $UNPACKDIR ..."
  123.     cd /
  124.     echo "$UNPACKDIR" | grep -q "^/tmp/pepperflashplugin-nonfree\." || die_hard "paranoia"
  125.     rm -rf "$UNPACKDIR"
  126. }
  127.  
  128. die_hard_with_a_cleanup() {
  129.     return_0
  130.     do_cleanup
  131.     die_hard "$1"
  132. }
  133.  
  134. trap "die_hard_with_a_cleanup interrupted" INT
  135.  
  136. cachedir=/var/cache/pepperflashplugin-nonfree
  137.  
  138. wgetquiet=' -q '
  139. wgetfast='-t 3 -T 15 '
  140. wgetalways=' -nd -P . '
  141. wgetprogress=' -v --progress=dot:default '
  142.  
  143. if [ "$ACTION" = "--install" -o "$ACTION" = "--status" ]
  144. then
  145.     installed=`strings /usr/lib/pepperflashplugin-nonfree/libpepflashplayer.so 2> /dev/null | grep LNX | cut -d ' ' -f 2 | sed -e "s/,/./g"`
  146.  
  147.     if [ -f $cachedir/$latestfile ]
  148.     then
  149.         chromeversion=`head -n 1 $cachedir/$latestfile`
  150.         flashversion=`tail -n 1 $cachedir/$latestfile`
  151.     else
  152.         chromeversion=0
  153.         flashversion=0
  154.     fi
  155.  
  156.     mkdir -p var/lib/apt/lists var/cache/apt/archives etc/apt/apt.conf.d etc/apt/preferences.d
  157.  
  158.     cat > apt.conf <<-EOF
  159.     Dir ".";
  160.     Dir::Etc::trusted "pubring.gpg";
  161.     Debug::NoLocking "true";
  162.     EOF
  163.  
  164.     arch=`dpkg --print-architecture`
  165.  
  166.     cat > etc/apt/sources.list <<-EOF
  167.     deb [arch=$arch] http://dl.google.com/linux/chrome/deb/ stable main
  168.     EOF
  169.  
  170.     gpg --quiet --no-permission-warning --homedir "etc/apt" --import /usr/lib/pepperflashplugin-nonfree/pubkey-google.txt
  171.  
  172.     [ "$verbose" != "yes" ] || echo "doing apt-get update on google repository"
  173.     stdouterr=`APT_CONFIG=apt.conf apt-get --quiet --quiet update 2>&1`
  174.     [ "$stdouterr" = "" ] || die_hard_with_a_cleanup "failed to retrieve status information from google : $stdouterr"
  175.  
  176.     newchromeversion=`APT_CONFIG=apt.conf apt-cache show google-chrome-$variant | grep "^Version: " | sed -e "s,^Version: ,,"`
  177.     poolfile=`APT_CONFIG=apt.conf apt-cache show google-chrome-$variant | grep "^Filename: " | sed -e "s,^Filename: ,,"`
  178.     deburl="http://dl.google.com/linux/chrome/deb/$poolfile"
  179.     debfile=`echo $poolfile|sed -e "s,.*/,,"`
  180.     debsize=`APT_CONFIG=apt.conf apt-cache show google-chrome-$variant | grep "^Size: " | sed -e "s,^Size: ,,"`
  181.     debsha1=`APT_CONFIG=apt.conf apt-cache show google-chrome-$variant | grep "^SHA1: " | sed -e "s,^SHA1: ,,"`
  182.     debmd5=`APT_CONFIG=apt.conf apt-cache show google-chrome-$variant | grep "^MD5sum: " | sed -e "s,^MD5sum: ,,"`
  183.  
  184.     if [ "$chromeversion" = "$newchromeversion" ]
  185.     then
  186.         upstream=$flashversion
  187.     else
  188.         downloadurl="http://people.debian.org/~bartm/pepperflashplugin-nonfree/$latestfile"
  189.         wgetoptions="$wgetquiet $wgetalways"
  190.         [ "$fast" != "yes" ] || wgetoptions="$wgetoptions $wgetfast"
  191.  
  192.         [ "$verbose" != "yes" ] || echo "downloading $downloadurl"
  193.         HOME=/root wget $wgetoptions $downloadurl || die_hard_with_a_cleanup "wget failed to download $downloadurl"
  194.  
  195.         mv $latestfile $cachedir
  196.  
  197.         chromeversion=`head -n 1 $cachedir/$latestfile`
  198.         flashversion=`tail -n 1 $cachedir/$latestfile`
  199.  
  200.         upstream=$flashversion
  201.     fi
  202. fi
  203.  
  204. case "$ACTION" in
  205.  
  206.     --install)
  207.         [ "$verbose" != "yes" ] || echo "selected action = $ACTION"
  208.  
  209.         [ "$upstream" != "" ] || die_hard_with_a_cleanup "failed to determine upstream version"
  210.  
  211.         if [ "$installed" != "" -a "$upstream" != "" -a "$installed" = "$upstream" ]
  212.         then
  213.  
  214.             [ "$verbose" != "yes" ] || echo "upstream version $upstream is already installed"
  215.  
  216.         else
  217.  
  218.             if [ -f $cachedir/$debfile ]
  219.             then
  220.                 cp -p $cachedir/$debfile .
  221.             fi
  222.    
  223.             if [ ! -f $debfile ]
  224.             then
  225.                 wgetoptions="$wgetalways $wgetprogress"
  226.                 [ "$quiet" != "yes" ] || wgetoptions="$wgetquiet $wgetalways"
  227.                 [ "$fast" != "yes" ] || wgetoptions="$wgetoptions $wgetfast"
  228.                 wgetoptions="$wgetoptions -O $UNPACKDIR/$debfile" # to change wget message : Saving to ...
  229.    
  230.                 HOME=/root wget $wgetoptions $deburl || die_hard_with_a_cleanup "wget failed to download $deburl"
  231.    
  232.                 [ `stat --format=%s $debfile` = "$debsize" ] || die_hard_with_a_cleanup "rejecting $debfile : wrong size"
  233.                 [ `sha1sum $debfile|sed -e "s, .*,,"` = "$debsha1" ] || die_hard_with_a_cleanup "rejecting $debfile : wrong sha1sum"
  234.                 [ `md5sum $debfile|sed -e "s, .*,,"` = "$debmd5" ] || die_hard_with_a_cleanup "rejecting $debfile : wrong md5sum"
  235.             fi
  236.    
  237.             dpkg-deb -x $debfile unpackchrome
  238.  
  239.             sofile=unpackchrome/opt/google/chrome/PepperFlash/libpepflashplayer.so
  240.             [ -e $sofile ] || sofile=unpackchrome/opt/google/chrome-unstable/PepperFlash/libpepflashplayer.so
  241.             [ -e $sofile ] || sofile=unpackchrome/opt/google/chrome/PepperFlash/libpepflashplayer.so
  242.  
  243.             mv -f $sofile /usr/lib/pepperflashplugin-nonfree
  244.             chown root:root /usr/lib/pepperflashplugin-nonfree/libpepflashplayer.so
  245.             chmod 644 /usr/lib/pepperflashplugin-nonfree/libpepflashplayer.so
  246.             mv $debfile $cachedir
  247.         fi
  248.  
  249.         [ "$verbose" != "yes" ] || echo "end of action $ACTION"
  250.  
  251.         [ ! -e /etc/chromium/default ] || \
  252.         grep -q pepperflashplugin-nonfree /etc/chromium/default \
  253.             || cat /usr/lib/pepperflashplugin-nonfree/etc-chromium-default.txt >> /etc/chromium/default
  254.         [ ! -e /etc/chromium-browser/default ] || \
  255.         grep -q pepperflashplugin-nonfree /etc/chromium-browser/default \
  256.             || cat /usr/lib/pepperflashplugin-nonfree/etc-chromium-default.txt >> /etc/chromium-browser/default
  257.  
  258.         ;;
  259.  
  260.     --uninstall)
  261.         [ "$verbose" != "yes" ] || echo "selected action = $ACTION"
  262.  
  263.         [ "$verbose" != "yes" ] || echo "removing files ..."
  264.         rm -f /usr/lib/pepperflashplugin-nonfree/libpepflashplayer.so
  265.  
  266.         [ "$verbose" != "yes" ] || echo "end of action $ACTION"
  267.  
  268.         ;;
  269.  
  270.     --status)
  271.         [ "$verbose" != "yes" ] || echo "selected action = $ACTION"
  272.  
  273.         echo "Flash Player version installed on this system  : $installed"
  274.         echo "Flash Player version available on upstream site: $upstream"
  275.  
  276.         [ "$verbose" != "yes" ] || echo "end of action $ACTION"
  277.  
  278.         ;;
  279.  
  280.     *)
  281.  
  282.         do_cleanup
  283.         show_usage
  284.  
  285.         ;;
  286.  
  287. esac
  288.  
  289. do_cleanup
  290.  
  291. [ "$verbose" != "yes" ] || echo "end of update-pepperflashplugin-nonfree"
Add Comment
Please, Sign In to add comment