Advertisement
TimeMen

install-lite.sh

Apr 21st, 2017
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.85 KB | None | 0 0
  1. #!/bin/bash
  2. clear
  3. if [ "$USER" != "root" ]
  4. then
  5.     echo "Please execute as root"
  6.     echo "sudo ./install_lite.sh"
  7.     exit
  8. fi
  9. cd ~/
  10.  
  11. echo "######################################"
  12. echo "#       Raspbian Lite Installer      #"
  13. echo "#------------------------------------#"
  14. echo "# Author:  Jakob Schaffarczyk        #"
  15. echo "# Version: 0.0.1                     #"
  16. echo "# Date:    19. April 2017            #"
  17. echo "# Contact: jaschaffarczyk(AT)gmx.net #"
  18. echo "#                                    #"
  19. echo "# Info: Autocomplete enabled!        #"
  20. echo "######################################"
  21. echo ""
  22. echo "Choose your SD-Card or USB Storage:"
  23. echo "Please remove all external devices"
  24. echo "except of your SD-Card before forwarding!"
  25. echo ""
  26. echo ""
  27. fdisk -l | grep "Disk /"
  28. echo ""
  29. echo "Filesystem: "
  30. read -e filesystem
  31. echo ""
  32. echo "This is the filesystem you choosed: $filesystem"
  33. echo ""
  34. echo ""
  35. echo "Do you really want to overwrite $filesystem?"
  36. echo "(n) No   (y) Yes"
  37. read answer
  38.  
  39. if [ "$answer" != "y" ]
  40. then
  41.     echo "See you soon"
  42.     sleep 1
  43.     clear
  44.     exit
  45. fi
  46.  
  47. if [ "$answer" == "y" ]
  48. then
  49.     clear
  50.     echo "umount $filesystem"
  51.     umount -fl $filesystem* 2> /dev/null
  52.     echo "umounted $filesystem and all its partitions"
  53.     echo ""
  54.     echo "Volume label: (default: RJLite)"
  55.     read volume
  56.     if [ "$volume" == "" ]
  57.     then
  58.         volume="RJLite"
  59.     fi
  60.     echo "Create ext4 partition on $filesystem called $volume"
  61.     mkfs.ext4 -L $volume $filesystem 2> /dev/null
  62.     echo "created ext4 partition on $filesystem called $volume"
  63.     echo ""
  64.     echo ""
  65.     echo "Is there an existing image?"
  66.     echo "(y) Yes   (n) No"
  67.     read -e answer
  68.     if [ "$answer" != "y" ]
  69.     then
  70.         clear
  71.         downloadlink="https://downloads.raspberrypi.org/raspbian_lite_latest"
  72.         wget -c $downloadlink
  73.         mkdir RJLite
  74.         mv raspbian_lite_latest RJLite
  75.         cd RJLite
  76.         unzip raspbian_lite_latest
  77.         imagefile=`ls | grep img`
  78.  
  79.         echo ""
  80.         echo "Write $imagefile to $filesystem"
  81.         dd if=$imagefile of=$filesystem bs=1M conv=fsync
  82.         echo "Wrote $imagepath to $filesystem"
  83.     fi
  84.  
  85.     if [ "$answer" == "y" ]
  86.     then
  87.         clear
  88.         echo "searching for images ..."
  89.         pwd
  90.         find | grep "raspbian-jessie-lite"
  91.         echo ""
  92.         echo "Path to image file:"
  93.         read -e imagepath
  94.         echo ""
  95.         echo "Write $imagepath to $filesystem"
  96.         dd if=$imagepath of=$filesystem bs=1M conv=fsync
  97.         echo "Wrote $imagepath to $filesystem"
  98.     fi
  99.  
  100.     clear
  101.     user=`users`
  102.     bootdir=/media/$user/boot
  103.     rootdir=/media/$user/root
  104.     sshdir=/home/$user/.ssh
  105.     rootsshdir=/$USER/.ssh
  106.     rm -rf $bootdir $rootdir
  107.     mkdir $bootdir
  108.     mkdir $rootdir
  109.     echo "Define boot and root partition of $hostn"
  110.     blkid -o list | grep $filesystem
  111.     echo "Boot partition: (mostly the first partition)"
  112.     read -e boot
  113.     echo "Root partition: (mostly the second partition)"
  114.     read -e root
  115.     echo "Mount $boot to $bootdir"
  116.     mount $boot $bootdir
  117.     echo "Mount $root to $rootdir"
  118.     mount $root $rootdir
  119.     #clear
  120.     echo "Create ssh file on $boot"
  121.     touch $bootdir/ssh
  122.     echo ""
  123.     echo ""
  124.     echo "Set WIFI settings"
  125.     echo ""
  126.     echo "Your hostname: (default: raspberrypi)"
  127.     read -e hostn
  128.     if [ "$hostn" == "" ]
  129.     then
  130.         hostn="raspberrypi"
  131.     fi
  132.     echo $hostn > $rootdir/etc/hostname
  133.     echo "Your WIFI SSID:"
  134.     read ssid
  135.     echo ""
  136.     echo "Your WIFI PSK:"
  137.     read psk
  138.     echo "" >> $rootdir/etc/wpa_supplicant/wpa_supplicant.conf
  139.     echo "network={" >> $rootdir/etc/wpa_supplicant/wpa_supplicant.conf
  140.     echo "        ssid=\"$ssid\"" >> $rootdir/etc/wpa_supplicant/wpa_supplicant.conf
  141.     echo "        psk=\"$psk\"" >> $rootdir/etc/wpa_supplicant/wpa_supplicant.conf
  142.     echo "}" >> $rootdir/etc/wpa_supplicant/wpa_supplicant.conf
  143.     echo ""
  144.     echo ""
  145.     echo "Change authentication from manual to dhcp"
  146.     cp $rootdir/etc/network/interfaces $rootdir/etc/network/interfaces.bak
  147.     sed -e 's/manual/dhcp/g' $rootdir/etc/network/interfaces.bak > $rootdir/etc/network/interfaces
  148.     echo ""
  149.     echo "Create authorized_keys file in .ssh folder?"
  150.     echo "This allows you to connect to $hostn without a password."
  151.     echo "(y) yes   (n) no"
  152.     read -e answer
  153.     if [ "$answer" == "y" ]
  154.     then
  155.         ssh-keygen -t rsa
  156.         mv $rootsshdir/id_rsa $sshdir/
  157.         mv $rootsshdir/id_rsa.pub $sshdir/
  158.         mv $sshdir/id_rsa $sshdir/id_rsa.old
  159.         mv $sshdir/id_rsa.pub $sshdir/id_rsa.pub.old
  160.         sed -e "s/root/$user/g" $sshdir/id_rsa.old > $sshdir/id_rsa
  161.         sed -e "s/root/$user/g" $sshdir/id_rsa.pub.old > $sshdir/id_rsa.pub
  162.         mkdir $rootdir/home/pi/.ssh
  163.         cp $sshdir/id_rsa.pub $rootdir/home/pi/.ssh/authorized_keys
  164.     fi
  165.     echo ""
  166.     echo "Successfully created authorized_keys file"
  167.     echo ""
  168.     echo ""
  169.     echo "Disable PasswordAuthentication? (enhances security enormously)"
  170.     read -e answer
  171.     if [ "$answer" == "y" ]
  172.     then
  173.         sed -i '52 s/#/ /' $rootdir/etc/ssh/sshd_config
  174.     fi
  175.     clear
  176.     sudo umount -fl $bootdir $rootdir
  177.     sudo rm -rf $rootdir
  178.     sudo rm -rf $bootdircd
  179.     echo "You've successfully installed Raspbian Jessie Lite on your storage"
  180.     echo "Bye"
  181. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement