From e01b6d8e4ac2e777cfe71d18fb9958c53ec83b94 Mon Sep 17 00:00:00 2001 From: Sthope Date: Tue, 15 Aug 2023 13:08:49 +0200 Subject: [PATCH] Add download_themes.sh --- download_themes.sh | 68 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 download_themes.sh diff --git a/download_themes.sh b/download_themes.sh new file mode 100644 index 0000000..4d06676 --- /dev/null +++ b/download_themes.sh @@ -0,0 +1,68 @@ +#!/bin/bash + +# Include configuration variables +source "./discord_url" + +# Define an array for themes with their names and URLs. +themes=( + "theme-dark-arc|https://raw.githubusercontent.com/Jieiku/theme-dark-arc-gitea/main/theme-dark-arc.css" + "theme-github-dark|https://codeberg.org/pat-s/gitea-github-theme/raw/branch/main/theme-github-dark.css" + "theme-github|https://codeberg.org/pat-s/gitea-github-theme/raw/branch/main/theme-github.css" + "theme-github-auto|https://codeberg.org/pat-s/gitea-github-theme/raw/branch/main/theme-github-auto.css" + "theme-tangerine-dream|https://raw.githubusercontent.com/jager012/tangerine-dream/main/theme-tangerine-dream.css" +) + +# Function to send an error message to Discord +function send_discord_message() { + message="$1" + + curl -H "Content-Type: application/json" -X POST -d "{\"content\": \"$message\"}" "$DISCORD_WEBHOOK_URL" +} + +# Logging functions +function log_info() { + log_message="$1" + echo "$(date +'%Y-%m-%d %H:%M:%S') - INFO: $log_message" +} + +function log_error() { + error_message="$1" + echo "$(date +'%Y-%m-%d %H:%M:%S') - ERROR: $error_message" + send_discord_message "$error_message" +} + +function update_theme() { + local_theme="$1" + local_file="$local_theme.css" + remote_url="$2" + remote_temp="./$local_theme-remote-temp.css" + + # Download the remote file to a temporary file + wget -q "$remote_url" -O "$remote_temp" + + if cmp -s "$local_file" "$remote_temp"; then + log_info "The $local_theme files have the same contents." + else + log_info "The $local_theme files have different contents. Updating local file..." + + # Replace the local file with the remote one + mv "$remote_temp" "$local_file" || { log_error "Failed to update $local_file"; exit 1; } + + log_info "$local_theme local file updated with the remote version." + fi + + # Clean up by removing the temporary remote file + rm -f "$remote_temp" +} + +function main() { + for theme in "${themes[@]}"; do + IFS="|" read -r theme_name remote_url <<< "$theme" + update_theme "$theme_name" "$remote_url" + done + + # send_discord_message "Themes checked and updated if needed." +} + +# Execute the main function +main