installer.sh 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/sh
  2. ## DESCRIPTION
  3. # This script will download the mediagoblin init scripts and install them for
  4. # you.
  5. # The script needs to know where your mediagoblin installation is. By default
  6. # this will be sed to what `pwd` will output when you run this script.
  7. #
  8. # This script uses the Dependency Based Boot in Debian >= 6.0
  9. # <http://wiki.debian.org/LSBInitScripts/DependencyBasedBoot>
  10. #
  11. ## USAGE
  12. #
  13. # # This will download the latest version of the installer.sh script directly
  14. # # From gist.github.com (-L allowing a 302 redirect to raw.github.com), then
  15. # # pipe the script directly through `sh` (presumably /bin/sh).
  16. # $ curl -L http://wandborg.se/mediagoblin-init-scripts/installer.sh | sh
  17. #
  18. # By default the MG_ROOT will be set to `pwd` and the user will be set to the
  19. # user you run the script as.
  20. #
  21. ## LICENSE: CC0 <http://creativecommons.org/publicdomain/zero/1.0/>
  22. # To the extent possible under law, Joar Wandborg <http://wandborg.se> has
  23. # waived all copyright and related or neighboring rights to
  24. # mediagoblin-paster. This work is published from Sweden.
  25. if ! [ -z "$1" ]; then
  26. MEDIAGOBLIN_ROOT=$1
  27. else
  28. MEDIAGOBLIN_ROOT=$(pwd)
  29. fi
  30. if ! [ -z "$2" ]; then
  31. MEDIAGOBLIN_USER=$2
  32. else
  33. MEDIAGOBLIN_USER=$(whoami)
  34. fi
  35. PASTER_INIT_URL="http://wandborg.se/mediagoblin-init-scripts/mediagoblin-paster.sh"
  36. PASTER_INIT_DESTINATION=/etc/init.d/mediagoblin-paster
  37. CELERYD_INIT_URL="http://wandborg.se/mediagoblin-init-scripts/mediagoblin-celery-worker.sh"
  38. CELERYD_INIT_DESTINATION=/etc/init.d/mediagoblin-celery-worker
  39. verify_and_install () {
  40. INIT_PATH=$1
  41. # Check if installation of the init script was successful
  42. if [ -f "$INIT_PATH" ]; then
  43. # Set executable permissions on the init script
  44. sudo chmod +x $INIT_PATH
  45. echo "Installing the $INIT_PATH script"
  46. # More on `insserv` at <http://wiki.debian.org/LSBInitScripts/DependencyBasedBoot>
  47. sudo insserv $INIT_PATH
  48. return 0
  49. fi
  50. return 1
  51. }
  52. # Download the mediagoblin-paster script from raw.github.com, replace the
  53. # MG_ROOT variable value with the $MEDIAGOBLIN_ROOT value and the MG_USER
  54. # variable value with the $MEDIAGOBLIN_USER value and pipe it to
  55. # the init script destination ($PASTER_INIT_DESTINATION).
  56. sudo su -c "curl $PASTER_INIT_URL \
  57. | sed s,^MG_ROOT=.*\n,MG_ROOT=$MEDIAGOBLIN_ROOT, \
  58. | sed s,^MG_USER=.*\n,MG_USER=$MEDIAGOBLIN_USER, \
  59. > $PASTER_INIT_DESTINATION"
  60. verify_and_install $PASTER_INIT_DESTINATION
  61. # Download and fix the mediagoblin-celery-worker script
  62. sudo su -c "curl $CELERYD_INIT_URL \
  63. | sed s,^MG_ROOT=.*\n,MG_ROOT=$MEDIAGOBLIN_ROOT, \
  64. | sed s,^MG_USER=.*\n,MG_USER=$MEDIAGOBLIN_USER, \
  65. > $CELERYD_INIT_DESTINATION"
  66. verify_and_install $CELERYD_INIT_DESTINATION