Advertisement
quiliro

copiar_usb.bash

Oct 20th, 2012
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.58 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Copyright (C) 2012 Quiliro Ordóñez and IgnorantGuru
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU Affero General Public License as
  7. # published by the Free Software Foundation, either version 3 of the
  8. # License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
  13. # GNU Affero General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Affero General Public
  16. # License along with this program.If not, see
  17. # <http://www.gnu.org/licenses/>.
  18. #
  19. # http://igurublog.wordpress.com
  20. # quiliro [at] fsfla [dot] org
  21. #
  22. #
  23. # Instructions to replicate:
  24. #
  25. # Copy the operating system to another USB memory by changing to the
  26. # directory where the image is and executing this command:
  27. # dd if=bom_compartilhar.img of=/dev/sdb
  28. # where sdb is the device corresponding to the destination USB memory.
  29. # You should type:
  30. # mount
  31. #
  32. # to discover which devices are currently mounted and deduce which one
  33. # is you destination USB memory. Then unmount the destination USB
  34. # memory and proceed to copy the operating system.
  35. #
  36. # Configure Num Lock to OFF in BIOS.
  37. #
  38. # Note: If you didn't copy the operating system from my image, you
  39. # should install the necesary packages. On Parabola GNU, the command
  40. # is:
  41. # pacman -S udevil rsync dosfstools sudo
  42. #
  43. # In order to start this script on boot, make it executable with:
  44. # chmod u+x copiar_usb.bash
  45. #
  46. # and at the end of Parabola's /etc/rc.local file, add:
  47. # devmon --exec-on-drive "/home/bom/copiar_usb.bash %f %d" &
  48. # setleds -num +caps -scroll < /dev/tty1 &
  49. #
  50. # Keep hacking this script and let us know your progress!
  51. #
  52.  
  53. keyboard="/dev/tty1"
  54.  
  55. echo
  56. echo "Changing Caps Lock to OFF"
  57. setleds -caps < $keyboard
  58.  
  59. native_path=`udevil --show-info $1 | grep "^  native-path:" | sed 's/^  native-path: *\(.*\) */\1/'`
  60. usb_port="${native_path##*/usb[[:digit:]]/}"
  61. echo
  62. echo "native_path is " $native_path
  63. echo "usb_port is " $usb_port
  64. usb_port="${usb_port%%/*}"
  65. echo "Now usb_port is " $usb_port
  66. echo
  67.  
  68. echo "%f device filesystem - is " $1
  69. echo "%d mount directory - is " $2
  70. echo
  71.  
  72. case "$usb_port" in
  73.  
  74.     "1-1" )
  75.     echo
  76.     echo "Changing Num Lock to ON"
  77.     setleds +num < $keyboard
  78.  
  79. ## One attempt at erasing the recycle bin:
  80. #   echo "Testing if enough space is left on the device"
  81. #   contents="du -s /home/bom/bom_compartilhar"
  82. #   (( $( read -d '' -ra df < <(LC_ALL=C df -P "$1" ); echo "${df[10]}" ) < contents)) && echo rm -rf "$2"/.Trash*;
  83. #
  84. ## Another attempt at erasing the recycle bin:
  85. #   free_space=$(df | grep $1 | awk '{ print '$4'; }')
  86. #   if [ $contents -lt $free_space ]; then
  87. #     echo "Not enough free space on $2. Erasing Trash bin."
  88. #     find $2 -name ".Trash*" -exec rm -rf {} \;
  89. #   fi
  90.  
  91.     echo
  92.         echo "Downloading to device $1 on port $usb_port mounted on $2"
  93.     echo
  94.         rsync -a /home/bom/bom_compartilhar "$2"/
  95.         ;;
  96.  
  97.     "2-1" )
  98.     echo
  99.     echo "Changing Scroll Lock to ON"
  100.     setleds +scroll < $keyboard
  101.     echo
  102.         echo "Uploading from device $1 on port $usb_port mounted on $2"
  103.     echo
  104.         rsync -a "$2"/bom_compartilhar /home/bom/
  105.         ;;
  106.  
  107.     "" )
  108.         echo "usb port for device \"$1\" could not be determined"
  109.         exit 1
  110.         ;;
  111.  
  112.     * )
  113.         echo "usb port $usb_port for device $1 ignored"
  114.  
  115. esac
  116.  
  117. devmon --unmount $1
  118. echo
  119. echo "Changing Caps Lock to ON and the others to OFF"
  120. setleds -num +caps -scroll < $keyboard
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement