From 0b84acf7f9df9c6029e4355abe88f9f5392f08d7 Mon Sep 17 00:00:00 2001 From: Nooop3 Date: Sat, 5 Sep 2020 18:18:32 +0800 Subject: [PATCH] Improvement: add gitee and jsdelivr resource url (#371) * Improvement: add gitee and jsdelivr resource url * Assign git_locate through cyclic check Original change by @nooop3 had it assigned as an environment variable, but probably more useful to have them directly checked as fallbacks. This also sets up the infrastructure to have the local version as the ultimate fallback. * Updated readme to make curl req. obvious Co-authored-by: Edward Guan Co-authored-by: Joshua Fogg --- fix.sh | 33 ++++++++++++++++++++++----------- readme.md | 11 +++++++---- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/fix.sh b/fix.sh index ea00daf..ee9e403 100755 --- a/fix.sh +++ b/fix.sh @@ -1,7 +1,7 @@ #!/bin/bash # Script for fixing hardcoded icons. Written and maintained on GitHub -# at https://github.com/Foggalong/hardcode-fixer - addtions welcome! +# at https://github.com/Foggalong/hardcode-fixer - additions welcome! # Copyright (C) 2014 # This program is free software: you can redistribute it and/or modify @@ -11,10 +11,9 @@ # If not, see . # Version info -date=201708180 # [year][month][date][extra] +date=202006261 # [year][month][date][extra] # Locations -git_locate="https://raw.githubusercontent.com/Foggalong/hardcode-fixer/master" username=${SUDO_USER:-$USER} userhome="/home/$username" global_apps=("/usr/share/applications/" @@ -124,20 +123,30 @@ if ! type "curl" >> /dev/null 2>&1; then gerror fi -# Checks for having internet access -if eval "curl -sk https://github.com/" >> /dev/null 2>&1; then - : # pass +# Choses online resource location from GitHub, Gitee, and jsDelivr +git_locate="local" +echo -n "Choosing host for updates... " +if eval "curl -sk https://raw.githubusercontent.com" >> /dev/null 2>&1; then + echo -e "connected to GitHub!" + git_locate="https://raw.githubusercontent.com/Foggalong/hardcode-fixer/master" +elif eval "curl -sk https://gitee.com" >> /dev/null 2>&1; then + echo -e "Connected to Gitee!" + git_locate="https://gitee.com/gh-mirror/hardcode-fixer/raw/master" +elif eval "curl -sk https://cdn.jsdelivr.net" >> /dev/null 2>&1; then + echo -e "Connected to jsDelivr!" + git_locate="https://cdn.jsdelivr.net/gh/Foggalong/hardcode-fixer@master" else + echo -e "failed!\n" echo -e \ "No internet connection available. This script\n" \ - "\rrequires internet access to connect to GitHub\n" \ - "\rto check for updates and download 'to-fix' info." + "\rrequires internet access to check for updates\n" \ + "\rand download the latest 'to-fix' info." gerror fi # Check for newer version of fix.sh new_date=$(curl -sk "${git_locate}"/fix.sh | grep "date=[0-9]\{9\}" | sed "s/[^0-9]//g") -if [ "$date" -lt "$new_date" ]; then +if [ -n "$new_date" ] && [ "$date" -lt "$new_date" ]; then echo -e \ "You're running an out of date version of\n" \ "\rthe script. Please download the latest\n" \ @@ -154,6 +163,7 @@ if [ "$date" -lt "$new_date" ]; then done fi + # Downloads latest version of the list curl -sk -o "/tmp/tofix.csv" "${git_locate}/tofix.csv" sed -i -e "1d" "/tmp/tofix.csv" # crops header line @@ -177,6 +187,7 @@ if [[ $UID -ne 0 ]] && [ $mode != "local" ]; then done fi + # Itterating over lines of tofix.csv, each split into an array IFS="," while read -r name launcher current new_icon; do @@ -199,10 +210,10 @@ while read -r name launcher current new_icon; do fi for app_location in "${combined_apps[@]}" - do + do if [ -f "$new_current" ]; then break - fi + fi if [ -f "$app_location$launcher" ]; then new_current=$(grep -Gq "Icon=*$" "$app_location$launcher") fi diff --git a/readme.md b/readme.md index 077743a..b24bcbd 100644 --- a/readme.md +++ b/readme.md @@ -1,11 +1,14 @@ # Hardcoded Icon Fixer -This program aims to be a safe, easy and standardised solution to the problem of hardcoded application icons in Linux. All it is is [this one bash script](https://github.com/Foggalong/hardcode-fixer/blob/master/fix.sh) - simply copy it to somewhere on your PC and run. Use ```./fix.sh -h``` for help. +This program aims to be a safe, easy and standardised solution to the problem of hardcoded application icons in Linux. All it is is [this one bash script](https://github.com/Foggalong/hardcode-fixer/blob/master/fix.sh) - simply copy it to somewhere on your PC and run. If you're an Arch user it's also available in the [AUR](https://aur.archlinux.org/packages/hardcode-fixer-git/). -If you're an Arch user it's also available in the [AUR](https://aur.archlinux.org/packages/hardcode-fixer-git/). +The script requires `curl` to download the latest '[to-fix](https://github.com/Foggalong/hardcode-fixer/blob/master/tofix.csv)' list from GitHub (else Gitee or jsDelivr if that fails). -### More information: -+ An indepth explanation of [what, why & how](https://github.com/Foggalong/hardcode-fixer/wiki/What,-Why-&-How) + +### More Info +Use `./fix.sh -h` for help, or otherwise consult [the wiki](https://github.com/Foggalong/hardcode-fixer/wiki) for: + ++ An indepth explanation of [what, why, & how](https://github.com/Foggalong/hardcode-fixer/wiki/What,-Why-&-How) + [Use instructions](https://github.com/Foggalong/hardcode-fixer/wiki/Instructions) + Supported [application list](https://github.com/Foggalong/hardcode-fixer/wiki/App-Support) + Information on [theme support](https://github.com/Foggalong/hardcode-fixer/wiki/Theme-Support)