Last active
July 29, 2020 03:24
-
-
Save geakstr/a8486d563d99d8e2e421 to your computer and use it in GitHub Desktop.
Setting up raspberry pi
This file contains 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
# Initial updates and necessary tools | |
aptitude update && aptitude full-upgrade && \ | |
aptitude install gcc gcc-4.4 gcc-4.5 gcc-4.6 gcc-4.7 git-core binutils curl \ | |
bcc psmisc htop hdparm cpufrequtils screen autoconf \ | |
make texinfo bc build-essential bzip2 libbz2-dev \ | |
zlib1g-dev libssl-dev libreadline6 libreadline6-dev \ | |
sqlite3 libsqlite3-dev ncurses-dev sudo \ | |
libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev | |
## rpi-update | |
wget --no-check-certificate \ | |
https://raw.github.com/Hexxeh/rpi-update/master/rpi-update \ | |
-O /usr/bin/rpi-update && chmod +x /usr/bin/rpi-update && \ | |
rpi-update | |
reboot | |
## raspi-config | |
echo "deb http://archive.raspberrypi.org/debian/ wheezy main" >> /etc/apt/sources.list && \ | |
wget http://archive.raspberrypi.org/debian/raspberrypi.gpg.key && \ | |
apt-key add raspberrypi.gpg.key && rm raspberrypi.gpg.key && \ | |
aptitude update && aptitude install raspi-config && \ | |
raspi-config | |
echo "127.0.0.1 pi" >> /etc/hosts | |
echo "force_turbo=0" >> /boot/config.txt | |
sed -i 's/#hdmi_drive=2/hdmi_drive=2/g' /boot/config.txt | |
# Make vcgencmd work | |
ln -s /opt/vc/bin/vcgencmd /usr/bin/vcgencmd | |
echo 'SUBSYSTEM=="vchiq",GROUP="video",MODE="0660"' > /etc/udev/rules.d/10-vchiq-permissions.rules | |
# Install add-apt-repository | |
wget http://blog.anantshri.info/content/uploads/2010/09/add-apt-repository.sh.txt && \ | |
mv add-apt-repository.sh.txt /usr/bin/add-apt-repository && \ | |
chmod o+x /usr/bin/add-apt-repository && \ | |
chown root:root /usr/bin/add-apt-repository | |
# Add user | |
groupadd geakstr | |
useradd geakstr -m -K UMASK=0066 -s /bin/bash \ | |
-g geakstr -G users,ssh,sudo,video,www-data | |
passwd geakstr | |
# Disable root ssh login http://www.cyberciti.biz/tips/linux-unix-bsd-openssh-server-best-practices.html | |
sed -i 's/PermitRootLogin yes/PermitRootLogin no/g' /etc/ssh/sshd_config | |
reboot | |
# Log in with new user! | |
# Make PI fastes! (all optional) | |
# Remove the extra tty / getty’s | |
sed -i '/[2-6]:23:respawn:\/sbin\/getty 38400 tty[2-6]/s%^%#%g' /etc/inittab | |
sed -i '/T0:23:respawn:\/sbin\/getty -L ttyAMA0 115200 vt100/s%^%#%g' /etc/inittab | |
# Disable IPv6 | |
echo "net.ipv6.conf.all.disable_ipv6=1" > /etc/sysctl.d/disableipv6.conf | |
echo "blacklist ipv6" >> /etc/modprobe.d/blacklist | |
sed -i '/::/s%^%#%g' /etc/hosts | |
# Replace logging system | |
aptitude -y purge rsyslog && aptitude -y install inetutils-syslogd | |
service inetutils-syslogd stop | |
for file in /var/log/*.log /var/log/mail.* /var/log/debug /var/log/syslog; do [ -f "$file" ] && rm -f "$file"; done | |
for dir in fsck news; do [ -d "/var/log/$dir" ] && rm -rf "/var/log/$dir"; done | |
echo -e "*.*;mail.none;cron.none\t -/var/log/messages\ncron.*\t -/var/log/cron\nmail.*\t -/var/log/mail" > /etc/syslog.conf | |
mkdir -p /etc/logrotate.d | |
echo -e "/var/log/cron\n/var/log/mail\n/var/log/messages {\n\trotate 4\n\tweekly\n\tmissingok\n\tnotifempty\n\tcompress\n\tsharedscripts\n\tpostrotate\n\t/etc/init.d/inetutils-syslogd reload >/dev/null\n\tendscript\n}" > /etc/logrotate.d/inetutils-syslogd | |
service inetutils-syslogd start | |
aptitude install lsof | |
cd /tmp | |
#### http://www.tremende.com/ramlog/download/ramlog_2.0.0_all.deb | |
wget --no-check-certificate "https://raw.github.com/swirepe/personalscripts/master/pi/ramlog_2.0.0_all.deb" -O ramlog_2.0.0_all.deb | |
dpkg -i ramlog_2.0.0_all.deb | |
nano /etc/default/ramlog # TMPFS_RAMFS_SIZE=40m | |
nano /etc/init.d/ramlog | |
# X-Start-Before: rsyslog | |
# X-Stop-After: rsyslog | |
nano /etc/init.d/inetutils-syslogd | |
# Required-Start: $remote_fs $time ramlog | |
# Required-Stop: umountnfs $time ramlog | |
insserv | |
# Static IP | |
nano /etc/network/interfaces | |
++++++++++++++++++++++ | |
# replace | |
iface eth0 inet dhcp | |
# with | |
iface eth0 inet static | |
address 192.168.1.100 | |
gateway 192.168.1.1 | |
netmask 255.255.255.0 | |
network 192.168.1.0 | |
broadcast 192.168.1.255 | |
++++++++++++++++++++++ | |
# Replace Deadline Scheduler with NOOP Scheduler | |
sed -i 's/deadline/noop/g' /boot/cmdline.txt | |
sed -i "s/#FSCKFIX=no/FSCKFIX=yes/g" /etc/default/rcS | |
tune2fs -c 3 /dev/mmcblk0p2 | |
reboot | |
# SSH key authorization | |
ssh-keygen -t rsa -C "[email protected]" | |
ssh-add ~/.ssh/id_rsa | |
pbcopy < ~/.ssh/id_rsa.pub | |
mkdir ~/.ssh | |
nano ~/.ssh/authorized_keys | |
# On Mac "cat ~/.ssh/id_rsa.pub" and copy to authorized_keys | |
chmod 700 ~/.ssh/ | |
chmod 600 ~/.ssh/authorized_keys | |
sudo reboot | |
# Format and mount flash | |
sudo -i | |
fdisk -l # Get flash name (example: /dev/sda1) | |
umount /dev/sda1 | |
mkfs.ext4 /dev/sda1 -L flash | |
mkdir /media/flash | |
mount -t auto /dev/sda1 /media/flash | |
blkid # Get and save UUID flash drive (*******-*******-*****-****) | |
nano /etc/fstab | |
+++++++++++++++++++++++ | |
UUID=6fd16c2e-a955-4c98-90c1-934ff6c7720b /media/flash ext4 defaults,noatime 0 0 | |
+++++++++++++++++++++++ | |
exit | |
# NTFS | |
sudo aptitude install ntfs-3g | |
sudo mkfs.ntfs /dev/sdb1 -f -v -I -L storage | |
blkid | |
# hd-idle | |
wget from http://www.sf.net/projects/hd-idle | |
sudo aptitude install debhelper | |
sudo dpkg-buildpackage -rfakeroot | |
sudo dpkg -i ../hd-idle_*.deb | |
# Edit /etc/default/hd-idle and /etc/init.d/hd-idle | |
# Bittorrent Sync | |
sudo -i | |
gpg --keyserver pgp.mit.edu --recv-keys 6BF18B15 && | |
gpg --armor --export 6BF18B15 | sudo apt-key add - && | |
echo deb http://debian.yeasoft.net/btsync wheezy main contrib non-free >> /etc/apt/sources.list.d/btsync.list && | |
echo deb-src http://debian.yeasoft.net/btsync wheezy main contrib non-free >> /etc/apt/sources.list.d/btsync.list && | |
aptitude update && aptitude install btsync && | |
usermod -a -G btsync geakstr && | |
mkdir /media/flash && | |
chown -R btsync:btsync /media/flash/sync && chmod -R 775 /media/flash/sync | |
exit | |
# Install nginx | |
sudo -i | |
apt-get install nginx | |
service nginx stop | |
useradd www-data && groupadd www-data && usermod -g www-data www-data | |
mkdir /var/www && chmod -R 775 /var/www && chown -R www-data:www-data /var/www | |
unlink /etc/nginx/sites-enabled/default | |
nano /etc/nginx/sites-available/main | |
cd /etc/nginx/sites-enabled | |
ln -s ../sites-available/main | |
service nginx start | |
exit | |
# Python | |
## Install https://github.com/yyuu/pyenv for managing Python versions | |
cd | |
git clone git://github.com/yyuu/pyenv.git .pyenv | |
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc | |
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc | |
echo 'eval "$(pyenv init -)"' >> ~/.zshrc | |
## Install Python 3.3 (this take much time) | |
pyenv install 3.3.3 && pyenv rehash && pyenv global 3.3.3 | |
git clone git://github.com/yyuu/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv | |
## Install uwsgi | |
pip install uwsgi && pyenv rehash | |
uwsgi --ini /var/www/app/uwsgi.ini | |
## Flask, nginx, uwsgi, circus configuration | |
pyenv virtualenv 3.3.3 flask-site | |
sudo apt-get install libzmq-dev libevent-dev | |
pip install uwsgi && pyenv rehash | |
pip install flask && pyenv rehash | |
touch /var/www/app/uwsgi.sock | |
nano /var/www/app/nginx.conf | |
+++++++++++++++++++++++++++++++++ | |
server { | |
listen 80; | |
server_name localhost; | |
charset utf-8; | |
location / { try_files $uri @yourapplication; } | |
location @yourapplication { | |
include uwsgi_params; | |
uwsgi_pass unix:/var/www/app/uwsgi.sock; | |
} | |
location /static { | |
root /var/www/app/static/; | |
} | |
} | |
+++++++++++++++++++++++++++++++++ | |
sudo ln -s /var/www/app/nginx.conf /etc/nginx/sites-enabled/flask | |
sudo service nginx restart | |
nano /var/www/app/uwsgi.ini | |
+++++++++++++++++++++++++++++++++ | |
[uwsgi] | |
#application's base folder | |
base = /var/www/app | |
#python module to import | |
app = app | |
module = %(app) | |
home = /home/geakstr/.pyenv/versions/flask-site | |
pythonpath = %(base) | |
#socket file's location | |
socket = /var/www/app/uwsgi.sock | |
#permissions for the socket file | |
chmod-socket = 666 | |
#the variable that holds a flask application inside the module imported at line #6 | |
callable = app | |
# Limit memory per process | |
limit-as=32 | |
#location of log files | |
logto = /var/www/app/logs/uwsgi.log | |
+++++++++++++++++++++++++++++++++ | |
sudo nano /etc/init/uwsgi.conf | |
+++++++++++++++++++++++++++++++++ | |
# simple uWSGI script | |
description "uwsgi tiny instance" | |
start on runlevel [2345] | |
stop on runlevel [06] | |
# Prod | |
exec /home/geakstr/.pyenv/versions/flask-site/bin/uwsgi --die-on-term --processes 4 --master --idle 60 --ini /var/www/app/uwsgi.ini | |
# Dev | |
#exec /home/geakstr/.pyenv/versions/flask-site/bin/uwsgi --py-autoreload 1 --die-on-term --processes 4 --master --idle 60 --ini /var/www/app/uwsgi.ini | |
+++++++++++++++++++++++++++++++++ | |
# Transmission | |
sudo -i | |
apt-get update && apt-get upgrade && apt-get dist-upgrade | |
apt-get install transmission-daemon | |
mkdir /media/storage/torrent | |
mkdir /media/storage/torrent/.tmp | |
usermod -a -G debian-transmission geakstr | |
chgrp debian-transmission /media/storage/torrent/.tmp | |
chgrp debian-transmission /media/storage/torrent | |
chmod 770 /media/storage/torrent/.tmp | |
chmod 770 /media/storage/torrent | |
service transmission-daemon stop | |
# Change to USER=geakstr | |
nano /etc/init.d/transmission-daemon | |
chown geakstr -R /var/lib/transmission-daemon/info/ | |
chown geakstr -R /media/storage/torrent/.tmp | |
chown geakstr -R /media/storage/torrent | |
cp settings.json /etc/transmission-daemon/settings.json | |
chown geakstr -R /etc/transmission-daemon/settings.json | |
service transmission-daemon start | |
exit | |
# Tesseract OCR | |
sudo apt-get install \ | |
imagemagick libpng12-dev libjpeg8-dev libtiff4-dev bc \ | |
libtesseract-dev libtesseract3 tesseract-ocr tesseract-ocr-equ \ | |
tesseract-ocr-equ tesseract-ocr-osd tesseract-ocr-osd \ | |
tesseract-ocr-eng tesseract-ocr-rus | |
############# START image to text script | |
#!/bin/bash | |
# Usage: i2t image.png eng | |
file_in=$1 | |
langs=$2 | |
if [ -z "$2" ] | |
then | |
langs="eng+rus" | |
fi | |
dpi=$(convert $file_in -format "%x" info:) | |
dpi=${dpi//[A-z\ ]/} | |
if [ $dpi -lt 300 ] | |
then | |
convert -resample 300 $file_in .ocr.tmp.tif | |
else | |
convert $file_in .ocr.tmp.tif | |
fi | |
tesseract .ocr.tmp.tif $file_in -l $langs | |
rm -f .ocr.tmp.tif | |
############# END image to text script | |
# All installed packages | |
dpkg --get-selections | |
# Install ZSH | |
#!/bin/bash | |
# https://gist.github.com/geakstr/8632955 | |
# Run: ./install_zsh username | |
username=$1 | |
export ZHS_OH_MY_ZSH_URL=https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh && | |
export ZSH_OH_MY_THEME_URL=https://gist.github.com/geakstr/8632148/raw/1ff4feb98a43e4802e5d55973cfa6d8a5a73fc74/oh-my-theme.zsh-theme && | |
export ZSH_DOWNLOAD_VERSION=5.0.5 && | |
cd /tmp && | |
wget http://www.zsh.org/pub/zsh-$ZSH_DOWNLOAD_VERSION.tar.bz2 && | |
tar xvf zsh-$ZSH_DOWNLOAD_VERSION.tar.bz2 && cd zsh-$ZSH_DOWNLOAD_VERSION && | |
./configure \ | |
--prefix=/usr \ | |
--bindir=/bin \ | |
--sysconfdir=/etc/zsh \ | |
--enable-etcdir=/etc/zsh && | |
make && | |
makeinfo Doc/zsh.texi --html -o Doc/html && | |
makeinfo Doc/zsh.texi \ | |
--html --no-split --no-headers -o Doc/zsh.html && | |
makeinfo Doc/zsh.texi --plaintext -o Doc/zsh.txt && | |
sudo make install && | |
sudo make infodir=/usr/share/info install.info && | |
sudo install -v -m755 -d /usr/share/doc/zsh-$ZSH_DOWNLOAD_VERSION/html && | |
sudo install -v -m644 Doc/html/* \ | |
/usr/share/doc/zsh-$ZSH_DOWNLOAD_VERSION/html && | |
sudo install -v -m644 Doc/zsh.{html,txt} \ | |
/usr/share/doc/zsh-$ZSH_DOWNLOAD_VERSION && | |
sudo sh -c "echo /bin/zsh >> /etc/shells" && | |
sudo sh -c "echo /bin/zsh-$ZSH_DOWNLOAD_VERSION >> /etc/shells" && | |
sudo chsh -s /bin/zsh $username && | |
curl -L $ZHS_OH_MY_ZSH_URL | sh && | |
export CURRENT_LOCALE=en_US.UTF-8 && | |
echo "export CURRENT_LOCALE=en_US.UTF-8" >> ~/.zshrc && | |
echo "export LANG=$CURRENT_LOCALE" >> ~/.zshrc && | |
echo "export LANGUAGE=$CURRENT_LOCALE" >> ~/.zshrc && | |
echo "export LC_CTYPE=$CURRENT_LOCALE" >> ~/.zshrc && | |
echo "export LC_NUMERIC=$CURRENT_LOCALE" >> ~/.zshrc && | |
echo "export LC_TIME=$CURRENT_LOCALE" >> ~/.zshrc && | |
echo "export LC_COLLATE=$CURRENT_LOCALE" >> ~/.zshrc && | |
echo "export LC_MONETARY=$CURRENT_LOCALE" >> ~/.zshrc && | |
echo "export LC_MESSAGES=$CURRENT_LOCALE" >> ~/.zshrc && | |
echo "export LC_PAPER=$CURRENT_LOCALE" >> ~/.zshrc && | |
echo "export LC_NAME=$CURRENT_LOCALE" >> ~/.zshrc && | |
echo "export LC_ADDRESS=$CURRENT_LOCALE" >> ~/.zshrc && | |
echo "export LC_TELEPHONE=$CURRENT_LOCALE" >> ~/.zshrc && | |
echo "export LC_MEASUREMENT=$CURRENT_LOCALE" >> ~/.zshrc && | |
echo "export LC_IDENTIFICATION=$CURRENT_LOCALE" >> ~/.zshrc && | |
echo "export LC_ALL=$CURRENT_LOCALE" >> ~/.zshrc && | |
wget $ZSH_OH_MY_THEME_URL -O ~/.oh-my-zsh/themes/oh-my-theme.zsh-theme && | |
sed -i 's/ZSH_THEME="robbyrussell"/ZSH_THEME="oh-my-theme"/g' ~/.zshrc && | |
sudo reboot | |
# nginx | |
sudo aptitude install build-essential zlib1g-dev libpcre3-dev libssl-dev libxslt1-dev libxml2-dev libgd2-xpm-dev libgeoip-dev libperl-dev | |
cd /tmp | |
wget http://nginx.org/download/nginx-1.6.0.tar.gz | |
tar zxf nginx-1.6.0.tar.gz | |
git clone git://github.com/yaoweibin/ngx_http_substitutions_filter_module.git | |
cd nginx-1.6.0 | |
./configure \ | |
--prefix=/usr/local/nginx \ | |
--conf-path=/etc/nginx/nginx.conf \ | |
--error-log-path=/var/log/nginx/error.log \ | |
--http-log-path=/var/log/nginx/access.log \ | |
--pid-path=/var/run/nginx.pid \ | |
--lock-path=/var/lock/nginx.lock \ | |
--user=www-data \ | |
--group=www-data \ | |
--with-http_addition_module \ | |
--with-http_auth_request_module \ | |
--with-http_perl_module \ | |
--with-http_flv_module \ | |
--with-http_geoip_module \ | |
--with-http_gzip_static_module \ | |
--with-http_stub_status_module \ | |
--with-http_image_filter_module \ | |
--with-http_mp4_module \ | |
--with-http_random_index_module \ | |
--with-http_secure_link_module \ | |
--with-http_spdy_module \ | |
--with-http_ssl_module \ | |
--with-http_stub_status_module \ | |
--with-http_sub_module \ | |
--with-http_dav_module \ | |
--with-http_xslt_module \ | |
--with-file-aio \ | |
--with-mail \ | |
--with-mail_ssl_module \ | |
--with-pcre \ | |
--add-module=/tmp/ngx_http_substitutions_filter_module | |
make | |
sudo make install | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment