Skip to content

Instantly share code, notes, and snippets.

@sunapi386
Last active June 23, 2018 22:39
Show Gist options
  • Select an option

  • Save sunapi386/3fe85962995b7aa6ed88b53ae77ba529 to your computer and use it in GitHub Desktop.

Select an option

Save sunapi386/3fe85962995b7aa6ed88b53ae77ba529 to your computer and use it in GitHub Desktop.
Clean minimal Raspbian
#!/usr/bin/env bash
# Given a fresh install of a Raspian OS, install the necessary tools.
# This is only meant to run once to setup a brand new fresh OS install.
#
# Author: Jason Sun
# Date: Feb 01, 2018
#
packages(){
sudo apt update
sudo apt install -y fish minicom vim vlc xinput-calibrator epiphany-browser \
x11-xserver-utils xautomation unclutter fbi libtool pkg-config build-essential \
sudo apt install -y libgoogle-glog-dev libgflags-dev
sudo apt install -y mpg123
# sudo apt install -y ddclient
sudo apt install -y tmux
sudo apt install -y vlc
sudo apt install -y minicom
sudo apt install -y vim
sudo apt install -y fish
autoconf automake python-dev xserver-xorg-input-evdev florence
chsh -s `which fish`
echo "Removing bloat"
sudo apt purge -y "libreoffice*" libreoffice* wolfram-engine sonic-pi scratch
sudo apt remove -y --purge "scratch*" python-minecraftpi
sudo apt autoremove -y
sudo apt clean
rm -rf ~/python_games/
sudo rm -rf /usr/share/raspi-ui-overrides/applications/wolfram-language.desktop
pip install pyyaml
}
ssh() {
echo "Setting up ssh"
ssh-keygen -f id_rsa -t rsa -N ''
touch ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
}
touchscreen() {
echo "Touchscreen calibration /usr/share/X11/xorg.conf.d/99-calibration.conf"
sudo touch /usr/share/X11/xorg.conf.d/99-calibration.conf
}
zmq() {
echo "Downloading"
cd ~/Downloads/
wget https://github.com/jedisct1/libsodium/releases/download/1.0.3/libsodium-1.0.3.tar.gz
wget http://download.zeromq.org/zeromq-4.1.3.tar.gz
wget https://raw.githubusercontent.com/zeromq/cppzmq/master/zmq.hpp
sudo mv zmq.hpp /usr/include/
tar -zxvf libsodium-1.0.3.tar.gz
tar -zxvf zeromq-4.1.3.tar.gz
echo "Installing libsodium 1.0.3"
cd ~/Downloads/libsodium-1.0.3/
./configure
make
sudo make install
echo "Installing zeromq"
cd ~/Downloads/zeromq-4.1.3/
./configure
make
sudo make install
sudo ldconfig
echo "Python wrappers"
sudo apt-get install python-dev
sudo pip install pyzmq
}
flatbuffers() {
git clone https://github.com/google/flatbuffers.git
cd flatbuffers
cmake -G "Unix Makefiles"
make
./flattests # this is quick, and should print "ALL TESTS PASSED"
sudo make install
}
udev_rules() {
cat << EOF | sudo tee -a /etc/udev/rules.d/98-com.rules
SUBSYSTEM=="input", GROUP="input", MODE="0660"
SUBSYSTEM=="i2c-dev", GROUP="i2c", MODE="0660"
SUBSYSTEM=="spidev", GROUP="spi", MODE="0660"
SUBSYSTEM=="bcm2835-gpiomem", GROUP="gpio", MODE="0660"
SUBSYSTEM=="gpio", GROUP="gpio", MODE="0660"
SUBSYSTEM=="gpio*", PROGRAM="/bin/sh -c '\
chown -R root:gpio /sys/class/gpio && chmod -R 770 /sys/class/gpio;\
chown -R root:gpio /sys/devices/virtual/gpio && chmod -R 770 /sys/devices/virtual/gpio;\
chown -R root:gpio /sys$devpath && chmod -R 770 /sys$devpath\
'"
KERNEL=="ttyAMA[01]", PROGRAM="/bin/sh -c '\
ALIASES=/proc/device-tree/aliases; \
if cmp -s $ALIASES/uart0 $ALIASES/serial0; then \
echo 0;\
elif cmp -s $ALIASES/uart0 $ALIASES/serial1; then \
echo 1; \
else \
exit 1; \
fi\
'", SYMLINK+="serial%c"
KERNEL=="ttyS0", PROGRAM="/bin/sh -c '\
ALIASES=/proc/device-tree/aliases; \
if cmp -s $ALIASES/uart1 $ALIASES/serial0; then \
echo 0; \
elif cmp -s $ALIASES/uart1 $ALIASES/serial1; then \
echo 1; \
else \
exit 1; \
fi \
'", SYMLINK+="serial%c"
SUBSYSTEM=="tty",ATTRS{product}=="LM-USB-COM",SYMLINK+="svv_rs485"
SUBSYSTEM=="tty",ATTRS{interface}=="CP2102 USB to UART Bridge Controller",SYMLINK+="pc_port"
SUBSYSTEM=="tty",ATTRS{manufacturer}=="u-blox AG - www.u-blox.com",SYMLINK+="gps"
EOF
}
autostart_file() {
echo "Creating autostart file ~/.config/lxsession/LXDE-pi/autostart"
cat <<EOF >> ~/.config/lxsession/LXDE-pi/autostart
@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
@xscreensaver -no-splash
@point-rpi
@xset s off
@xset -dpms
@xset s noblank
@sed -i 's/"exited_cleanly": false/"exited_cleanly": true/' ~/.config/chromium Default/Preferences
@lxterminal -l -e '/home/pi/rpi/rpi_supervisor.py'
EOF
}
pi_ignition_file() {
echo "Creating python booter file ~/rpi_supervisor.py"
cat <<EOF >> ~/rpi_supervisor.py
# I expect this file to be populated
EOF
}
install_ffmpeg() {
echo "Source: https://www.johnvansickle.com/ffmpeg/"
wget https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-armhf-32bit-static.tar.xz
# China may not have this /ffmpeg-release-armhf-32bit-static.tar.xz
tar xvfJ ffmpeg-release-armhf-32bit-static.tar.xz
echo "All formats: ffmpeg -f v4l2 -list_formats all -i /dev/video0"
echo A limitation of statically linking glibc is the loss of DNS resolution. Installing
echo nscd through your package manager will fix this or you can use
echo "ffmpeg -i http://<ip address here>/" instead of "ffmpeg -i http://example.com/"
echo "copying to bin folder so PATH can find it"
cd ffmpeg-release-armhf-32bit-static
sudo cp ff* qt-faststart /usr/bin
}
python_pip() {
echo "pip install stuff"
pip3 install pyzmq
pip3 install websocket-client
pip3 install psutil
pip3 install gTTs # not supported in China?
pip3 install pyyaml
}
gps_info() {
# https://bigdanzblog.wordpress.com/2015/01/18/connecting-u-blox-neo-6m-gps-to-raspberry-pi/
sudo apt install -y jq
sudo apt install -y gpsd gpsd-clients
echo "to show one:"
echo "gpspipe -w -n 30 | grep -m 1 lat | jq '.'"
}
gps_geturl() {
echo 'http://google.com/maps/@'\
$(gpspipe -w -n 30 | grep -m 1 lat | jq '.lat')','\
$(gpspipe -w -n 30 | grep -m 1 lat | jq '.lon')
}
echo "Installing stuff"
packages
ssh
touchscreen
zmq
flatbuffers
udev_rules
autostart_file
pi_ignition_file
install_ffmpeg
python_pip
gps_info
gps_geturl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment