Skip to content

Instantly share code, notes, and snippets.

@ABeltramo
Last active April 22, 2016 19:24
Show Gist options
  • Save ABeltramo/51955d67baa45f9a203e to your computer and use it in GitHub Desktop.
Save ABeltramo/51955d67baa45f9a203e to your computer and use it in GitHub Desktop.
Launch this script to initialize, install and configure RaspberryPI

Raspberry PI Bootstrap

Series of command to start and configure an empty Raspbian image


What will be installed:

  • NodeJS
  • Transmission (Plus basic configuration)
  • MOTD
  • 192.168.1.193 IP Address
  • Static Mount point for my HD
  • TimeMachine enable (and configured)
  • Samba enable (and configured)
  • HTOP
  • NO-IP
  • MYSQL
  • UFW (basic configuration to allow previous services)
  • It also remove all the unnecessary package preinstalled on raspbian (see SlimRaspbian.sh)

Final size of the system: *~ 1,9 GB*

How to start the magic?

curl --silent --location https://gist.github.com/ABeltramo/51955d67baa45f9a203e/raw/RecoveryRPI.sh -o /home/pi/RecoveryRPI.sh
sudo sh RecoveryRPI.sh

Installing Gogs (This will require more time, building time it's really slow):

curl --silent --location https://raw.githubusercontent.com/meinside/rpi-configs/master/bin/prep_go.sh -o /home/pi/BuildGo.sh
sudo sh ./BuildGo.sh
### Wait long time for build to complete ####
sudo shutdown -r now
http://blog.meinside.pe.kr/Gogs-on-Raspberry-Pi/
proc /proc proc defaults 0 0
/dev/mmcblk0p5 /boot vfat defaults 0 2
/dev/mmcblk0p6 / ext4 defaults,noatime 0 1
# a swapfile is not a swap partition, so no using swapon|off from here on, use dphys-swapfile swap[on|off] for that
#Adding external HD
#UUID=d9b7bef2-8747-450d-b4ea-fada78890223 /mnt/externalDisk ext4 defaults 0 0
UUID=5b5b6b3d-9770-4092-9429-83c5ad70a6c9 /mnt/timeMachine ext4 defaults 0 0
#Samsung2TB
#/dev/sda1 /mnt/Samsung2TB ext4 defaults 0 0
UUID=AAD4F646D4F613F3 /mnt/externalDisk ntfs-3g uid=pi,gid=users,dmask=022,fmask=133 0 0
#!/bin/bash
let upSeconds="$(/usr/bin/cut -d. -f1 /proc/uptime)"
let secs=$((${upSeconds}%60))
let mins=$((${upSeconds}/60%60))
let hours=$((${upSeconds}/3600%24))
let days=$((${upSeconds}/86400))
UPTIME=`printf "%d days, %02dh%02dm%02ds" "$days" "$hours" "$mins" "$secs"`
# get the load averages
read one five fifteen rest < /proc/loadavg
echo "$(tput setaf 2)"
echo "
_ _ _
__ _| |__ ___| | |_ _ __ __ _ _ __ ___ ___
/ _ | |_ \ / _ \ | __| __/ _ | | _ _ \ / _ \
| (_| | |_) | __/ | |_| | | (_| |_| | | | | | __/
\__|_|____/ \___|_|\__|_| \__|_(_)_| |_| |_|\___|
"
echo "$(tput setaf 2)
.~~. .~~. `date +"%A, %e %B %Y, %r"`
'. \ ' ' / .' `uname -srmo`$(tput setaf 1)
.~ .~~~..~.
: .~.'~'.~. :
~ ( ) ( ) ~ Uptime.............: ${UPTIME}
( : '~'.~.'~' : ) Load Averages......: ${one}, ${five}, ${fifteen} (1, 5, 15 min)
~ .~ ( ) ~. ~ Memory.............: `cat /proc/meminfo | grep MemFree | awk {'print $2'}`kB $
( : '~' : ) Running Processes..: `ps ax | wc -l | tr -d " "`
'~ .~~~. ~'
'~'
$(tput sgr0)"
export PS1="\[\e[31m\]\u\[\e[m\]\[\e[36m\]@\[\e[m\]\[\e[32m\]\h\[\e[m\] \[\e[35m\]\w\[\e[m\] "
#######################################################
#! /bin/sh
case "$1" in
start)
echo "Starting noip2."
/usr/local/bin/noip2
;;
stop)
echo -n "Shutting down noip2."
killall -q -TERM /usr/local/bin/noip2
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
exit 0
#######################################################
#!/bin/bash
#Dove salvare l'output di questo script
OUT="/tmp/recovery.log"
RED='\033[0;31m'
NC='\033[0m' # No Color
#STARTING
echo "${RED}RECOVERY... STARTED!${NC}"
echo "${RED}Updating...${NC}"
sudo apt-get update > $OUT
sudo apt-get upgrade > $OUT
############################################################
echo "${RED}Installing curl${NC}"
sudo apt-get install -y curl > $OU
############################################################
echo "${RED}Removing unnecessary packets${NC}"
curl --silent --location https://gist.github.com/ABeltramo/51955d67baa45f9a203e/raw/SlimRaspbian.sh -o /home/pi/SlimRaspbian.sh
chmod +x /home/pi/SlimRaspbian.sh
sudo sh /home/pi/SlimRaspbian.sh | sudo sh
############################################################
echo "${RED}Installing nodejs${NC}"
sudo apt-get install -y nodejs > $OUT
echo "${RED}Installing nodejs dependency${NC}"
sudo npm install -g forever
sudo npm install -g forever-service
############################################################
echo "${RED}Installing transmission${NC}"
sudo apt-get install -y transmission-daemon > $OUT
sudo /etc/init.d/transmission-daemon stop > $OUT # Stop Transmission for change settings
sudo rm /var/lib/transmission-daemon/info/settings.json
sudo curl --silent --location https://gist.github.com/ABeltramo/51955d67baa45f9a203e/raw/Transmission.json -o /var/lib/transmission-daemon/info/settings.json
############################################################
echo "${RED}Cambio il MOTD${NC}"
sudo rm /home/pi/.bash_profile
sudo curl --silent --location https://gist.github.com/ABeltramo/51955d67baa45f9a203e/raw/MOTD -o /home/pi/.bash_profile
############################################################
echo "${RED}Giving 192.168.1.193 IP Address${NC}"
sudo rm /etc/network/interfaces
sudo curl --silent --location https://gist.github.com/ABeltramo/51955d67baa45f9a203e/raw/StaticIP -o /etc/network/interfaces
############################################################
echo "${RED}Creating mount point${NC}"
mkdir /mnt/externalDisk
mkdir /mnt/timeMachine
echo "${RED}Auto mount external Disk${NC}"
sudo echo "UUID=d9b7bef2-8747-450d-b4ea-fada78890223 /mnt/externalDisk ext4 defaults 0 0" >> /etc/fstab
sudo echo "UUID=5b5b6b3d-9770-4092-9429-83c5ad70a6c9 /mnt/timeMachine ext4 defaults 0 0" >> /etc/fstab
############################################################
echo "${RED}Installing samba${NC}"
sudo apt-get install -y samba samba-common-bin > $OUT
echo "${RED}Configuring samba${NC}"
sudo curl --silent --location https://gist.github.com/ABeltramo/51955d67baa45f9a203e/raw/smb.conf -o /etc/samba/smb.conf
sudo update-rc.d samba defaults
############################################################
echo "${RED}Installing for TimeMachine${NC}"
sudo apt-get install -y netatalk > $OUT
sudo update-rc.d netatalk defaults
sudo echo "/mnt/timeMachine \"Time Machine\" options:tm" >> /etc/netatalk/AppleVolumes.default
sudo service netatalk restart
############################################################
echo "${RED}Installing HTOP${NC}"
sudo apt-get install -y htop > $OUT
############################################################
echo "${RED}Installing NO-IP${NC}"
mkdir /home/pi/noip
wget -P /home/pi/noip http://www.no-ip.com/client/linux/noip-duc-linux.tar.gz
tar vzxf /home/pi/noip/noip-duc-linux.tar.gz
sudo make -C /home/pi/noip/noip-2.1.9-1
sudo make -C /home/pi/noip/noip-2.1.9-1 install
cd #Ritorno indietro
sudo /usr/local/bin/noip2
############################################################
echo "${RED}Autostarting NO-IP${NC}"
sudo curl --silent --location https://gist.github.com/ABeltramo/51955d67baa45f9a203e/raw/NoipAutostart -o /etc/init.d/noip2
sudo chmod 755 /etc/init.d/noip2
sudo update-rc.d noip2 defaults > $OUT
############################################################
echo "${RED}Installing MYSQL{NC}"
sudo apt-get install -y mysql-server --fix-missing
############################################################
echo "${RED}Installing UFW${NC}"
sudo apt-get install -y ufw > $OUT
echo "${RED}Configuring UFW${NC}"
# Allow from local network
sudo ufw allow from 192.168.1.1/24
# Allow port 22 to everyone in the world
sudo ufw allow 22
# Allow 9091 (Transmission)
sudo ufw allow 9091
# Allow 3306 (Mysql)
sudo ufw allow 3306
# Start UFW
sudo ufw enable --force-enable
############################################################
echo "${RED}Premi invio per riavviare${NC}"
read input_variable
sudo shutdown -r now
# TAKEN FROM: http://blog.samat.org/2015/02/05/slimming-an-existing-raspbian-install/
SlimRaspbian.sh
# GUI-related packages
pkgs="
xserver-xorg-video-fbdev
xserver-xorg xinit
gstreamer1.0-x gstreamer1.0-omx gstreamer1.0-plugins-base
gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-alsa
gstreamer1.0-libav
epiphany-browser
lxde lxtask menu-xdg gksu
xserver-xorg-video-fbturbo
xpdf gtk2-engines alsa-utils
netsurf-gtk zenity
desktop-base lxpolkit
weston
omxplayer
raspberrypi-artwork
lightdm gnome-themes-standard-data gnome-icon-theme
qt50-snapshot qt50-quick-particle-examples
"
# Edu-related packages
pkgs="$pkgs
idle python3-pygame python-pygame python-tk
idle3 python3-tk
python3-rpi.gpio
python-serial python3-serial
python-picamera python3-picamera
python3-pygame python-pygame python-tk
python3-tk
debian-reference-en dillo x2x
scratch nuscratch
timidity
smartsim penguinspuzzle
pistore
sonic-pi
python3-numpy
python3-pifacecommon python3-pifacedigitalio python3-pifacedigital-scratch-handler python-pifacecommon python-pifacedigitalio
oracle-java8-jdk
minecraft-pi python-minecraftpi
wolfram-engine
"
# Remove packages
for i in $pkgs; do
echo apt-get -y remove --purge $i
done
# Remove automatically installed dependency packages
echo apt-get -y autoremove
# Remove all packages marked rc (thanks @symm)
dpkg --list |grep "^rc" | cut -d " " -f 3 | xargs dpkg --purge
[global]
server string = %h server
security = SHARE
obey pam restrictions = Yes
guest account = pi
pam password change = Yes
passwd program = /usr/bin/passwd %u
passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
unix password sync = Yes
syslog = 0
log file = /var/log/samba/log.%m
max log size = 1000
dns proxy = No
usershare allow guests = Yes
panic action = /usr/share/samba/panic-action %d
idmap config * : backend = tdb
[homes]
comment = Home Directories
valid users = %S
create mask = 0700
directory mask = 0700
browseable = No
[printers]
comment = All Printers
path = /var/spool/samba
create mask = 0700
printable = Yes
print ok = Yes
browseable = No
[print$]
comment = Printer Drivers
path = /var/lib/samba/printers
[HD - Usb]
comment = Disco USB
path = /mnt/externalDisk/
read only = No
guest ok = Yes
[Time Machine]
comment = Time Machine OSX
path = /mnt/timeMachine
read only = No
guest ok = Yes
[Home]
comment = PI home
path = /home/pi/
read only = No
guest ok = Yes
# Loopback
auto lo
iface lo inet loopback
# Interfaccia Ethernet
iface eth0 inet static
address 192.168.1.193
netmask 255.255.255.0
network 192.168.1.1
broadcast 192.168.1.255
gateway 192.168.1.1
{
"alt-speed-down": 50,
"alt-speed-enabled": false,
"alt-speed-time-begin": 540,
"alt-speed-time-day": 127,
"alt-speed-time-enabled": false,
"alt-speed-time-end": 1020,
"alt-speed-up": 50,
"bind-address-ipv4": "0.0.0.0",
"bind-address-ipv6": "::",
"blocklist-enabled": false,
"blocklist-url": "http://www.example.com/blocklist",
"cache-size-mb": 4,
"dht-enabled": true,
"download-dir": "/mnt/externalDisk/Film/",
"download-limit": 100,
"download-limit-enabled": 0,
"download-queue-enabled": true,
"download-queue-size": 5,
"encryption": 1,
"idle-seeding-limit": 30,
"idle-seeding-limit-enabled": false,
"incomplete-dir": "/mnt/externalDisk/torrent/",
"incomplete-dir-enabled": false,
"lpd-enabled": false,
"max-peers-global": 200,
"message-level": 2,
"peer-congestion-algorithm": "",
"peer-limit-global": 240,
"peer-limit-per-torrent": 60,
"peer-port": 51413,
"peer-port-random-high": 65535,
"peer-port-random-low": 49152,
"peer-port-random-on-start": false,
"peer-socket-tos": "default",
"pex-enabled": true,
"port-forwarding-enabled": false,
"preallocation": 1,
"prefetch-enabled": 1,
"queue-stalled-enabled": true,
"queue-stalled-minutes": 30,
"ratio-limit": 2,
"ratio-limit-enabled": false,
"rename-partial-files": true,
"rpc-authentication-required": true,
"rpc-bind-address": "0.0.0.0",
"rpc-enabled": true,
"rpc-password": "alepollotorrent",
"rpc-port": 9091,
"rpc-url": "/transmission/",
"rpc-username": "ale",
"rpc-whitelist": "*.*.*.*",
"rpc-whitelist-enabled": true,
"scrape-paused-torrents-enabled": true,
"script-torrent-done-enabled": false,
"script-torrent-done-filename": "",
"seed-queue-enabled": false,
"seed-queue-size": 10,
"speed-limit-down": 100,
"speed-limit-down-enabled": false,
"speed-limit-up": 100,
"speed-limit-up-enabled": false,
"start-added-torrents": true,
"trash-original-torrent-files": false,
"umask": 18,
"upload-limit": 10,
"upload-limit-enabled": 0,
"upload-slots-per-torrent": 14,
"utp-enabled": true,
"watch-dir": "/home/pi/torrentDownloader/torrentFile/",
"watch-dir-enabled": true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment