bananenkeyboard/piconfig/readonly.sh

45 lines
1.8 KiB
Bash

sudo apt remove -y --purge triggerhappy logrotate dphys-swapfile cron
sudo apt autoremove -y --purge
sudo apt install -y busybox-syslogd
sudo apt remove -y --purge rsyslog
sudo sh -c 'echo -n "fastboot noswap ro" >>/boot/cmdline.txt'
sudo rm -rf /var/lib/dhcp/ /var/run /var/spool /var/lock /etc/resolv.conf
sudo ln -s /tmp /var/lib/dhcp
sudo ln -s /tmp /var/run
sudo ln -s /tmp /var/spool
sudo ln -s /tmp /var/lock
sudo touch /tmp/dhcpcd.resolv.conf; ln -s /tmp/dhcpcd.resolv.conf /etc/resolv.conf
sudo rm /var/lib/systemd/random-seed
sudo ln -s /tmp/random-seed /var/lib/systemd/random-seed
sudo sed -i 's#ExecStart=/lib/systemd/systemd-random-seed load#ExecStartPre=/bin/echo "" >/tmp/random-seed\nExecStart=/lib/systemd/systemd-random-seed load#' /lib/systemd/system/systemd-random-seed.service
sudo systemctl daemon-reload
sudo systemctl disable console-setup
sudo sed -i 's#\(.*PARTUUID.*defaults\)\(.*\)#\1,ro\2#' /etc/fstab
sudo cat <<EOT >>/etc/fstab
tmpfs /tmp tmpfs nosuid,nodev 0 0
tmpfs /var/log tmpfs nosuid,nodev 0 0
tmpfs /var/tmp tmpfs nosuid,nodev 0 0
EOT
sudo cat <<"EOT" >>/etc/bash.bashrc
# set variable identifying the filesystem you work in (used in the prompt below)
set_bash_prompt(){
fs_mode=$(mount | sed -n -e "s/^\/dev\/.* on \/ .*(\(r[w|o]\).*/\1/p")
PS1='\[\033[01;32m\]\u@\h${fs_mode:+($fs_mode)}\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
}
alias ro='sudo mount -o remount,ro / ; sudo mount -o remount,ro /boot'
alias rw='sudo mount -o remount,rw / ; sudo mount -o remount,rw /boot'
# setup fancy prompt"
PROMPT_COMMAND=set_bash_prompt
EOT
sudo cat <<EOT >>/etc/bash.bash_logout
sudo mount -o remount,rw /
history -a
sudo mount -o remount,ro /
sudo mount -o remount,ro /boot
EOT