From 393bb81768f43355a3666edc590ff8128705fae2 Mon Sep 17 00:00:00 2001 From: Juarez Rudsatz Date: Wed, 13 Sep 2023 15:45:49 -0300 Subject: [PATCH 1/2] Added new mode print --- fix.sh | 49 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/fix.sh b/fix.sh index ee9e403..4a82ca7 100755 --- a/fix.sh +++ b/fix.sh @@ -75,6 +75,8 @@ else case $1 in -l|--local) mode="local";; + -p|--print) + mode="print";; -r|--revert) echo "This will undo all changes previously made." while true; do @@ -90,8 +92,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 ;; @@ -104,16 +107,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 \ @@ -170,7 +175,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 @@ -223,11 +228,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 @@ -304,5 +311,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" From 953cf32a02b45cff8a78cad3094a049a125e5287 Mon Sep 17 00:00:00 2001 From: Juarez Rudsatz Date: Wed, 13 Sep 2023 16:00:57 -0300 Subject: [PATCH 2/2] Remove log msg from print allowing output to a pipe --- fix.sh | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/fix.sh b/fix.sh index 4a82ca7..3dd5444 100755 --- a/fix.sh +++ b/fix.sh @@ -68,6 +68,14 @@ 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" @@ -78,7 +86,7 @@ else -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 @@ -130,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" @@ -152,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" \