Advertisement
unixwz0r

cp-st (copy setup-tuxhat & conf to /mnt/usr/bin)

Jan 23rd, 2015
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.24 KB | None | 0 0
  1. #!/bin/bash -x
  2. ##################### Copy /opt folder to /mnt with progress
  3. DIALOGRC=${DIALOGRC}
  4. CONFIGFILE=/opt/setup/setup-tuxhat.conf
  5. DIALOG=${DIALOG=dialog}
  6.  
  7. # config file for theme black and white
  8. if [[ -f $CONFIGFILE ]]; then
  9.   source $CONFIGFILE
  10. else
  11.   echo "Error missing file: setup-tuxhat.conf - Required by program"
  12.   exit 1
  13. fi
  14. ## Create an array of all files in /opt directory
  15. DIRS=(/opt/setup/bin/setup-tuxhat/*)
  16.  
  17. #Destination directory
  18. DEST="/mnt/usr/bin/"
  19.  
  20. # Create $DEST if does not exits
  21. [ ! -d $DEST ] && mkdir -p $DEST
  22.  
  23. # Show a progress bar
  24. # ---------------------------------
  25. # Redirect dialog commands input using substitution
  26. #
  27. DIALOGRC="$DIALOGRC" $DIALOG  --title "Copy System files" --gauge "Copying files..." 10 75 < <(
  28.  
  29. # Get total number of files in array
  30.    n=${#DIRS[*]};
  31.  
  32.    # set counter - it will increase every-time a file is copied to $DEST
  33.    i=0
  34.  
  35.    #
  36.    # Start the for loop
  37.    #
  38.    # read each file from $DIRS array
  39.    # $f has filename
  40.    for f in "${DIRS[@]}"
  41.    do
  42.       # calculate progress
  43.       PCT=$(( 100*(++i)/n ))
  44.  
  45.       # update dialog box
  46. cat <<EOF
  47. XXX
  48. $PCT
  49. Copying file "$f"...
  50. XXX
  51. EOF
  52.   # copy file $f to $DEST
  53.   /bin/cp -ar $f ${DEST} &>/dev/null
  54.    done
  55. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement