usb.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #!/bin/bash
  2. Version=`cat build_node.sh | grep -Po "(?<=Version=)([0-9]|\.)*(?=\s|$)"`
  3. echo -e "\e[93mLitecoincash Headless Node builder $Version USB Tool\e[0m"
  4. echo -e "Author : wareck@gmail.com"
  5. f2fs_="NO" # add YES for f2fs, NO for ext4
  6. sda=""
  7. sdb=""
  8. sdc=""
  9. sdd=""
  10. sda=`ls -n /dev/disk/by-uuid/ | grep "sda" | awk '{print$9}'` >/dev/null
  11. sdb=`ls -n /dev/disk/by-uuid/ | grep "sdb" | awk '{print$9}'` >/dev/null
  12. sdc=`ls -n /dev/disk/by-uuid/ | grep "sdc" | awk '{print$9}'` >/dev/null
  13. sdd=`ls -n /dev/disk/by-uuid/ | grep "sdd" | awk '{print$9}'` >/dev/null
  14. function error_config {
  15. echo -e "\nChoose your file filesystem first:"
  16. echo "nano usb.sh"
  17. echo "edit f2fs=\"YES\" for f2fs or f2fs=\"NO\" for ext4"
  18. echo "save and run again ./usb.sh"
  19. echo ""
  20. exit
  21. }
  22. if [ -z $f2fs_ ]; then error_config && exit ;fi
  23. if ! [[ $f2fs_ = "YES" || $f2fs_ = "NO" ]]
  24. then
  25. echo $f2fs_
  26. error_config
  27. fi
  28. if [ -z $sda ];then sda_p=0; else sda_p=1;fi
  29. if [ -z $sdb ];then sdb_p=0; else sdb_p=1;fi
  30. if [ -z $sdc ];then sdc_p=0; else sdc_p=1;fi
  31. if [ -z $sdd ];then sdd_p=0; else sdd_p=1;fi
  32. num=$(($sda_p + $sdb_p + $sdc_p + $sdd_p))
  33. echo ""
  34. if ! [ $num = 1 ]
  35. then
  36. echo -e "More than one USB drive."
  37. echo -e "\e[33mCan't continue automaticaly\e[0m."
  38. echo -e "Please remove one USB drive or do it manualy..."
  39. echo -e
  40. exit
  41. else
  42. echo -e "Drive detected => \e[32mUUID=$sda\e[0m"
  43. fi
  44. if ! grep -q $sda /etc/fstab
  45. then
  46. if [ -f /tmp/tmp ]; then rm /tmp/tmp ;fi
  47. if [ $f2fs_ = "YES" ]
  48. then
  49. sudo apt-get install f2fs-tools -y
  50. cat <<'EOF'>> /tmp/tmp
  51. #USB Drive for OkCash
  52. UUID=SDA /home/pi/.litecoincash f2fs defaults,noatime 0 1
  53. EOF
  54. else
  55. cat <<'EOF'>> /tmp/tmp
  56. #USB Drive for OkCash
  57. UUID=SDA /home/pi/.litecoincash ext4 defaults,noatime 0 1
  58. EOF
  59. fi
  60. sed -i "s/SDA/$sda/" /tmp/tmp
  61. sed -i "s/pi/$USER/" /tmp/tmp
  62. sudo bash -c "cat /tmp/tmp >> /etc/fstab"
  63. echo -e "\n\e[95mLines added to /etc/fstab:\e[0m"
  64. tail -n +2 /tmp/tmp
  65. echo -e ""
  66. sleep 2
  67. else
  68. echo -e ""
  69. echo -e "Drive is already defined in /etc/fstab."
  70. echo -e ""
  71. sleep 1
  72. fi
  73. if [ ! -d /home/$USER/.litecoincash ]
  74. then
  75. echo -e "\e[95mCreate directory:\e[0m"
  76. echo -e "mkdir /home/$USER/.litecoincash"
  77. mkdir /home/$USER/.litecoincash
  78. sudo chown -R $USER /home/$USER/.litecoincash
  79. sudo chmod -R 777 /home/$USER/.litecoincash
  80. echo -e "Done."
  81. echo -e
  82. fi
  83. echo -e "\e[95mMount drive:\e[0m"
  84. sudo chown -R $USER /home/$USER/.litecoincash
  85. sudo chmod -R 777 /home/$USER/.litecoincash
  86. if mountpoint -q "/home/$USER/.litecoincash"
  87. then
  88. echo -e "Already mounted."
  89. echo -e "Done."
  90. echo -e
  91. else
  92. sudo mount /home/$USER/.litecoincash
  93. echo "Done."
  94. echo -e
  95. fi
  96. echo -e "\e[95mDirectory Check:\e[0m"
  97. ls -w 2 /home/$USER/.litecoincash
  98. echo -e