Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # Raspberry Pi Setup Script Verion 2.1
- # Date 20/12/2017
- # Modification: Modified the initial setup script to use BerryBoot so the user can use multiple
- # operating systems on the Raspberry Pi at once. The script is now referred to as a setup script rather
- # than an install script
- #Date 27/05/2016
- # Initial install script
- # !/bin/bash
- # Quit on error
- # nano /etc/ssh/sshd_config
- # PermitRootLogin without-password
- # PermitRootLogin yes
- # /etc/init.d/ssh restart
- set -e
- set -x
- dated="2016-05-27"
- deb_download="https://downloads.raspberrypi.org/raspbian_latest"
- src="-src"
- path="/sbin/"
- file="route"
- dispmanxpass=""
- deb_release="raspbian_latest"
- home="/home/pi/"
- user="pi"
- root="root"
- cron="/var/spool/cron/crontabs/"$user"
- md="http://mirrordirector.raspbian.org/raspbian/"
- archive="http://archive.raspbian.org/raspbian"
- src="-src"
- #Network settings
- country=AU
- #Store eth0 ip address in a variable for use later
- eth0ip=""
- #Store Wlan0 ip address in a variable for use later
- wlan0ip=""
- netmask=""
- network=""
- gateway=""
- broadcast=""
- dns1=""
- dns2=""
- hamnetwork=""
- #only change homegroup/workgroup if it
- #is not the default for the operating system
- homegroup=""
- homenetwork=""
- psk=""
- hs=""
- hspsk=""
- #User variables (change to suit)
- #image=$(find $pwd -type f -name "deb_release")
- #echo "$image"
- #Check image exists else download
- #if !["$image$directory$deb_release"] ; then
- #echo "-net 0.0.0.0 gw 10.1.1.1 eth0" > $path$file
- #deb_local_mirror="http://debian.kmp.or.at:3142/debian"
- #deb_download="$url$downloads$deb_mirror$deb_release"
- #wget "$deb_download"
- #fi
- #Check image path is set
- #if ["$image$directory$deb_release"] then
- # dd if="$image$directory$deb_release" of=$device bs=512 count=1
- #fi
- raspi-config
- path="/boot/"
- file="ssh"
- pidir="/media/pi/"
- rootfs=$pidir"rootfs"
- data=$pidir"data"
- storage=$pidir"storage"
- echo ""> $path$file
- path="/etc/apt/"
- file="sources.list"
- sed -i "s/'#deb-src/deb-src'/g" $path$file
- file="weekly.sh"
- echo "sudo apt-get update
- sudo apt-get upgrade
- sudo apt-get dist-upgrade" > $home$file
- echo @weekly $home$file | tee -a $cron
- rm $home$file
- host=$(hostname)
- file="monthly.sh"
- echo "sudo rpi-update sudo apt-get install raspberrypi-ui-mods
- #sudo dd bs=4M if=/dev/sdb of=raspbian.img
- rsync -avz -e ssh pi@"$host$sambapath"
- sudo apt-get clean" > $home$file
- echo @monthly $home$file | tee -a $cron
- rm $home$file
- file="reboot.sh"
- echo "" > $home$file
- echo @reboot $home$file | tee -a $cron
- rm $home$file
- # cat /etc/os-release
- OS=$(uname -s)
- ARCH=$(uname -m)
- #Version of Operating System
- #7.8 Whezzy, 8.0 Jessie
- VER=$(cat /etc/debian_version)
- path="/etc/"
- file="resolv.conf"
- echo "Generated by resolvconf
- domain Home
- nameserver "$dns1"
- nameserver "$dns2"" > $path$file
- apt-get update -y
- apt-get upgrade -y
- apt-get dist-upgrade -y
- BRANCH=next rpi-update
- apt-get install moreutils pacman iperf nmap wget sunxi-tools libvncserver-dev libconfig++-dev -y
- apt-get install rsync gdisk -y
- apt-get install raspberrypi-ui-mods -y
- apt-get install ntfs-3g -y
- apt-get install perl -y
- apt-get search perl | sed -e 's/ - .*//' | xargs apt-get install -y
- apt-get install python-sense-emu python3-sense-emu
- apt-get install git-core -y
- apt-get install git -y
- apt-get install cmake -y
- apt-get install libusb-1.0-0-dev -y
- apt-get install build-essential -y
- apt-get install moreutils -y
- apt-get install wpasupplicant -y
- apt-get install samba samba-common-bin -y
- apt-get install winbind -y
- file="linux-firmware"
- if [ ! -d $home$file ]; then
- git clone https://kernel.googlesource.com/pub/scm/linux/kernel/git/firmware/linux-firmware
- fi
- if [ ! -d $rootfs ]; then
- mkdir $rootfs
- fi
- if [ ! -d $data ]; then
- mkdir $data
- fi
- if [ ! -d $storage ]; then
- mkdir $storage
- fi
- #apt-get install rbp-userland-dev-osmc
- apt-get install unzip
- # #Install Dispmanx
- wget https://github.com/patrikolausson/dispmanx_vnc/archive/master.zip
- unzip master.zip -d $home
- rm master.zip
- cd dispmanx_vnc-master
- make
- # #Check if there is currently a lock in place, if so then exit, if not then create a lock
- path="/usr/bin/"
- if [ ! -f $path".lock" ]; then
- cp dispmanx_vncserver $path
- touch $path".lock"
- chmod +x $path"dispmanx_vncserver"
- cp dispmanx_vncserver.conf.sample /etc/dispmanx_vncserver.conf
- modprobe uinput
- path="/etc/"
- file="dispmanx_vncserver.conf"
- echo "relative = false;
- port = 5900;
- screen = 0;
- unsafe = false;
- fullscreen = false;
- multi-threaded = false;
- password=\"$dispmanxpass\";
- frame-rate = 23;
- downscale = false;
- localhost = false;
- vnc-params = \"\";" > $path$file
- echo "[Unit]
- Description=VNC Server
- #After=network-online.target mediacenter.service'
- #Requires=mediacenter.service
- [Service]
- Restart=on-failure
- RestartSec=30
- Nice=15
- User=root
- Group=root
- Type=simple
- ExecStartPre=/sbin/modprobe evdev
- ExecStart=/usr/bin/dispmanx_vncserver
- KillMode=process
- [Install]
- WantedBy=multi-user.target" > "/etc/systemd/system/dispmanx_vncserver.service"
- systemctl start dispmanx_vncserver.service
- systemctl enable dispmanx_vncserver.service
- systemctl daemon-reload
- fi
- # # # #Wifi dropout
- path="/etc/modprobe.d/"
- file="8192cu.conf"
- # echo "#Disable power saving
- echo "options 8192cu rtw_power_mgnt=0 rtw_enusbss=1 rtw_ips_mode=1"> $path$file
- cp /etc/apt/sources.list /var/backups/sources.list
- cp /etc/network/interfaces /var/backups/interfaces
- cp /etc/wpa_supplicant/wpa_supplicant.conf /var/backups/wpa_supplicant.conf
- rsync -avzh /var/lib/dpkg/. /var/backups/dpkg/
- path="/etc/wpa_supplicant/"
- file="wpa_supplicant.conf"
- echo "country="$country"
- ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
- ap_scan=1
- update_config=1" > $path$file
- wpa_passphrase $homenetwork $psk >> $path$file
- wpa_passphrase $hs $hspsk >> $path$file
- sed -i "s/"#psk="//g" $path$file
- sed -i "s/\"$psk\"//g" $path$file
- sed -i "s/"#hspsk="//g" $path$file
- #Remove the double quotes leftover from the old password.
- sed -i "s/\"$hspsk\"//g" $path$file
- path="/etc/network/interfaces.d/"
- file="wlan0"
- echo "auto wlan0
- iface wlan0 inet dhcp
- wpa-essid=$homenetwork
- wpa-psk=$psk
- auto wlan1
- iface wlan1 inet dhcp
- wpa-essid=$homenetwork
- wpa-psk=$psk"> $path$file
- if [ $VER="8.0" ]; then
- # #DHCP Server
- path="/etc/"
- file="dhcpcd.conf"
- echo "# A sample configuration for dhcpcd.
- # See dhcpcd.conf(5) for details.
- # Allow users of this group to interact with dhcpcd via the control socket.
- # controlgroup wheel
- # Inform the DHCP server of our hostname for DDNS.
- # hostname
- # Use the hardware address of the interface for the Client ID.
- # clientid
- # or
- # Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
- # duid
- # Persist interface configuration when dhcpcd exits.
- # persistent
- # Rapid commit support.
- Safe to enable by default because it requires the equivalent option set
- on the server to actually work.
- option rapid_commit
- A list of options to request from the DHCP server.
- option domain_name_servers, domain_name, domain_search, host_name
- option classless_static_routes
- Most distributions have NTP support.
- option ntp_servers
- Respect the network MTU.
- Some interface drivers reset when changing the MTU so disabled by default.
- option interface_mtu
- A ServerID is required by RFC2131.
- require dhcp_server_identifier
- Generate Stable Private IPv6 Addresses instead of hardware based ones
- slaac private
- A hook script is provided to lookup the hostname if not set by the DHCP
- server, but it should not be run by default.
- nohook lookup-hostname
- interface eth0
- static ip_address="$eth0ip"/24
- static network="$network"
- static routers="$gateway"
- static broadcast="$broadcast"
- static domain_name_server="$gateway", "$dns1", "$dns2"
- interface wlan0
- static ip_address="$wlan0ip"/24
- static network="$network"
- static routers="$gateway"
- static broadcast="$broadcast"
- static domain_name_server="$gateway", "$dns1", "$dns2"">$path$file
- elif [ $VER="7.8" ]; then #Whezzy
- path="/etc/network/"
- file="interfaces"
- echo "auto lo
- iface lo inet loopback
- iface eth0 inet static
- address=$eth0ip
- netmask=$netmask
- network=$network
- gateway=$gateway
- broadcast=$broadcast
- auto wlan0
- iface wlan0 inet static
- address=$wlan0ip
- netmask=$netmask
- network=$network
- gateway=$gateway
- broadcast=$broadcast
- wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
- allow-hotplug wlan1
- iface wlan1 inet manual
- wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
- iface default inet dhcp" >$path$file
- fi
- # Keyboard Layout
- path="/etc/default/"
- file="keyboard"
- perl -e 's/#XKBLAYOUT="gb"/KBLAYOUT="us"/g' $path$file
- #Samba
- path="/etc/samba/"
- file="smb.conf"
- cp $path$file /var/backups/$file
- sambaPath=$data
- mkdir -p $sambaPath
- chown -R root:$user $sambaPath
- chmod -R ug+rwx,o+rx-w $sambaPath
- if [ ! -d $sambaPath"/" ]; then
- mkdir $sambaPath"/documents"
- mkdir $sambaPath"/music"
- mkdir $sambaPath"/pictures"
- mkdir $sambaPath"/videos"
- mkdir $sambaPath"/RPiServerBackup"
- mkdir $sambaPath"/OSMCBackup"
- mkdir $sambaPath"/DVBscan"
- mkdir $sambaPath"/TVHDebug"
- fi
- if [ ! -f $path$file".lock" ]; then
- cp /usr/share/samba/smb.conf $path
- sed -i "s/workgroup = WORKGROUP/workgroup = "$homegroup"/g" $path$file
- sed -i 's/# wins support = no/wins support = yes/g' $path$file
- echo "[data]
- comment = Raspberry Pi Share
- path = "$sambaPath"
- security = pi
- browseable = yes
- writeable = yes
- readonly = no
- guest ok = no
- create mask = 0777
- directory mask = 0777
- public = no" >> $path$file
- fi
- # #Check if there is currently a lock in place, if so then exit, if not then create a lock
- if [ -f $path$file".lock" ]; then
- echo $path$file" is locked!"
- else
- touch $path$file".lock"
- fi
- smbpasswd -a $user
- /etc/init.d/samba restart
- path="/etc/"
- file="nsswitch.conf"
- sed -i "s/'hosts: files mdns4_minimal [NOTFOUND=return] dns/hosts: files mdns4_minimal [NOTFOUND=return] dns files wins'/g" $path$file
- path="/usr/bin/"
- dir="hamachi"
- file="logmein-hamachi_2.1.0.174-1_armhf.deb"
- if [ ! -d $path$dir ]; then
- # #Hamachi
- # #hamachi set-nick
- # #hamachi login
- # #hamachi create my-net secretpassword
- # #hamachi do-join my-net
- # #hamachi go-online my-net
- # #hamachi list
- # #hamachi go-offline my-net
- # #wget https://github.com/txt3rob/hamachi-pi/blob/master/hamachi.sh
- # #chmod 777 hamachi.sh
- # #./hamachi.sh
- # #echo "Please login to you hamachi account and manually add the client to the network"
- # #sleep 2m
- echo "installing requirements"
- apt-get -y install --fix-missing lsb lsb-core
- echo "Downloading Hamachi"
- wget https://www.vpn.net/installers/logmein-hamachi_2.1.0.174-1_armhf.deb
- echo "Install Hamachi"
- dpkg -i logmein-hamachi_2.1.0.174-1_armhf.deb
- /etc/init.d/logmein-hamachi start
- echo "installing chkconfig"
- apt-get -y install chkconfig
- chkconfig -s logmein-hamachi 2
- echo "starting hamachi"
- hamachi login
- echo "please enter your logmein account email address"
- read email
- hamachi attach $email
- echo "please enter your raspberry pi nickname"
- read nick
- hamachi set-nick $nick
- echo "your pi should now be on your hamachi network"
- hamachi do-join $hamnetwork
- hamachi go-online $hamnetwork
- elif [ -d $path$file ]; then
- echo $path$file "already exists!"
- fi
- chown pi:pi -R $home
- #FSTAB
- path="/etc/"
- file="fstab"
- tee "${path}${file}" <<-EOF
- proc /proc proc defaults 0 0
- /dev/mmcblk0p1 /boot vfat defaults 0 2
- /dev/mmcblk0p2 / ext4 defaults,noatime 0 1
- /dev/sdb1 $rootfs ext4 nofail 0 1
- /dev/sdb2 $data ext4 nofail 0 1
- /dev/sda1 $storage ntfs nofail 0 1"
- EOF
- path="/etc/udev/rules.d/"
- tee "${path}usb.sh" <<-EOF
- #!/bin/bash
- sudo mount -a
- EOF
- file="10-usb.rules"
- tee "${path}${file}" <<-EOF
- KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}!="?*", SUBSYSTEMS=="usb", RUN+="usb.sh"
- EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement