Last active
April 28, 2019 00:50
-
-
Save mlagerberg/6d28d808289b5b68a4400d0dd1927450 to your computer and use it in GitHub Desktop.
[rpi-install-lite] Installs common stuff on a fresh Raspbian installation, without user input #rpi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
############################################################################ | |
# | |
# Installs and configures many things useful for a fresh Rasbian install. | |
# All things configured are described in this repo: | |
# https://github.com/mlagerberg/raspberry-pi-setup | |
# A more complete version of this script (that requires user input) can | |
# be found here: https://gist.github.com/mlagerberg/df0e433f984b4c3595f7 | |
# | |
# Created by Mathijs Lagerberg, 2017 | |
# | |
# USE WITH CAUTION AND AT YOUR OWN RISK! | |
# | |
# This script performs the following actions | |
# - Disable root login | |
# - Increase SSH keepalive | |
# - Install a whooooole bunch of packages (will take a while) | |
# - Set-up a firewall (with ports open for http, btsync and remote desktop) | |
# - Install my dotfiles | |
# - Make the LEDs a little less blinky | |
# - Upgrade the system | |
# | |
############################################################################ | |
# Check for root access | |
if [[ $EUID -ne 0 ]]; then | |
echo "This script must be run as root" | |
exit 1 | |
fi | |
# Disable root login: | |
echo | |
echo "Disabling root login..." | |
passwd -dl root | |
# Keep SSH connections alive (do this before installing packages!) | |
echo "Configuring SSH..." | |
echo " | |
ClientAliveInterval 30 | |
TCPKeepAlive yes | |
ClientAliveCountMax 99999" >> /etc/ssh/sshd_config | |
#sudo service network-manager restart | |
sudo service networking restart | |
# Install all kinds of stuff | |
echo | |
echo "Installing packages..." | |
apt-get update | |
apt-get -y install git iptables fail2ban libpam-google-authenticator iftop ntfs-3g ntfs-config testdisk xrdp x11-xserver-utils unclutter motion bluetooth bluez blueman pi-bluetooth bluez-firmware gphoto2 samba samba-common-bin lirc liblircclient-dev libav-tools tightvncserver net-tools mailutils python-pip tmux | |
# iptables | |
echo "Configuring firewall..." | |
iptables -A INPUT -j ACCEPT -m state --state ESTABLISHED,RELATED | |
# Web | |
iptables -A INPUT -p tcp --dport 80 -m state --state NEW -j ACCEPT | |
iptables -A INPUT -p tcp --dport 8000 -m state --state NEW -j ACCEPT | |
iptables -A INPUT -p tcp --dport 8080 -m state --state NEW -j ACCEPT | |
iptables -A INPUT -p tcp --dport 443 -m state --state NEW -j ACCEPT | |
# SSH | |
iptables -A INPUT -p tcp --dport 22 -m state --state NEW -j ACCEPT | |
# BTSync | |
iptables -A INPUT -p tcp --dport 55555 -m state --state NEW -j ACCEPT | |
iptables -A INPUT -p tcp --dport 3838 -m state --state NEW -j ACCEPT | |
iptables -A INPUT -p udp --dport 3838 -m state --state NEW -j ACCEPT | |
# Syncthing | |
#iptables -A INPUT -p tcp --dport 22000 -m state --state NEW -j ACCEPT | |
#iptables -A INPUT -p tcp --dport 21025 -m state --state NEW -j ACCEPT | |
# Remote desktop | |
iptables -A INPUT -p tcp --dport 3389 -m state --state NEW -j ACCEPT | |
# Ping | |
iptables -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT | |
# Block the rest | |
iptables -P INPUT DROP | |
iptables-save > /etc/iptables.up.conf | |
# And make sure the config file is used: | |
echo "#!/bin/bash | |
/sbin/iptables-restore < /etc/iptables.up.conf" > /etc/network/if-pre-up.d/iptables | |
chmod +x /etc/network/if-pre-up.d/iptables | |
# Install dotfiles | |
su pi <<'EOF' | |
mkdir ~/dotfiles | |
cd ~/dotfiles | |
git clone https://github.com/mlagerberg/dotfiles | |
cd dotfiles/ | |
chmod +x install.sh | |
source install.sh | |
EOF | |
# Install hosts file | |
cp /etc/hosts /etc/hosts.old | |
wget https://raw.githubusercontent.com/mlagerberg/raspberry-pi-setup/master/scripts/hosts | |
mv hosts /etc/hosts | |
# Alter LEDs | |
echo " | |
dtparam=act_led_trigger=mmc0 | |
dtparam=act_led_activelow=off | |
dtparam=pwr_led_trigger=cpu0 | |
dtparam=pwr_led_activelow=off | |
" >> /boot/config.txt | |
# Install Resilio Sync | |
mkdir /var/cloud | |
cd /var/cloud/ | |
wget "http://download.getsyncapp.com/endpoint/btsync/os/linux-arm/track/stable" | |
tar -zxvf stable | |
rm stable | |
(exec ./btsync --dump-sample-config) >> btsync.conf | |
useradd --shell /bin/false -d /var/cloud btsync | |
chown -R btsync:btsync /var/cloud | |
# All done, let's update | |
apt-get -y dist-upgrade | |
# Restart SSH | |
/etc/init.d/ssh restart | |
# And make sure it starts on boot | |
#sudo update-rc.d ssh defaults | |
sudo systemctl enable ssh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment