Add download_themes.sh
This commit is contained in:
parent
a375907b64
commit
e01b6d8e4a
68
download_themes.sh
Normal file
68
download_themes.sh
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user