Skip to content

Instantly share code, notes, and snippets.

@stuthedew
Created February 13, 2015 01:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stuthedew/cfa167f8b85e12dd08a1 to your computer and use it in GitHub Desktop.
Save stuthedew/cfa167f8b85e12dd08a1 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Change the following word 'pi' to your own username if it's not 'pi'
YOURUSERNAME="pi"
YELLOW="\033[1;33m"
RED="\033[0;31m"
BLUE="\033[1;34m"
ENDCOLOR="\033[0m"
if [ $USER != root ]; then
echo -e $RED"Error: you need to be root! Use 'sudo'..."
echo -e $YELLOW"Exiting..."$ENDCOLOR
exit 0
fi
# Remove unnecessary GUI programmes and their configuration files (obviously don't do this if you want a graphical desktop
echo -e $YELLOW"Removing pointless packages. This could take a while, maybe one should make a cup of tea."$ENDCOLOR
apt-get purge --auto-remove scratch -y
apt-get purge --auto-remove debian-reference-en dillo idle3 python3-tk idle python-pygame python-tk -y
apt-get purge --auto-remove lightdm gnome-themes-standard gnome-icon-theme raspberrypi-artwork -y
apt-get purge --auto-remove gvfs-backends gvfs-fuse desktop-base lxpolkit netsurf-gtk zenity xdg-utilse -y
apt-get purge --auto-remove mupdf gtk2-engines lxde lxtask menu-xdg gksu -y
apt-get purge --auto-remove midori xserver-xorg xinit xserver-xorg-video-fbdev -y
apt-get purge --auto-remove libraspberrypi-dev libraspberrypi-doc -y
apt-get purge --auto-remove dbus-x11 libx11-6 libx11-data libx11-xcb1 x11-common x11-utils -y
apt-get purge --auto-remove lxde-icon-theme gconf-service gconf2-common -y
rm -rf /home/$YOURUSERNAME/Desktop /home/$YOURUSERNAME/python_games /home/$YOURUSERNAME/ocr_pi.png
echo -e $YELLOW"Upgrading packages, normally takes a few minutes..."$ENDCOLOR
aptitude update
aptitude -r full-upgrade -y
aptitude clean
echo -e $YELLOW"Updating Raspberry Pi firmware.."$ENDCOLOR
rpi-update
# Remove the extra tty / gettys to save 3.5MB RAM
echo -e $YELLOW"Removing extra ttys / gettys, to save some RAM"$ENDCOLOR
sed -i '/[2-6]:23:respawn:\/sbin\/getty 38400 tty[2-6]/s%^%#%g' /etc/inittab
# Disable getty on the Raspberry Pi serial line
sed -i '/T0:23:respawn:\/sbin\/getty -L ttyAMA0 115200 vt100/s%^%#%g' /etc/inittab
# Customise the size of the swap file, 512MB recommended
echo -e $YELLOW"Customising swap to make better use of RAM..."$ENDCOLOR
echo "CONF_SWAPSIZE=512" > /etc/dphys-swapfile
# Initialise the swapfile
dphys-swapfile setup
# Enable the swapfile
dphys-swapfile swapon
# Default swappiness is 1, we will change this value to 10, which will allow for better memory usage at the expense of more swap usage
sed -i 's/vm.swappiness=1/vm.swappiness=10/g' /etc/sysctl.conf
# Purge cached block devices before cached filesystem entries
echo 'vm.vfs_cache_pressure=50' >> /etc/sysctl.conf
# Most users will not need IPv6 support - it's not used much yet, and can potentially pose a security threat (rarely). Disable it to save the resources and speed up networking.
echo -e $YELLOW"Disabling IPv6 - it's not needed generally and will speed up networking a bit"$ENDCOLOR
echo "net.ipv6.conf.all.disable_ipv6=1" > /etc/sysctl.d/disableipv6.conf
# Disable the kernel module
echo 'blacklist ipv6' >> /etc/modprobe.d/blacklist
# Remove IPv6 hosts
sed -i '/::/s%^%#%g' /etc/hosts
# All done!
echo -e $BLUE"Script Finished! Reeboot then go grab a beer..."$ENDCOLOR
@stuthedew
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment