Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- clear
- if [ "$USER" != "root" ]
- then
- echo "Please execute as root"
- echo "sudo ./install_lite.sh"
- exit
- fi
- cd ~/
- echo "######################################"
- echo "# Raspbian Lite Installer #"
- echo "#------------------------------------#"
- echo "# Author: Jakob Schaffarczyk #"
- echo "# Version: 0.0.1 #"
- echo "# Date: 19. April 2017 #"
- echo "# Contact: jaschaffarczyk(AT)gmx.net #"
- echo "# #"
- echo "# Info: Autocomplete enabled! #"
- echo "######################################"
- echo ""
- echo "Choose your SD-Card or USB Storage:"
- echo "Please remove all external devices"
- echo "except of your SD-Card before forwarding!"
- echo ""
- echo ""
- fdisk -l | grep "Disk /"
- echo ""
- echo "Filesystem: "
- read -e filesystem
- echo ""
- echo "This is the filesystem you choosed: $filesystem"
- echo ""
- echo ""
- echo "Do you really want to overwrite $filesystem?"
- echo "(n) No (y) Yes"
- read answer
- if [ "$answer" != "y" ]
- then
- echo "See you soon"
- sleep 1
- clear
- exit
- fi
- if [ "$answer" == "y" ]
- then
- clear
- echo "umount $filesystem"
- umount -fl $filesystem* 2> /dev/null
- echo "umounted $filesystem and all its partitions"
- echo ""
- echo "Volume label: (default: RJLite)"
- read volume
- if [ "$volume" == "" ]
- then
- volume="RJLite"
- fi
- echo "Create ext4 partition on $filesystem called $volume"
- mkfs.ext4 -L $volume $filesystem 2> /dev/null
- echo "created ext4 partition on $filesystem called $volume"
- echo ""
- echo ""
- echo "Is there an existing image?"
- echo "(y) Yes (n) No"
- read -e answer
- if [ "$answer" != "y" ]
- then
- clear
- downloadlink="https://downloads.raspberrypi.org/raspbian_lite_latest"
- wget -c $downloadlink
- mkdir RJLite
- mv raspbian_lite_latest RJLite
- cd RJLite
- unzip raspbian_lite_latest
- imagefile=`ls | grep img`
- echo ""
- echo "Write $imagefile to $filesystem"
- dd if=$imagefile of=$filesystem bs=1M conv=fsync
- echo "Wrote $imagepath to $filesystem"
- fi
- if [ "$answer" == "y" ]
- then
- clear
- echo "searching for images ..."
- pwd
- find | grep "raspbian-jessie-lite"
- echo ""
- echo "Path to image file:"
- read -e imagepath
- echo ""
- echo "Write $imagepath to $filesystem"
- dd if=$imagepath of=$filesystem bs=1M conv=fsync
- echo "Wrote $imagepath to $filesystem"
- fi
- clear
- user=`users`
- bootdir=/media/$user/boot
- rootdir=/media/$user/root
- sshdir=/home/$user/.ssh
- rootsshdir=/$USER/.ssh
- rm -rf $bootdir $rootdir
- mkdir $bootdir
- mkdir $rootdir
- echo "Define boot and root partition of $hostn"
- blkid -o list | grep $filesystem
- echo "Boot partition: (mostly the first partition)"
- read -e boot
- echo "Root partition: (mostly the second partition)"
- read -e root
- echo "Mount $boot to $bootdir"
- mount $boot $bootdir
- echo "Mount $root to $rootdir"
- mount $root $rootdir
- #clear
- echo "Create ssh file on $boot"
- touch $bootdir/ssh
- echo ""
- echo ""
- echo "Set WIFI settings"
- echo ""
- echo "Your hostname: (default: raspberrypi)"
- read -e hostn
- if [ "$hostn" == "" ]
- then
- hostn="raspberrypi"
- fi
- echo $hostn > $rootdir/etc/hostname
- echo "Your WIFI SSID:"
- read ssid
- echo ""
- echo "Your WIFI PSK:"
- read psk
- echo "" >> $rootdir/etc/wpa_supplicant/wpa_supplicant.conf
- echo "network={" >> $rootdir/etc/wpa_supplicant/wpa_supplicant.conf
- echo " ssid=\"$ssid\"" >> $rootdir/etc/wpa_supplicant/wpa_supplicant.conf
- echo " psk=\"$psk\"" >> $rootdir/etc/wpa_supplicant/wpa_supplicant.conf
- echo "}" >> $rootdir/etc/wpa_supplicant/wpa_supplicant.conf
- echo ""
- echo ""
- echo "Change authentication from manual to dhcp"
- cp $rootdir/etc/network/interfaces $rootdir/etc/network/interfaces.bak
- sed -e 's/manual/dhcp/g' $rootdir/etc/network/interfaces.bak > $rootdir/etc/network/interfaces
- echo ""
- echo "Create authorized_keys file in .ssh folder?"
- echo "This allows you to connect to $hostn without a password."
- echo "(y) yes (n) no"
- read -e answer
- if [ "$answer" == "y" ]
- then
- ssh-keygen -t rsa
- mv $rootsshdir/id_rsa $sshdir/
- mv $rootsshdir/id_rsa.pub $sshdir/
- mv $sshdir/id_rsa $sshdir/id_rsa.old
- mv $sshdir/id_rsa.pub $sshdir/id_rsa.pub.old
- sed -e "s/root/$user/g" $sshdir/id_rsa.old > $sshdir/id_rsa
- sed -e "s/root/$user/g" $sshdir/id_rsa.pub.old > $sshdir/id_rsa.pub
- mkdir $rootdir/home/pi/.ssh
- cp $sshdir/id_rsa.pub $rootdir/home/pi/.ssh/authorized_keys
- fi
- echo ""
- echo "Successfully created authorized_keys file"
- echo ""
- echo ""
- echo "Disable PasswordAuthentication? (enhances security enormously)"
- read -e answer
- if [ "$answer" == "y" ]
- then
- sed -i '52 s/#/ /' $rootdir/etc/ssh/sshd_config
- fi
- clear
- sudo umount -fl $bootdir $rootdir
- sudo rm -rf $rootdir
- sudo rm -rf $bootdircd
- echo "You've successfully installed Raspbian Jessie Lite on your storage"
- echo "Bye"
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement