blogsetup 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/env bash
  2. set -eu
  3. # blogsetup
  4. # ~~~~~~~~~
  5. #
  6. # Pre running this you should run:
  7. #
  8. # git clone https://github.com/thcipriani/dotfiles ~/.dotfiles.git
  9. # git clone ~/.dotfiles.git ~/.dotfiles
  10. #
  11. # This program handles:
  12. #
  13. # 1. Ensuring that ~/.ikiwiki is setup and inplace
  14. # 2. Ensuring that the githooks are in place for ~/.dotfiles.git
  15. # 3. Ensuring that the post-update hooks are inplace for ~/.dotfiles.git
  16. (( $# < 1 )) && {
  17. cat<<HELP
  18. Usage: $(basename "$0") <local|remote>
  19. ... Use remote for the server, local everywhere else
  20. HELP
  21. exit 1
  22. }
  23. [[ -d "$HOME/.dotfiles" && -d "$HOME/.dotfiles.git" ]] || {
  24. cat<<CLONE
  25. This command assumes you've run:
  26. git clone https://github.com/thcipriani/dotfiles ~/.dotfiles.git
  27. git clone ~/.dotfiles.git ~/.dotfiles
  28. ...so probably do that.
  29. CLONE
  30. exit 2
  31. }
  32. USER=$(whoami)
  33. WHEREAMI=$1
  34. (( $(id -u) == 0 )) && {
  35. echo "Don't run this as root, fool"
  36. exit 3
  37. }
  38. [[ "$WHEREAMI" == 'local' || "$WHEREAMI" == 'remote' ]] || {
  39. cat<<WHERE
  40. '$WHEREAMI' should be either "local" or "remote"
  41. WHERE
  42. }
  43. if [[ ! -h "$HOME/.ikiwiki" ]]; then
  44. mv "$HOME/.ikiwiki" "$HOME/.ikiwiki-$(date +%s)"
  45. ln -sf "$HOME/.dotfiles/ikiwiki" "$HOME/.ikiwiki"
  46. fi
  47. cp "$HOME/.ikiwiki/ikiwiki-hooks/post-update" "$HOME/.dotfiles.git/hooks/post-update"
  48. if [[ ! -d "$HOME/.dotfiles.git/hooks/post-update.d" ]]; then
  49. cp -r "$HOME/.ikiwiki/ikiwiki-hooks/post-update.d" "$HOME/.dotfiles.git/hooks/post-update.d"
  50. fi
  51. ikiwiki --changesetup "$HOME/.ikiwiki/TylerCipriani.setup"
  52. if [[ "$WHEREAMI" == 'local' ]]; then
  53. # No-op for the local setup
  54. printf '#!/bin/bash\nexec /bin/true' > "$HOME/.dotfiles.git/hooks/post-update.d/99-amazon-update"
  55. fi
  56. chmod u+s "$HOME/.dotfiles.git/hooks/post-update"
  57. for file in "$HOME"/.dotfiles.git/hooks/post-update.d/*; do
  58. chmod u+s "$file"
  59. done
  60. echo "DONE! Please oh please be done"