ylee2019

efreetcc

Feb 22nd, 2021 (edited)
1,251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.04 KB | None | 0 0
  1. #!/bin/bash
  2. # Copyright 2021 [email protected]
  3. #
  4. # This work is free. You can redistribute it and/or modify it under the
  5. # terms of the Do What The Fuck You Want To Public License, Version 2,
  6. # as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
  7.  
  8. # Note: I use a program I wrote, efl-version, to determine efl version
  9. #       and I am assuming the efl version is the same as the efreet version
  10. #       perhaps not necessarily true on debian (others?) where it is possible to
  11. #       install efl compontents separately.
  12. #       In the event that efl-version is not installed (in PATH) this program will
  13. #       fallback on pkg-config and assumes it as well as efl development files are installed.
  14.  
  15. # I don't deal with non debian/standard --prefix instaations
  16. # should I kill efreetd first, is that even possible as it restarts...
  17. # FIXME: do I need to delete subdirs_$USER-VirtualBox.eet also
  18. # I only handle/test archs i686 and x86_64, unsure how it acts on other archs
  19.  
  20. set -eu
  21.  
  22. print_help()
  23. {
  24.   printf '%s\n' "Bodhi's magical efreet cli tool."
  25.   printf '\t%s\n\n' "This tool attempts to fix a broken efreet cache. Use at your own risk."
  26.   printf 'Usage: %s [option] ...\n\n' "$0"
  27.   printf '%s %s\n\n'  "$0" "with no options, deletes all efreet caches, regenerates them all and resarts the WM"
  28.   printf 'Options:\n'
  29.   printf '\t%s\n' "-i, --icons:   Regenerate efreets icon cache "
  30.   printf '\t%s\n' "-d, --desks:   Regenerate efreets application data cache"
  31.   printf '\t%s\n' "-m, --mimes:   Regenerate efreets mime types cache"
  32.   printf '\t%s\n' "-s, --safe:    Do not delete efreet cache(s) before regeneration"
  33.   printf '\t%s\n' "--restart:     Restart Window Manager after regeneration of cache(s)"
  34.   printf '\t%s\n' "-l, --license: Prints license and exits"
  35.   printf '\t%s\n' "-v, --version: Prints version and exits"
  36.   printf '\t%s\n' "-h, --help:    Prints help and exits"
  37. }
  38.  
  39. # # When called, the process ends.
  40. # Args:
  41. #   $1: The exit message (print to stderr)
  42. #   $2: The exit code (default is 1)
  43. # if env var _PRINT_HELP is set to 'yes', the usage is print to stderr (prior to $1)
  44. die()
  45. {
  46.   local _ret="${2:-1}"
  47.   test "${_PRINT_HELP:-no}" = yes && print_help >&2
  48.   echo -e "$1" >&2
  49.   exit "${_ret}"
  50. }
  51.  
  52. # THE DEFAULTS INITIALIZATION
  53. _ICONS=0
  54. _DESKS=0
  55. _MIMES=0
  56. _SAFE=0
  57. _RESET=0
  58.  
  59. # Check to ensure efreet is actually installed
  60. if ! hash efreetd 2>/dev/null; then
  61.   PRINT_HELP=no die "FATAL ERROR: EFreet is not installed!!" 1
  62. fi
  63.  
  64. if hash efl-version 2>/dev/null; then
  65.   EFL_VERSION=$(efl-version | cut -c 1-4)
  66. else
  67.   pkg-config --modversion efl >/dev/null;
  68.   if [ $? -eq 1 ]; then
  69.     echo "Development files for EFL are not installed."
  70.     echo "Install either efl-version or libefl-dev."
  71.     echo
  72.     # FIXME: add link for efl-version
  73.     _PRINT_HELP=no die "FATAL ERROR: Unable to determine efl version." 1
  74.   else
  75.     EFL_VERSION=$(pkg-config --modversion efl | cut -c 1-4)
  76.   fi
  77. fi
  78. ARCH=$(uname -i | sed -e 's/686/386/g')
  79. EFREET_PATH="/usr/lib/$ARCH-linux-gnu/efreet/v-$EFL_VERSION"
  80. if [ ! -d "$EFREET_PATH" ]; then
  81.   PRINT_HELP=no die "FATAL ERROR: efreet path does not exist: $EFREET_PATH" 1
  82. fi
  83.  
  84. xdg_data_dirs()
  85. {
  86.   local IFS=':'
  87.   local PATHS=''
  88.  
  89.   read -ra ADDR <<< "$XDG_DATA_DIRS"
  90.   for i in "${ADDR[@]}"; do   # access each element of array
  91.       PATHS+=" \"$i/$1\""
  92.   done
  93.   echo "$PATHS"
  94. }
  95.  
  96. ICON_PATHS="/usr/share/icons ~/.icons /usr/local/share/icons/ /usr/share/pixmaps/ /usr/local/share/pixmaps/"
  97. ICON_PATHS+=" $(xdg_data_dirs "icons")"
  98. DESK_PATHS="/usr/share/applications ~/.local/share/applications/"
  99. DESK_PATHS+=" $(xdg_data_dirs "applications")"
  100.  
  101. do_all()
  102. {
  103.   echo "do all"
  104.   if [ $_SAFE -eq 0 ]; then
  105.    rm -rf ~/.cache/efreet
  106.   fi
  107.   "$EFREET_PATH/efreet_icon_cache_create" -d "$ICON_PATHS" -e .png .svg .jpg .xpm
  108.   "$EFREET_PATH/efreet_desktop_cache_create" -d "$DESK_PATHS" ~/.local/share/applications
  109.   "$EFREET_PATH/efreet_mime_cache_create"
  110.    enlightenment_remote -restart
  111.   exit 0
  112. }
  113.  
  114. danger()
  115. {
  116.   echo "Really delete efreet cache and regenerate all data?"
  117.   if [[ "$(read -r -e -p 'Continue? [y/N]> '; echo "$REPLY")" == [Yy]* ]]; then
  118.     do_all
  119.   else
  120.     exit 0
  121.   fi
  122. }
  123.  
  124. # The parsing of the command-line
  125. parse_commandline()
  126. {
  127.   if [ -z "$*" ]; then danger; fi
  128.   while test $# -gt 0
  129.   do
  130.     _key="$1"
  131.     case "$_key" in
  132.       -i|--icons)
  133.         _ICONS=1
  134.         ;;
  135.       -d|--desks)
  136.         _DESKS=1
  137.         ;;
  138.       -m|--mimes)
  139.         _MIMES=1
  140.         ;;
  141.       -s|--safe)
  142.         _SAFE=1
  143.         ;;
  144.       --restart)
  145.         _RESET=1
  146.         ;;
  147.       -l|--license)
  148.         echo "Do What The Fuck You Want To Public License, Version 2"
  149.         echo "See http://www.wtfpl.net/ for more details."
  150.         echo -e "\nTHIS SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED\n"
  151.         echo "Copyright 2021 Bodhi Linux, https://www.bodhilinux.com"
  152.         exit 0
  153.         ;;
  154.       -v|--version)
  155.         printf '%s v%s\n\n%s\n' "$0" "0.1" ''
  156.         exit 0
  157.         ;;
  158.       -h|--help)
  159.         print_help
  160.         exit 0
  161.         ;;
  162.       *)
  163.         _PRINT_HELP=yes die "\nFATAL ERROR: Got an unexpected argument '$1'" 1
  164.         ;;
  165.     esac
  166.     shift
  167.   done
  168. }
  169.  
  170. parse_commandline "$@"
  171.  
  172. sum=$(($_ICONS + $_MIMES + $_DESKS))
  173. if [ $sum -eq 3 ]; then
  174.   do_all
  175. fi
  176.  
  177. if [ $sum -eq 0 ] && [ $_RESET -eq 1 ]; then
  178.   _PRINT_HELP=yes die "\nFATAL ERROR: Argument '$1' must be used with one or more cache to delete" 1
  179. fi
  180.  
  181. if ((_ICONS)) ; then
  182. # FIXME: do I need to delete subdirs_$USER-VirtualBox.eet also
  183.   if [ $_SAFE -eq 0 ]; then
  184.      rm ~/.cache/efreet/icon*
  185.   fi
  186.    "$EFREET_PATH/efreet_icon_cache_create" -d "$ICON_PATHS" -e .png .svg .jpg .xpm
  187. fi
  188.  
  189. if ((_DESKS)) ; then
  190.   if [ $_SAFE -eq 0 ]; then
  191.      rm ~/.cache/efreet/desktop*
  192.   fi
  193.   "$EFREET_PATH/efreet_desktop_cache_create" -d "$DESK_PATHS"
  194. fi
  195.  
  196. if ((_MIMES)); then
  197.   if [ $_SAFE -eq 0 ]; then
  198.      rm ~/.cache/efreet/mime*
  199.   fi
  200.   "$EFREET_PATH/efreet_mime_cache_create"
  201. fi
  202.  
  203. if [ $_RESET -eq 1 ]; then
  204.   enlightenment_remote -restart
  205. fi
  206.  
Advertisement
Add Comment
Please, Sign In to add comment