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.

gitea.lin.sh 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/bin/bash
  2. # Check if Gitea is installed by checking for the systemd service or binary
  3. #if systemctl is-active --quiet gitea || [ -f /usr/local/bin/gitea ]; then
  4. # echo "Gitea is already installed. Exiting installation."
  5. # exit 0
  6. #fi
  7. # Check if Gitea is installed
  8. if systemctl is-active --quiet gitea || [ -f /usr/local/bin/gitea ]; then
  9. echo "Uninstalling existing Gitea installation..."
  10. # Stop the Gitea service
  11. sudo systemctl stop gitea
  12. # Disable the Gitea service from starting automatically
  13. sudo systemctl disable gitea
  14. # Remove the Gitea binary
  15. sudo rm -f /usr/local/bin/gitea
  16. # Remove Gitea systemd service file
  17. sudo rm -f /etc/systemd/system/gitea.service
  18. # Reload systemd daemon to apply changes
  19. sudo systemctl daemon-reload
  20. # Remove Gitea directories (Optional: You can keep data or backup)
  21. sudo rm -rf /var/lib/gitea
  22. echo "Gitea uninstalled successfully."
  23. else
  24. echo "Gitea is not installed."
  25. fi
  26. # Update system packages
  27. sudo apt update -y
  28. sudo apt upgrade -y
  29. # Install dependencies
  30. sudo apt install -y git wget curl lsb-release sqlite3
  31. # Set the Gitea version
  32. GITEA_VERSION="1.23.5" # Replace with the latest version if needed
  33. # Download Gitea binary
  34. # wget -O /tmp/gitea https://dl.gitea.com/gitea/${GITEA_VERSION}/gitea-${GITEA_VERSION}-linux-amd64
  35. wget -O /tmp/gitea https://github.com/go-gitea/gitea/releases/download/v1.23.5/gitea-1.23.5-linux-amd64
  36. chmod +x /tmp/gitea
  37. # Move Gitea binary to /usr/local/bin
  38. sudo mv /tmp/gitea /usr/local/bin/gitea
  39. # Create necessary directories
  40. #sudo mkdir -p /var/lib/gitea/{custom,data,log}
  41. # Create necessary directories for Gitea (custom, data, log)
  42. sudo mkdir -p /var/lib/gitea/custom /var/lib/gitea/data /var/lib/gitea/log
  43. sudo chown -R $USER:$USER /var/lib/gitea
  44. sudo chmod -R 755 /var/lib/gitea
  45. sudo mkdir /etc/gitea
  46. chown root:git /etc/gitea
  47. chmod 770 /etc/gitea
  48. # chmod 750 /etc/gitea
  49. # chmod 640 /etc/gitea/app.ini
  50. # Create a system user for Gitea
  51. sudo useradd --system --create-home --shell /bin/bash --comment 'Gitea' gitea
  52. # Setup systemd service for Gitea
  53. cat <<EOF | sudo tee /etc/systemd/system/gitea.service
  54. [Unit]
  55. Description=Gitea
  56. After=network.target
  57. [Service]
  58. ExecStart=/usr/local/bin/gitea web
  59. Restart=always
  60. User=gitea
  61. Group=gitea
  62. Environment=USER=gitea HOME=/var/lib/gitea GITEA_WORK_DIR=/var/lib/gitea/data
  63. [Install]
  64. WantedBy=multi-user.target
  65. EOF
  66. # Reload systemd to recognize the new service
  67. sudo systemctl daemon-reload
  68. # Enable and start Gitea service
  69. sudo systemctl enable gitea
  70. sudo systemctl start gitea
  71. # Output the status of Gitea service
  72. sudo systemctl status gitea
  73. # Display message for post-installation configuration
  74. echo "Gitea is installed and running. You can access it at http://<your_server_ip>:3000"