Advertisement
xiq

Untitled

xiq
Dec 20th, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 11.92 KB | None | 0 0
  1. #
  2. # Raspberry Pi Setup Script Verion 2.1
  3. # Date 20/12/2017
  4. # Modification: Modified the initial setup script to use BerryBoot so the user can use multiple
  5. # operating systems on the Raspberry Pi at once. The script is now referred to as a setup script rather
  6. # than an install script
  7. #Date 27/05/2016
  8. # Initial install script
  9. # !/bin/bash
  10. # Quit on error
  11. # nano /etc/ssh/sshd_config
  12. # PermitRootLogin without-password
  13. # PermitRootLogin yes
  14. # /etc/init.d/ssh restart
  15. set -e
  16. set -x
  17. dated="2016-05-27"
  18. deb_download="https://downloads.raspberrypi.org/raspbian_latest"
  19. src="-src"
  20. path="/sbin/"
  21. file="route"
  22. dispmanxpass=""
  23. deb_release="raspbian_latest"
  24. home="/home/pi/"
  25. user="pi"
  26. root="root"
  27. cron="/var/spool/cron/crontabs/"$user"
  28. md="http://mirrordirector.raspbian.org/raspbian/"
  29. archive="http://archive.raspbian.org/raspbian"
  30. src="-src"
  31. #Network settings
  32. country=AU
  33. #Store eth0 ip address in a variable for use later
  34. eth0ip=""
  35. #Store Wlan0 ip address in a variable for use later
  36. wlan0ip=""
  37. netmask=""
  38. network=""
  39. gateway=""
  40. broadcast=""
  41. dns1=""
  42. dns2=""
  43. hamnetwork=""
  44. #only change homegroup/workgroup if it
  45. #is not the default for the operating system
  46. homegroup=""
  47. homenetwork=""
  48. psk=""
  49. hs=""
  50. hspsk=""
  51. #User variables (change to suit)
  52. #image=$(find $pwd -type f -name "deb_release")
  53. #echo "$image"
  54. #Check image exists else download
  55. #if !["$image$directory$deb_release"] ; then
  56.     #echo "-net 0.0.0.0 gw 10.1.1.1 eth0" > $path$file
  57.     #deb_local_mirror="http://debian.kmp.or.at:3142/debian"
  58.     #deb_download="$url$downloads$deb_mirror$deb_release"
  59.     #wget "$deb_download"
  60. #fi
  61.  
  62. #Check image path is set
  63. #if ["$image$directory$deb_release"] then
  64. #  dd if="$image$directory$deb_release" of=$device bs=512 count=1
  65. #fi
  66. raspi-config
  67. path="/boot/"
  68. file="ssh"
  69. pidir="/media/pi/"
  70. rootfs=$pidir"rootfs"
  71. data=$pidir"data"
  72. storage=$pidir"storage"
  73. echo ""> $path$file
  74. path="/etc/apt/"
  75. file="sources.list"
  76. sed -i "s/'#deb-src/deb-src'/g" $path$file
  77. file="weekly.sh"
  78. echo "sudo apt-get update
  79. sudo apt-get upgrade
  80. sudo apt-get dist-upgrade" > $home$file
  81. echo @weekly $home$file | tee -a $cron
  82. rm $home$file
  83. host=$(hostname)
  84. file="monthly.sh"
  85. echo "sudo rpi-update sudo apt-get install raspberrypi-ui-mods
  86. #sudo dd bs=4M if=/dev/sdb of=raspbian.img
  87. rsync -avz -e ssh pi@"$host$sambapath"
  88. sudo apt-get clean" > $home$file
  89. echo @monthly $home$file | tee -a $cron
  90. rm $home$file
  91. file="reboot.sh"
  92. echo "" > $home$file
  93. echo @reboot $home$file | tee -a $cron
  94. rm $home$file
  95. # cat /etc/os-release
  96. OS=$(uname -s)
  97. ARCH=$(uname -m)
  98. #Version of Operating System
  99. #7.8 Whezzy, 8.0 Jessie
  100. VER=$(cat /etc/debian_version)
  101. path="/etc/"
  102. file="resolv.conf"
  103. echo "Generated by resolvconf
  104. domain Home
  105. nameserver "$dns1"
  106. nameserver "$dns2"" > $path$file
  107.  
  108. apt-get update -y
  109. apt-get upgrade -y
  110. apt-get dist-upgrade -y
  111. BRANCH=next rpi-update
  112. apt-get install moreutils pacman iperf nmap wget sunxi-tools libvncserver-dev libconfig++-dev -y
  113. apt-get install rsync gdisk -y
  114. apt-get install raspberrypi-ui-mods -y
  115. apt-get install ntfs-3g -y
  116. apt-get install perl -y
  117. apt-get search perl | sed -e 's/ - .*//' | xargs apt-get install -y
  118. apt-get install python-sense-emu python3-sense-emu
  119. apt-get install git-core -y
  120. apt-get install git -y
  121. apt-get install cmake -y
  122. apt-get install libusb-1.0-0-dev -y
  123. apt-get install build-essential -y
  124. apt-get install moreutils -y
  125. apt-get install wpasupplicant -y
  126. apt-get install samba samba-common-bin -y
  127. apt-get install winbind -y
  128. file="linux-firmware"
  129. if [ ! -d $home$file ]; then
  130.   git clone https://kernel.googlesource.com/pub/scm/linux/kernel/git/firmware/linux-firmware
  131. fi
  132. if [ ! -d $rootfs ]; then
  133.    mkdir $rootfs
  134. fi
  135. if [ ! -d $data ]; then
  136.     mkdir $data
  137. fi
  138. if [ ! -d $storage ]; then
  139.     mkdir $storage
  140. fi
  141. #apt-get install rbp-userland-dev-osmc
  142. apt-get install unzip
  143. # #Install Dispmanx
  144. wget https://github.com/patrikolausson/dispmanx_vnc/archive/master.zip
  145. unzip master.zip -d  $home
  146. rm master.zip
  147. cd dispmanx_vnc-master
  148. make
  149. # #Check if there is currently a lock in place, if so then exit, if not then create a lock
  150. path="/usr/bin/"
  151. if [ ! -f $path".lock" ]; then
  152.    cp dispmanx_vncserver $path
  153.    touch $path".lock"
  154.     chmod +x $path"dispmanx_vncserver"
  155.     cp dispmanx_vncserver.conf.sample /etc/dispmanx_vncserver.conf
  156.     modprobe uinput
  157.     path="/etc/"
  158.     file="dispmanx_vncserver.conf"
  159.     echo "relative = false;
  160.     port = 5900;
  161.     screen = 0;
  162.     unsafe = false;
  163.     fullscreen = false;
  164.     multi-threaded = false;
  165.     password=\"$dispmanxpass\";
  166.     frame-rate = 23;
  167.     downscale = false;
  168.     localhost = false;
  169.     vnc-params = \"\";" > $path$file
  170.     echo "[Unit]
  171.     Description=VNC Server
  172.     #After=network-online.target mediacenter.service'
  173.     #Requires=mediacenter.service
  174.    
  175.     [Service]
  176.     Restart=on-failure
  177.     RestartSec=30
  178.     Nice=15
  179.     User=root
  180.     Group=root
  181.     Type=simple
  182.     ExecStartPre=/sbin/modprobe evdev
  183.     ExecStart=/usr/bin/dispmanx_vncserver
  184.     KillMode=process
  185.  
  186.     [Install]
  187.     WantedBy=multi-user.target" > "/etc/systemd/system/dispmanx_vncserver.service"
  188.      systemctl start dispmanx_vncserver.service
  189.      systemctl enable dispmanx_vncserver.service
  190.      systemctl daemon-reload
  191. fi
  192.  
  193. # # # #Wifi dropout
  194. path="/etc/modprobe.d/"
  195. file="8192cu.conf"
  196. # echo "#Disable power saving
  197. echo "options 8192cu rtw_power_mgnt=0 rtw_enusbss=1 rtw_ips_mode=1"> $path$file
  198.  cp /etc/apt/sources.list /var/backups/sources.list
  199. cp /etc/network/interfaces /var/backups/interfaces
  200. cp /etc/wpa_supplicant/wpa_supplicant.conf /var/backups/wpa_supplicant.conf
  201. rsync -avzh /var/lib/dpkg/. /var/backups/dpkg/
  202. path="/etc/wpa_supplicant/"
  203. file="wpa_supplicant.conf"
  204. echo "country="$country"
  205. ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
  206. ap_scan=1
  207. update_config=1" > $path$file
  208.  
  209. wpa_passphrase $homenetwork $psk >> $path$file
  210. wpa_passphrase $hs $hspsk >> $path$file
  211. sed -i "s/"#psk="//g" $path$file
  212. sed -i "s/\"$psk\"//g" $path$file
  213. sed -i "s/"#hspsk="//g" $path$file
  214. #Remove the double quotes  leftover from the old password.
  215. sed -i "s/\"$hspsk\"//g" $path$file
  216. path="/etc/network/interfaces.d/"
  217. file="wlan0"
  218. echo "auto wlan0
  219. iface wlan0 inet dhcp
  220. wpa-essid=$homenetwork
  221. wpa-psk=$psk
  222. auto wlan1
  223. iface wlan1 inet dhcp
  224. wpa-essid=$homenetwork
  225. wpa-psk=$psk"> $path$file
  226.  
  227. if [ $VER="8.0" ]; then
  228.     # #DHCP Server
  229.     path="/etc/"
  230.     file="dhcpcd.conf"
  231.     echo "# A sample configuration for dhcpcd.
  232.     # See dhcpcd.conf(5) for details.
  233.  
  234.     # Allow users of this group to interact with dhcpcd via the control socket.
  235.     # controlgroup wheel
  236.  
  237.     # Inform the DHCP server of our hostname for DDNS.
  238.     # hostname
  239.  
  240.     # Use the hardware address of the interface for the Client ID.
  241.     # clientid
  242.     # or
  243.     # Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
  244.     # duid
  245.  
  246.     # Persist interface configuration when dhcpcd exits.
  247.     # persistent
  248.  
  249.     # Rapid commit support.
  250.     Safe to enable by default because it requires the equivalent option set
  251.     on the server to actually work.
  252.     option rapid_commit
  253.  
  254.     A list of options to request from the DHCP server.
  255.     option domain_name_servers, domain_name, domain_search, host_name
  256.     option classless_static_routes
  257.     Most distributions have NTP support.
  258.     option ntp_servers
  259.     Respect the network MTU.
  260.     Some interface drivers reset when changing the MTU so disabled by default.
  261.     option interface_mtu
  262.  
  263.     A ServerID is required by RFC2131.
  264.     require dhcp_server_identifier
  265.  
  266.     Generate Stable Private IPv6 Addresses instead of hardware based ones
  267.     slaac private
  268.  
  269.     A hook script is provided to lookup the hostname if not set by the DHCP
  270.     server, but it should not be run by default.
  271.     nohook lookup-hostname
  272.     interface eth0
  273.     static ip_address="$eth0ip"/24
  274.     static network="$network"
  275.     static routers="$gateway"
  276.     static broadcast="$broadcast"
  277.     static domain_name_server="$gateway", "$dns1", "$dns2"
  278.     interface wlan0
  279.     static ip_address="$wlan0ip"/24
  280.     static network="$network"
  281.     static routers="$gateway"
  282.     static broadcast="$broadcast"
  283.     static domain_name_server="$gateway", "$dns1", "$dns2"">$path$file
  284. elif [ $VER="7.8" ]; then  #Whezzy
  285.     path="/etc/network/"
  286.     file="interfaces"
  287.     echo "auto lo
  288.     iface lo inet loopback
  289.     iface eth0 inet static
  290.     address=$eth0ip
  291.     netmask=$netmask
  292.     network=$network
  293.     gateway=$gateway
  294.     broadcast=$broadcast
  295.     auto wlan0
  296.     iface wlan0 inet static
  297.     address=$wlan0ip
  298.     netmask=$netmask
  299.     network=$network
  300.     gateway=$gateway
  301.     broadcast=$broadcast
  302.         wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
  303.     allow-hotplug wlan1
  304.     iface wlan1 inet manual
  305.         wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
  306.     iface default inet dhcp" >$path$file
  307. fi
  308.  # Keyboard Layout
  309. path="/etc/default/"
  310. file="keyboard"
  311. perl -e 's/#XKBLAYOUT="gb"/KBLAYOUT="us"/g' $path$file
  312. #Samba
  313. path="/etc/samba/"
  314. file="smb.conf"
  315. cp $path$file /var/backups/$file
  316. sambaPath=$data
  317. mkdir -p $sambaPath
  318. chown -R root:$user $sambaPath
  319. chmod -R ug+rwx,o+rx-w $sambaPath
  320. if [ ! -d  $sambaPath"/" ]; then
  321.    mkdir $sambaPath"/documents"
  322.    mkdir $sambaPath"/music"
  323.    mkdir $sambaPath"/pictures"
  324.    mkdir $sambaPath"/videos"
  325.    mkdir $sambaPath"/RPiServerBackup"
  326.    mkdir $sambaPath"/OSMCBackup"
  327.    mkdir $sambaPath"/DVBscan"
  328.    mkdir $sambaPath"/TVHDebug"
  329. fi
  330.  
  331. if [ ! -f $path$file".lock" ]; then
  332.     cp /usr/share/samba/smb.conf $path
  333.     sed -i "s/workgroup = WORKGROUP/workgroup = "$homegroup"/g" $path$file
  334.     sed -i 's/#   wins support = no/wins support = yes/g' $path$file
  335.     echo "[data]
  336.        comment = Raspberry Pi Share
  337.        path = "$sambaPath"
  338.        security = pi
  339.        browseable = yes
  340.        writeable = yes
  341.        readonly = no
  342.        guest ok = no
  343.        create mask = 0777
  344.        directory mask = 0777
  345.        public = no" >> $path$file
  346. fi  
  347. # #Check if there is currently a lock in place, if so then exit, if not then create a lock
  348. if [ -f $path$file".lock" ]; then
  349.     echo $path$file" is locked!"
  350. else
  351.     touch $path$file".lock"
  352. fi
  353. smbpasswd -a $user
  354. /etc/init.d/samba restart
  355.  path="/etc/"
  356.  file="nsswitch.conf"
  357.  sed -i "s/'hosts:          files mdns4_minimal [NOTFOUND=return] dns/hosts:          files mdns4_minimal [NOTFOUND=return] dns files wins'/g" $path$file
  358. path="/usr/bin/"
  359. dir="hamachi"
  360. file="logmein-hamachi_2.1.0.174-1_armhf.deb"
  361. if [ ! -d $path$dir ]; then
  362. # #Hamachi
  363. # #hamachi set-nick
  364. # #hamachi login
  365. # #hamachi create my-net secretpassword
  366. # #hamachi do-join my-net
  367. # #hamachi go-online my-net
  368. # #hamachi list
  369. # #hamachi go-offline my-net
  370. # #wget https://github.com/txt3rob/hamachi-pi/blob/master/hamachi.sh
  371. # #chmod 777 hamachi.sh
  372. # #./hamachi.sh
  373. # #echo "Please login to you hamachi account and manually add the client to the network"
  374. # #sleep 2m
  375.     echo "installing requirements"
  376.     apt-get -y install --fix-missing lsb lsb-core
  377.     echo "Downloading Hamachi"
  378.     wget https://www.vpn.net/installers/logmein-hamachi_2.1.0.174-1_armhf.deb
  379.     echo "Install Hamachi"
  380.     dpkg -i logmein-hamachi_2.1.0.174-1_armhf.deb
  381.     /etc/init.d/logmein-hamachi start
  382.     echo "installing chkconfig"
  383.     apt-get -y install chkconfig
  384.     chkconfig -s logmein-hamachi 2
  385.     echo "starting hamachi"
  386.     hamachi login
  387.     echo "please enter your logmein account email address"
  388.     read email
  389.     hamachi attach $email
  390.     echo "please enter your raspberry pi nickname"
  391.     read nick
  392.     hamachi set-nick $nick
  393.     echo "your pi should now be on your hamachi network"
  394.     hamachi do-join $hamnetwork
  395.     hamachi go-online $hamnetwork
  396. elif [ -d $path$file ]; then
  397. echo $path$file "already exists!"
  398. fi
  399. chown pi:pi -R $home
  400.  
  401. #FSTAB
  402. path="/etc/"
  403. file="fstab"
  404. tee "${path}${file}" <<-EOF
  405.     proc            /proc           proc    defaults          0       0
  406.     /dev/mmcblk0p1  /boot           vfat    defaults          0       2
  407.     /dev/mmcblk0p2  /               ext4    defaults,noatime 0       1
  408.     /dev/sdb1 $rootfs ext4 nofail 0 1
  409.     /dev/sdb2 $data ext4 nofail 0 1
  410.     /dev/sda1 $storage ntfs nofail 0 1"
  411. EOF
  412.  
  413. path="/etc/udev/rules.d/"
  414. tee "${path}usb.sh" <<-EOF
  415.     #!/bin/bash
  416.     sudo mount -a
  417. EOF
  418.  
  419. file="10-usb.rules"
  420. tee "${path}${file}" <<-EOF
  421.     KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}!="?*", SUBSYSTEMS=="usb", RUN+="usb.sh"
  422. EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement