Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/mode print #410

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 49 additions & 20 deletions fix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,25 @@ function backup() {
fi
}

function info() {
echo -e "$@" > /dev/stderr
}

function infos() {
echo -en "$@" > /dev/stderr
}

# Deals with the flags
if [ -z "$1" ]; then
mode="fix"
else
case $1 in
-l|--local)
mode="local";;
-p|--print)
mode="print";;
-r|--revert)
echo "This will undo all changes previously made."
info "This will undo all changes previously made."
while true; do
read -r -p "Are you sure you want to continue? " answer
case $answer in
Expand All @@ -90,8 +100,9 @@ else
"Usage: ./$(basename -- $0) [OPTION]\n" \
"\rFixes hardcoded icons of installed applications.\n\n" \
"\rCurrently supported options:\n" \
"\r -l, --local \t Only fixes local launchers.\n" \
"\r -r, --revert \t Reverts any changes made.\n" \
"\r -l, --local \t\t Only fixes local launchers.\n" \
"\r -r, --revert \t\t Reverts any changes made.\n" \
"\r -p, --print \t\t Only prints and make no chages.\n" \
"\r -h, --help \t\t Displays this help menu.\n" \
"\r -v, --version \t Displays program version.\n"
exit 0 ;;
Expand All @@ -104,16 +115,18 @@ else
gerror
esac
fi

# Creates the missing folders
if [ ! -d "$local_scalable_icon" ]; then
su -c "mkdir '$local_scalable_icon' -p" "$username"
fi
if [ ! -d "$local_icon" ]; then
su -c "mkdir '$local_icon' -p" "$username"
if [ "${mode}" != 'print' ]; then
if [ ! -d "$local_scalable_icon" ]; then
su -c "mkdir '$local_scalable_icon' -p" "$username"
fi
if [ ! -d "$local_icon" ]; then
su -c "mkdir '$local_icon' -p" "$username"
fi
fi



# Verifies if 'curl' is installed
if ! type "curl" >> /dev/null 2>&1; then
echo -e \
Expand All @@ -125,15 +138,15 @@ fi

# Choses online resource location from GitHub, Gitee, and jsDelivr
git_locate="local"
echo -n "Choosing host for updates... "
infos "Choosing host for updates... "
if eval "curl -sk https://raw.githubusercontent.com" >> /dev/null 2>&1; then
echo -e "connected to GitHub!"
info "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!"
info "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!"
info "Connected to jsDelivr!"
git_locate="https://cdn.jsdelivr.net/gh/Foggalong/hardcode-fixer@master"
else
echo -e "failed!\n"
Expand All @@ -147,7 +160,7 @@ 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 [ -n "$new_date" ] && [ "$date" -lt "$new_date" ]; then
echo -e \
info \
"You're running an out of date version of\n" \
"\rthe script. Please download the latest\n" \
"\rverison from the GitHub page or update\n" \
Expand All @@ -170,7 +183,7 @@ sed -i -e "1d" "/tmp/tofix.csv" # crops header line
chown "$username" "/tmp/tofix.csv"

# Checks for root
if [[ $UID -ne 0 ]] && [ $mode != "local" ]; then
if [[ $UID -ne 0 ]] && [ "$mode" != 'local' ] && [ "$mode" != 'print' ]; then
echo "The script must be run as root to (un)fix global launchers."
while true; do
read -r -p "Do you want to continue in local mode? " answer
Expand Down Expand Up @@ -223,11 +236,13 @@ while read -r name launcher current new_icon; do
sed -i "s/$name,$launcher,$current,$new_icon/$name,$launcher,$new_current,$new_icon/" "/tmp/tofix.csv"
fi
fi
if [ ! -d "$local_scalable_icon" ]; then
su -c "mkdir '$local_scalable_icon' -p" "$username"
fi
if [ ! -d "$local_icon" ]; then
su -c "mkdir '$local_icon' -p" "$username}"
if [ "$mode" != 'print' ]; then
if [ ! -d "$local_scalable_icon" ]; then
su -c "mkdir '$local_scalable_icon' -p" "$username"
fi
if [ ! -d "$local_icon" ]; then
su -c "mkdir '$local_icon' -p" "$username}"
fi
fi
if [ "$mode" == "fix" ] || [ "$mode" == "local" ]; then
# Local & Steam launchers
Expand Down Expand Up @@ -304,5 +319,19 @@ while read -r name launcher current new_icon; do
fi
fi
done
# Listing code
elif [ "$mode" == 'print' ]; then
for local_app in "${local_apps[@]}"
do
if [ -f "$local_app$launcher" ]; then
echo -e "$name\t$local_app$launcher"
fi
done
for global_app in "${global_apps[@]}"
do
if [ -f "$global_app$launcher" ]; then
echo -e "$name\t$global_app$launcher"
fi
done
fi
done < "/tmp/tofix.csv"