DragonHawk

install_update_flash.sh

Mar 27th, 2011
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.37 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # install or update Adobe Flash with dpkg
  4.  
  5. # Adobe offers Flash in a dpkg package, suitable for use with Debian, Ubuntu
  6. # and other Linux systems using dpkg.  However, the only APT repository
  7. # which includes Flash is Ubuntu, and that doesn't always work on Debian,
  8. # due to incompatible dependencies.
  9. #
  10. # This script retrieves the dpkg file from Adobe (if needed), and then
  11. # installs it if the downloaded package file is a newer/different version
  12. # than what's currently installed (if anything).
  13.  
  14. # ---------- constants ----------
  15.  
  16. PKGFILE="install_flash_player_10_linux.deb"
  17. PKGURL="http://fpdownload.macromedia.com/get/flashplayer/current/$PKGFILE"
  18. PKGDIR="/var/cache/install_update_flash"
  19.  
  20. # ---------- functions ----------
  21.  
  22. function die () {
  23.     echo "FATAL ERROR: $*"
  24.     exit 1
  25. }
  26.  
  27. function decho () {
  28. # debug echo
  29.     [ -n "$DEBUG" ] || return
  30.     echo "$@"
  31. }
  32.  
  33. # ---------- program ----------
  34.  
  35. # chdir to cache dir, creating if needed
  36. [ -e "$PKGDIR" ] || mkdir "$PKGDIR" || die "mkdir trouble"
  37. cd "$PKGDIR" || die "chdir trouble"
  38.  
  39. # get latest version, if newer than what we have (or if we have nothing)
  40. wget --no-verbose --timestamping "$PKGURL" || die "wget trouble"
  41.  
  42. # download file should be size greater than zero
  43. [ -s "$PKGFILE" ] || die "package file is missing/empty/bogus after download attempt"
  44.  
  45. # get package name and version from file we downloaded
  46. PKGNAME=$( dpkg-deb --field "$PKGFILE" Package ) || die "trouble examining downloaded package file"
  47. FILEVER=$( dpkg-deb --field "$PKGFILE" Version ) || die "trouble examining downloaded package file"
  48.  
  49. decho "PKGNAME=$PKGNAME"
  50. decho "FILEVER=$FILEVER"
  51.  
  52. # get version of installed package of same name (if any)
  53. unset INSTVER
  54. INSTVER=$( dpkg-query --show --showformat='${Version}\n' "$PKGNAME" )
  55. RC=$?
  56. if [ "$RC" = 1 ]; then
  57.     INSTVER=none
  58. elif [ "$RC" -gt 1 ]; then
  59.     die "trouble querying installed packages"
  60. fi
  61. # RC=0 means we got an installed package version
  62.  
  63. decho "INSTVER=$INSTVER"
  64.  
  65. # exit no-op if same version already installed
  66. if [ "$INSTVER" = "$FILEVER" ]; then
  67.     decho "installed version same as download version, nothing to do"
  68.     exit 0
  69. fi
  70.  
  71. echo "New/different version downloaded.  Installing downloaded package file..."
  72. echo "Installed : $INSTVER"
  73. echo "Downloaded: $FILEVER"
  74.  
  75. # dpkg exit code becomes our exit code
  76. dpkg --install "$PKGFILE"
  77.  
  78. # ---------- EOF ----------
Advertisement
Add Comment
Please, Sign In to add comment