admin scripts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.5 KiB

  1. #!/bin/bash
  2. # Script to add a hg repo
  3. # Blame/contact werdz if there's any bugs or something doesn't work.
  4. HG=/usr/bin/hg
  5. COLLECTION=/storage/hg
  6. APACHE_UID=33
  7. APACHE_GID=33
  8. WEBHOST=morpheus
  9. ALLOW_ARCHIVE="gz zip bz2"
  10. CHOWN=/bin/chown
  11. if [[ $HOSTNAME != "$WEBHOST" ]]; then
  12. echo "This script must be run on the web server ($WEBHOST)."
  13. exit 1
  14. fi
  15. echo "What will this repository be called?"
  16. read -r REPONAME
  17. if [[ -e $COLLECTION/$REPONAME ]]; then
  18. echo "This repository already exists! Aborting."
  19. exit 2
  20. fi
  21. echo "What users should have write access to $REPONAME? (space separated list)"
  22. read -r USERLIST
  23. echo "Enter a brief description of this repository:"
  24. read -r DESCRIPTION
  25. echo "Enter a primary contact in the form Name <emailaddress@host.com>:"
  26. read -r CONTACT
  27. echo "Please confirm that the following details are correct:"
  28. echo "Repository name: $REPONAME"
  29. echo "Users with write (push) access: $USERLIST"
  30. echo "Description: $DESCRIPTION"
  31. echo "Primary contact: $CONTACT"
  32. echo
  33. echo -n "Are these correct? "
  34. ANSWER=""
  35. while [[ $ANSWER != "y" ]] && [[ $ANSWER != "n" ]]; do
  36. echo -n "(y/n) "
  37. read -r ANSWER
  38. done
  39. if [[ $ANSWER == "n" ]]; then
  40. echo "Aborting"
  41. exit 3
  42. fi
  43. echo "Init repository..."
  44. $HG init $COLLECTION/"$REPONAME"
  45. echo "Create configuration file..."
  46. cat > $COLLECTION/"$REPONAME"/.hg/hgrc << EOF
  47. [web]
  48. allow_push = $USERLIST
  49. contact = $CONTACT
  50. description = $DESCRIPTION
  51. allow_archive = $ALLOW_ARCHIVE
  52. EOF
  53. echo "Fix permissions..."
  54. $CHOWN -R $APACHE_UID:$APACHE_GID $COLLECTION/"$REPONAME"
  55. echo "Operation complete"
  56. exit 0