Advertisement
Guest User

merda

a guest
Nov 23rd, 2014
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.98 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. #Generic installation script for BE::Shell
  4. #themes and configs by Hombremaledicto.
  5. #Initial release V.0.1
  6.  
  7. #This script should not be executed as root
  8.  
  9. if [ "$(id -u)" == "0" ]; then
  10.     echo -e 'This script must be executed as normal user!!!\nI will now exit.'
  11.   exit 1
  12. fi
  13.  
  14. #Setting distro indipendent paths
  15.  
  16. declare -r scriptDir="$( cd "$( dirname ${BASH_SOURCE[0]} )" && pwd )"
  17. declare -r kdeDir="`kde4-config --localprefix`/share/"
  18. declare -r themesDir="${kdeDir}/apps/be.shell/Themes"
  19. declare -r configFile="${kdeDir}/config/be.shell"
  20.  
  21. #Test functions
  22.  
  23. declare -f confirm
  24. declare -f copy
  25. declare -f isRunning
  26. declare -f choice
  27. declare -f main
  28.  
  29. choice(){
  30.  
  31. declare -a confList="$( ls -l "$scriptDir" | grep 'be.shell' | sed 's/.*\.//' )"
  32. echo -e "Please, select a theme from the list below:\n"
  33.  
  34. for element in "${confList[@]}"; do
  35.        printf "%s\n" "${confList[@]}"
  36.    done
  37.  
  38. echo -n "Enter your choice:"
  39.  
  40.    read -r -p  "${1} " response      
  41.    case $response in
  42.    Vertex|Lullaby)
  43.        chosenConf="${scriptDir}/be.shell.$response"
  44.        chosenTheme="${scriptDir}/Themes/$response"
  45.        ;;
  46.    *)  return
  47.        ;;
  48.    esac    
  49.  
  50. }
  51.  
  52. confirm (){
  53.  
  54.    read -r -p "${1} " response
  55.    case $response in
  56.        [yY][eE][sS]|[yY])
  57.            true
  58.            ;;
  59.        *)
  60.            false
  61.            ;;
  62.    esac
  63.    
  64. }
  65.  
  66. copy(){
  67.  
  68. echo -e "$chosenConf\n$chosenTheme"
  69.  
  70. local dateHour="$( date "+%Y%m%d%H%M%S" )"
  71. local oldTheme="$( cat "$configFile" | grep -Po "(?<=Theme=)[ A-Za-z0-9]*" )"
  72. #tar cvzf "${oldTheme}.${dateHour}" "${themesDir}/${oldTheme}" "${configFile}"
  73.  
  74.  
  75. if [[ ! -f "$configFile" ]]; then
  76.      `cp "${scriptDir}/be.shell" "$configFile"`
  77.    else
  78.      confirm "Do you want to backup the existing theme and config? y/N:" && `tar -cf "${kdeDir}/apps/be.shell/$oldTheme.$dateHour" ${themesDir}/${oldTheme} ${configFile} &> /dev/null`
  79.    fi
  80.  
  81. if [[ ! -d "$themesDir" ]]; then
  82.     `mkdir "$themesDir"`
  83.   else
  84.    if [[ ! -d "$themesDir/Vertex" ]]; then
  85.      `cp -r "$chosenTheme" "$themesDir"`
  86.    else
  87.      echo "Theme is installed :-)"
  88.    fi
  89. fi
  90.  
  91. if [[ ! -f "$configFile" ]]; then
  92.     echo "$configFile does not exist"
  93.   else
  94.     echo "$configFile exists in filesystem"
  95. fi    
  96.  
  97. }
  98.  
  99. isRunning(){
  100.  
  101. local pShell="plasma-desktop"
  102. local bShell="be.shell"
  103.  
  104. if [[  -z `pidof "$pShell"` ]]; then
  105.   if [[ ! -z `pidof "$bShell"` ]]; then
  106.     confirm "I will now reload be.shell. Continue? [y/N]:" && `kquitapp "$bShell"; sleep 2; "$bShell" &> /dev/null`
  107.   else
  108.     confirm "Starting be.shell. Continue? [y/N]:" &&`"$bShell"`
  109.     fi
  110.   else
  111.     confirm "I will now stop Plasma and start be.shell. Continue? [y/N]:" && `kquitapp "$pShell"; sleep 2; "$bShell" &> /dev/null`
  112. fi
  113.  
  114. }
  115.  
  116. main(){
  117.  
  118. echo -e "\nInstallation Script for BE::Shell themes and configs by
  119. Hombremaledicto - https://github.com/Hombremaledicto/be.shell\n"
  120.  
  121. choice
  122. copy
  123. isRunning
  124.  
  125. echo "Done"
  126.  
  127. }
  128.  
  129. main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement