From 4bde4d7d1b3f6282186fd3409e91e86325eda97f Mon Sep 17 00:00:00 2001 From: Michel Roegl-Brunner <73236783+michelroegl-brunner@users.noreply.github.com> Date: Tue, 10 Dec 2024 14:34:00 +0100 Subject: [PATCH] Ideas for CONTRIBUTING.md (#768) * Update CONTRIBUTING.md * Update CONTRIBUTING.md * Update CONTRIBUTING.md * Update CONTRIBUTING.md * Update CONTRIBUTING.md --- .github/CONTRIBUTOR_GUIDE/CONTRIBUTING.md | 77 +++++++++++++++++++++-- 1 file changed, 73 insertions(+), 4 deletions(-) diff --git a/.github/CONTRIBUTOR_GUIDE/CONTRIBUTING.md b/.github/CONTRIBUTOR_GUIDE/CONTRIBUTING.md index 12637fc9..507b085d 100644 --- a/.github/CONTRIBUTOR_GUIDE/CONTRIBUTING.md +++ b/.github/CONTRIBUTOR_GUIDE/CONTRIBUTING.md @@ -131,6 +131,71 @@ function update_script() { - `check_container_storage`: Checks available storage - `check_container_resources`: Validates CPU/RAM resources +```bash +# Check if installation is present | -f for file, -d for folder + if [[ ! -f [INSTALLATION_CHECK_PATH] ]]; then + msg_error "No ${APP} Installation Found!" + exit + fi +``` + +> **Note**: +> - First you need to check if the APP is installed in the LXC +> - Replace ```INSTALLATION_CHECK_PATH``` with the path to the APP ```i.e. (/opt/app)``` + +```bash + # Crawling the new version and checking whether an update is required + RELEASE=$(curl -fsSL [RELEASE_URL] | [PARSE_RELEASE_COMMAND]) + if [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]] || [[ ! -f /opt/${APP}_version.txt ]]; then + + # Code to update the APP + + else + msg_ok "No update required. ${APP} is already at v${RELEASE}" + fi + exit +``` + +> **Note**: +> - Crawl for the newest version. Example for Github Releases: +> - ```RELEASE=$(curl -s https://api.github.com/repos/USER/REPO/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')``` +> - Then check if updating is required. + +```bash + # Stopping Services + msg_info "Stopping $APP" + systemctl stop [SERVICE_NAME] + msg_ok "Stopped $APP" + + # Creating Backup + msg_info "Creating Backup" + tar -czf "/opt/${APP}_backup_$(date +%F).tar.gz" [IMPORTANT_PATHS] + msg_ok "Backup Created" + + # Execute Update + msg_info "Updating $APP to v${RELEASE}" + [UPDATE_COMMANDS] + msg_ok "Updated $APP to v${RELEASE}" + + # Starting Services + msg_info "Starting $APP" + systemctl start [SERVICE_NAME] + sleep 2 + msg_ok "Started $APP" + + # Cleaning up + msg_info "Cleaning Up" + rm -rf [TEMP_FILES] + msg_ok "Cleanup Completed" + + # Last Action + echo "${RELEASE}" >/opt/${APP}_version.txt + msg_ok "Update Successful" +``` + +> **Note**: +> - In the IF-Block you then write the code to update the APP, Start and Stop the Services and clean up any temporary files + ## 6. 🏁 Script-End ```bash @@ -182,7 +247,10 @@ update_os ```bash msg_info "Installing Dependencies" -$STD apt-get install -y curl sudo mc +$STD apt-get install -y \ + curl \ + sudo \ + mc msg_ok "Installed Dependencies" ``` @@ -231,8 +299,6 @@ $STD apt-get -y autoclean msg_ok "Cleaned" ``` - - ## 7. 📢 Progress Messages ```bash @@ -250,12 +316,15 @@ echo "${RELEASE}" >"/opt/${APPLICATION}_version.txt" ## 9. 🔐 Credentials Management ```bash +USERNAME=username +PASSWORD=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | head -c13) { echo "Application-Credentials" echo "Username: $USERNAME" echo "Password: $PASSWORD" } >> ~/application.creds ``` +- Use random generated Passwords if possible ## 10. 📂 Directory Structure @@ -308,7 +377,7 @@ git clone https://github.com/yourUserName/ForkName ### 3. Create a New Branch ```bash -git checkout -b your-feature-branch +git switch -c your-feature-branch ``` ### 4. Change Paths in build.func and install.func