Skip to content

Commit

Permalink
Improvement: add gitee and jsdelivr resource url (#371)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: Joshua Fogg <[email protected]>
  • Loading branch information
3 people authored Sep 5, 2020
1 parent f812186 commit 0b84acf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
33 changes: 22 additions & 11 deletions fix.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,10 +11,9 @@
# If not, see <http://www.gnu.org/licenses/>.

# 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/"
Expand Down Expand Up @@ -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" \
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
11 changes: 7 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 0b84acf

Please sign in to comment.