setup_status_network.sh 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/bin/bash
  2. # live fast! die young!
  3. set -e
  4. source /etc/statusnet/setup.cfg
  5. # setup_status_network.sh mysite 'My Site' '1user' 'owner@example.com' 'Firsty McLastname'
  6. export nickname="$1"
  7. export sitename="$2"
  8. export tags="$3"
  9. export email="$4"
  10. export fullname="$5"
  11. export siteplan="$6"
  12. if [ "$siteplan" == '' ]; then
  13. siteplan='single-user'
  14. fi
  15. # Fixme: if this is changed later we need to update profile URLs
  16. # for the created user.
  17. export server="$nickname.$WILDCARD"
  18. # End-user info
  19. export userpass=`$PWDGEN`
  20. export roles="administrator moderator owner"
  21. # DB info
  22. export password=`$PWDGEN`
  23. export database=$nickname$DBBASE
  24. export username=$nickname$USERBASE
  25. # Create the db
  26. mysqladmin -h $DBHOST -u $ADMIN --password=$ADMINPASS create $database
  27. for f in statusnet.sql innodb.sql sms_carrier.sql foreign_services.sql notice_source.sql; do
  28. mysql -h $DBHOST -u $ADMIN --password=$ADMINPASS $database < ../db/$f;
  29. done
  30. mysql -h $DBHOST -u $ADMIN --password=$ADMINPASS $SITEDB << ENDOFCOMMANDS
  31. GRANT ALL ON $database.* TO '$username'@'localhost' IDENTIFIED BY '$password';
  32. GRANT ALL ON $database.* TO '$username'@'%' IDENTIFIED BY '$password';
  33. INSERT INTO status_network (nickname, dbhost, dbuser, dbpass, dbname, sitename, created)
  34. VALUES ('$nickname', '$DBHOSTNAME', '$username', '$password', '$database', '$sitename', now());
  35. ENDOFCOMMANDS
  36. for top in $AVATARBASE $FILEBASE $BACKGROUNDBASE; do
  37. mkdir $top/$nickname
  38. chmod a+w $top/$nickname
  39. done
  40. php $PHPBASE/scripts/checkschema.php -s"$server"
  41. php $PHPBASE/scripts/settag.php -s"$server" "$nickname" "$tags"
  42. php $PHPBASE/scripts/registeruser.php \
  43. -s"$server" \
  44. -n"$nickname" \
  45. -f"$fullname" \
  46. -w"$userpass" \
  47. -e"$email"
  48. for role in $roles
  49. do
  50. php $PHPBASE/scripts/userrole.php \
  51. -s"$server" \
  52. -n"$nickname" \
  53. -r"$role"
  54. done
  55. if [ -f "$MAILTEMPLATE" ]
  56. then
  57. # fixme how safe is this? are sitenames sanitized?
  58. cat $MAILTEMPLATE | \
  59. sed "s/\$nickname/$nickname/" | \
  60. sed "s/\$sitename/$sitename/" | \
  61. sed "s/\$userpass/$userpass/" | \
  62. sed "s/\$siteplan/$siteplan/" | \
  63. php $PHPBASE/scripts/sendemail.php \
  64. -s"$server" \
  65. -n"$nickname" \
  66. --subject="$MAILSUBJECT"
  67. else
  68. echo "No mail template, not sending email."
  69. fi
  70. if [ -f "$POSTINSTALL" ]
  71. then
  72. echo "Running $POSTINSTALL ..."
  73. source "$POSTINSTALL"
  74. fi