Install gitea with systemd

install.bash 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/bin/bash
  2. # Most of the code credit for determining version is here: https://gist.github.com/lukechilds/a83e1d7127b78fef38c2914c4ececc3c
  3. VER=$(curl --silent "https://api.github.com/repos/go-gitea/gitea/releases/latest" | # Get latest release from GitHub api
  4. grep '"tag_name":' | # Get tag line
  5. sed -E 's/.*"([^"]+)".*/\1/' | # Pluck JSON value
  6. sed 's|[v,]||g' ) # Remove v
  7. while [[ $# -gt 0 ]]
  8. do
  9. key="$1"
  10. case $key in
  11. -v|version)
  12. VER="$2"
  13. shift # past argument
  14. ;;
  15. *)
  16. # unknown option
  17. if test -z "${unknown}"
  18. then
  19. unknown=$1
  20. else
  21. echo "Unknown Option"
  22. exit 1
  23. fi
  24. ;;
  25. esac
  26. shift # past argument or value
  27. done
  28. # Create a 'gitea' user and group with the home /opt/gitea, no password (because it's a system user) and no GECOS
  29. sudo adduser gitea --home /opt/gitea --disabled-password --gecos ''
  30. # Make some other potentially useful directories for that user/group
  31. sudo mkdir -p /opt/gitea/ /var/log/gitea
  32. sudo chown -R gitea:gitea /opt/gitea/ /var/log/gitea
  33. # Download and install gitea
  34. # Check if architecure is i386 and download Gitea
  35. if [ -n "$(uname -a | grep i386)" ]; then
  36. sudo curl -fsSL -o "/opt/gitea/gitea-$VER" "https://dl.gitea.io/gitea/$VER/gitea-$VER-linux-386"
  37. fi
  38. # Check if architecure is x86 and download Gitea
  39. if [ -n "$(uname -a | grep x86_64)" ]; then
  40. sudo curl -fsSL -o "/opt/gitea/gitea-$VER" "https://dl.gitea.io/gitea/$VER/gitea-$VER-linux-amd64"
  41. fi
  42. # Check if architecure is ARMv6 and download Gitea
  43. if [ -n "$(uname -a | grep armv6l)" ]; then
  44. sudo curl -fsSL -o "/opt/gitea/gitea-$VER" "https://dl.gitea.io/gitea/$VER/gitea-$VER-linux-arm-6"
  45. fi
  46. # Check if architecure is ARMv7 and download Gitea
  47. if [ -n "$(uname -a | grep armv7l)" ]; then
  48. sudo curl -fsSL -o "/opt/gitea/gitea-$VER" "https://dl.gitea.io/gitea/$VER/gitea-$VER-linux-arm-7"
  49. fi
  50. # Setup Gitea symlink and permissions
  51. sudo chmod +x /opt/gitea/gitea-$VER
  52. rm -f /opt/gitea/gitea
  53. sudo ln -sf gitea-$VER /opt/gitea/gitea
  54. sudo ln -sf gitea-$VER /usr/local/bin/gitea
  55. # Download and install the gitea.service for systemd
  56. sudo curl -fsSL -o /etc/systemd/system/gitea.service https://git.coolaj86.com/coolaj86/gitea-installer.sh/raw/branch/master/dist/etc/systemd/system/gitea.service
  57. # Start gitea
  58. sudo systemctl enable gitea
  59. ## If this is performing an upgrade it may need extra ram for a limited time
  60. # fallocate -l 1G /tmp.swap
  61. # mkswap /tmp.swap
  62. # chmod 0600 /tmp.swap
  63. # swapon /tmp.swap
  64. sudo systemctl restart gitea
  65. set +e
  66. my_ip=$(ifconfig | grep inet | grep Mask | grep -v ':127\\.0\\.0\\.1' | grep -v ':192\\.168' | grep -v ':10\\.' | head -n 1 | cut -f 2 -d ':' | cut -f 1 -d ' ')
  67. my_ip=${my_ip:-localhost}
  68. set -e
  69. echo ""
  70. echo ""
  71. echo "###########################"
  72. echo "# Time to Configure #"
  73. echo "###########################"
  74. echo ""
  75. echo "Just a few more steps to complete at the setup URL:"
  76. echo ""
  77. echo " http://$my_ip:3000/"
  78. echo ""
  79. echo "Future changes can be made by editing the config file:"
  80. echo ""
  81. echo " /opt/gitea/custom/conf/app.ini"
  82. echo ""
  83. echo ""
  84. echo "P.S. Would you like to customize Gitea?"
  85. echo ""
  86. echo " Read basic instructions:"
  87. echo " https://git.coolaj86.com/coolaj86/gitea-installer.sh/_edit/master/install.bash"
  88. echo ""
  89. echo " View current templates:"
  90. echo " https://github.com/go-gitea/gitea/tree/v$VER/templates"
  91. echo ""
  92. echo " See a sample app.ini:"
  93. echo " https://github.com/go-gitea/gitea/blob/v$VER/custom/conf/app.ini.sample"
  94. echo ""
  95. # sleep 5
  96. # swapoff /tmp.swap
  97. # rm /tmp.swap