raspiblitz/build_sdcard.sh

694 lines
28 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
2019-01-27 11:03:07 +01:00
#########################################################################
# Build your SD card image based on: 2021-10-30-raspios-bullseye-arm64.zip
# https://downloads.raspberrypi.org/raspios_arm64/images/raspios_arm64-2021-11-08/
# SHA256: b35425de5b4c5b08959aa9f29b9c0f730cd0819fe157c3e37c56a6d0c5c13ed8
# PGP fingerprint: 8738CD6B956F460C
# PGP key: https://www.raspberrypi.org/raspberrypi_downloads.gpg.key
2019-06-04 11:01:52 +02:00
# setup fresh SD card with image above - login per SSH and run this script:
2019-01-27 11:03:07 +01:00
##########################################################################
defaultBranch="v1.7"
echo "*****************************************"
echo "* RASPIBLITZ SD CARD IMAGE SETUP *"
echo "*****************************************"
echo "For details on optional parameters - see build script source code:"
2021-08-27 09:59:21 +02:00
# 1st optional parameter: NO-INTERACTION
# ----------------------------------------
2021-08-27 09:56:47 +02:00
# When 'true' then no questions will be asked on building .. so it can be used in build scripts
# for containers or as part of other build scripts (default is false)
noInteraction="${1:-false}"
if [ "${noInteraction}" != "true" ] && [ "${noInteraction}" != "false" ]; then
echo "ERROR: NO-INTERACTION parameter needs to be either 'true' or 'false'"
exit 1
fi
echo "1) NO-INTERACTION --> '${noInteraction}'"
2021-08-27 09:59:21 +02:00
# 2nd optional parameter: FATPACK
# -------------------------------
# could be 'true' or 'false' (default)
# When 'true' it will pre-install needed frameworks for additional apps and features
# as a convenience to safe on install and update time for additional apps.
# When 'false' it will just install the bare minimum and additional apps will just
# install needed frameworks and libraries on demand when activated by user.
# Use 'false' if you want to run your node without: go, dot-net, nodejs, docker, ...
fatpack="${2:-false}"
if [ "${fatpack}" != "true" ] && [ "${fatpack}" != "false" ]; then
echo "ERROR: FATPACK parameter needs to be either 'true' or 'false'"
exit 1
2018-12-10 00:50:50 +01:00
fi
echo "2) FATPACK --> '${fatpack}'"
2018-12-22 13:57:49 +01:00
2021-08-27 09:59:21 +02:00
# 3rd optional parameter: GITHUB-USERNAME
# ---------------------------------------
# could be any valid github-user that has a fork of the raspiblitz repo - 'rootzoll' is default
# The 'raspiblitz' repo of this user is used to provisioning sd card
# with raspiblitz assets/scripts later on.
# If this parameter is set also the branch needs to be given (see next parameter).
githubUser="${3:-rootzoll}"
echo "3) GITHUB-USERNAME --> '${githubUser}'"
2021-08-27 09:59:21 +02:00
# 4th optional parameter: GITHUB-BRANCH
# -------------------------------------
# could be any valid branch or tag of the given GITHUB-USERNAME forked raspiblitz repo
# https://github.com/rootzoll/raspiblitz/tags
githubBranch="${4:-"${defaultBranch}"}"
echo "4) GITHUB-BRANCH --> '${githubBranch}'"
2021-08-27 09:59:21 +02:00
# 5th optional parameter: DISPLAY-CLASS
# ----------------------------------------
2021-09-09 18:24:49 +02:00
# Could be 'hdmi', 'headless' or 'lcd' (lcd is default)
# On 'false' the standard video output is used (HDMI) by default.
2021-04-08 00:02:57 +02:00
# https://github.com/rootzoll/raspiblitz/issues/1265#issuecomment-813369284
displayClass="${5:-lcd}"
[ "${displayClass}" = "false" ] && displayClass="hdmi"
2021-04-08 00:02:57 +02:00
if [ "${displayClass}" != "hdmi" ] && [ "${displayClass}" != "lcd" ] && [ "${displayClass}" != "headless" ]; then
echo "ERROR: DISPLAY-CLASS parameter needs to be 'lcd', 'hdmi' or 'headless'"
exit 1
fi
echo "5) DISPLAY-CLASS --> '${displayClass}'"
2021-08-27 09:59:21 +02:00
# 6th optional parameter: TWEAK-BOOTDRIVE
# ---------------------------------------
# could be 'true' (default) or 'false'
# If 'true' it will try (based on the base OS) to optimize the boot drive.
# If 'false' this will skipped.
tweakBootdrives="${6:-true}"
if [ "${tweakBootdrives}" != "true" ] && [ "${tweakBootdrives}" != "false" ]; then
echo "ERROR: TWEAK-BOOTDRIVE parameter needs to be either 'true' or 'false'"
exit 1
fi
echo "6) TWEAK-BOOTDRIVE --> '${tweakBootdrives}'"
2021-08-27 09:59:21 +02:00
# 7th optional parameter: WIFI
# ---------------------------------------
# could be 'false' or 'true' (default) or a valid WIFI country code like 'US' (default)
# If 'false' WIFI will be deactivated by default
# If 'true' WIFI will be activated by with default country code 'US'
# If any valid wifi country code Wifi will be activated with that country code by default
modeWifi="${7:-US}"
[ "${modeWifi}" = "true" ] && modeWifi="US"
echo "7) WIFI --> '${modeWifi}'"
# AUTO-DETECTION: CPU-ARCHITECTURE
# ---------------------------------------
cpu="$(uname -m)"
architecture="$(dpkg --print-architecture)"
case "${cpu}" in
arm*|aarch64|x86_64|amd64);;
*) echo -e "!!! FAIL !!!\nCan only build on ARM, aarch64, x86_64 not on: cpu=${cpu}"; exit 1;;
esac
echo "X) CPU-ARCHITECTURE --> '${cpu} (${architecture})'"
2018-10-13 22:43:07 +02:00
# AUTO-DETECTION: OPERATINGSYSTEM
# ---------------------------------------
if [ $(grep -c 'Debian' /etc/os-release 2>/dev/null) -gt 0 ]; then
if [ $(uname -n | grep -c 'raspberrypi') -gt 0 ] && [ "${cpu}" = aarch64 ]; then
# default image for RaspberryPi
baseimage="raspios_arm64"
elif [ $(uname -n | grep -c 'rpi') -gt 0 ] && [ "${cpu}" = aarch64 ]; then
# experimental: a clean alternative image of debian for RaspberryPi
baseimage="debian_rpi64"
elif [ "${cpu}" = "arm" ] || [ "${cpu}" = "aarch64" ]; then
# experimental: fallback for all debian on arm
baseimage="armbian"
else
# experimental: fallback for all debian on other CPUs
baseimage="debian"
fi
elif [ $(grep -c 'Ubuntu' /etc/os-release 2>/dev/null) -gt 0 ]; then
baseimage="ubuntu"
else
2018-10-13 22:43:07 +02:00
cat /etc/os-release 2>/dev/null
uname -a
echo "!!! FAIL: Base Image cannot be detected or is not supported."
2018-10-13 22:43:07 +02:00
exit 1
fi
echo "X) OPERATING-SYSTEM ---> '${baseimage}'"
# USER-CONFIRMATION
if [ "${noInteraction}" != "true" ]; then
echo -n "# Do you agree with all parameters above? (yes/no) "
read -r installRaspiblitzAnswer
[ "$installRaspiblitzAnswer" != "yes" ] && exit 1
fi
echo -e "Building RaspiBlitz ...\n"
sleep 3 ## give time to cancel
export DEBIAN_FRONTEND=noninteractive
# FIXING LOCALES
# https://github.com/rootzoll/raspiblitz/issues/138
# https://daker.me/2014/10/how-to-fix-perl-warning-setting-locale-failed-in-raspbian.html
# https://stackoverflow.com/questions/38188762/generate-all-locales-in-a-docker-image
if [ "${baseimage}" = "raspios_arm64" ]||[ "${baseimage}" = "debian_rpi64" ]; then
echo -e "\n*** FIXING LOCALES FOR BUILD ***"
2019-08-07 23:11:45 +02:00
2019-04-14 12:08:18 +02:00
sudo sed -i "s/^# en_US.UTF-8 UTF-8.*/en_US.UTF-8 UTF-8/g" /etc/locale.gen
sudo sed -i "s/^# en_US ISO-8859-1.*/en_US ISO-8859-1/g" /etc/locale.gen
sudo locale-gen
2020-01-20 20:37:30 +01:00
export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
if [ ! -f /etc/apt/sources.list.d/raspi.list ]; then
echo "# Add the archive.raspberrypi.org/debian/ to the sources.list"
echo "deb http://archive.raspberrypi.org/debian/ bullseye main" | sudo tee /etc/apt/sources.list.d/raspi.list
fi
2019-04-14 12:08:18 +02:00
fi
2018-12-01 22:33:18 +01:00
echo "*** Remove unnecessary packages ***"
sudo apt remove --purge -y libreoffice* oracle-java* chromium-browser nuscratch scratch sonic-pi plymouth python2 vlc
sudo apt clean -y
sudo apt autoremove -y
2019-11-27 08:49:11 +01:00
echo -e "\n*** UPDATE Debian***"
sudo apt update -y
sudo apt upgrade -f -y
2021-08-19 18:52:12 +02:00
echo -e "\n*** SOFTWARE UPDATE ***"
# based on https://stadicus.github.io/RaspiBolt/raspibolt_20_pi.html#software-update
# htop git curl bash-completion vim jq dphys-swapfile bsdmainutils -> helpers
# autossh telnet vnstat -> network tools bandwidth monitoring for future statistics
# parted dosfstolls -> prepare for format data drive
# btrfs-progs -> prepare for BTRFS data drive raid
# fbi -> prepare for display graphics mode. https://github.com/rootzoll/raspiblitz/pull/334
# sysbench -> prepare for powertest
# build-essential -> check for build dependencies on Ubuntu, Armbian
# dialog -> dialog bc python3-dialog
# rsync -> is needed to copy from HDD
# net-tools -> ifconfig
# xxd -> display hex codes
# netcat -> for proxy
# openssh-client openssh-sftp-server sshpass -> install OpenSSH client + server
# psmisc -> install killall, fuser
# ufw -> firewall
# sqlite3 -> database
general_utils="htop git curl bash-completion vim jq dphys-swapfile bsdmainutils autossh telnet vnstat parted dosfstools btrfs-progs fbi sysbench build-essential dialog bc python3-dialog"
python_dependencies="python3-venv python3-dev python3-wheel python3-jinja2 python3-pip"
server_utils="rsync net-tools xxd netcat openssh-client openssh-sftp-server sshpass psmisc ufw sqlite3"
[ "${baseimage}" = "armbian" ] && armbian_dependencies="armbian-config" # add armbian-config
sudo apt install -y ${general_utils} ${python_dependencies} ${server_utils} ${armbian_dependencies}
sudo apt clean -y
sudo apt autoremove -y
echo -e "\n*** Python DEFAULT libs & dependencies ***"
# make sure /usr/bin/pip exists (and calls pip3 in Debian Buster)
sudo update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1
# 1. libs (for global python scripts)
# grpcio==1.42.0 googleapis-common-protos==1.53.0 toml==0.10.2 j2cli==0.3.10 requests[socks]==2.21.0
# 2. For TorBox bridges python scripts (pip3) https://github.com/radio24/TorBox/blob/master/requirements.txt
# pytesseract mechanize PySocks urwid Pillow requests
# 3. Nyx
# setuptools
python_libs="grpcio==1.42.0 googleapis-common-protos==1.53.0 toml==0.10.2 j2cli==0.3.10 requests[socks]==2.21.0"
torbox_libs="pytesseract mechanize PySocks urwid Pillow requests setuptools"
sudo -H python3 -m pip install --upgrade pip
sudo -H python3 -m pip install ${python_libs} ${torbox_libs}
if [ -f "/usr/bin/python3.9" ]; then
# use python 3.9 if available
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.9 1
echo "python calls python3.9"
elif [ -f "/usr/bin/python3.10" ]; then
# use python 3.10 if available
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.10 1
sudo ln -s /usr/bin/python3.10 /usr/bin/python3.9
echo "python calls python3.10"
else
echo "!!! FAIL !!!"
echo "There is no tested version of python present"
exit 1
fi
2019-11-27 08:49:11 +01:00
echo -e "\n*** PREPARE ${baseimage} ***"
2019-04-14 12:08:18 +02:00
# make sure the pi user is present
if [ "$(compgen -u | grep -c pi)" -eq 0 ];then
echo "# Adding the user pi"
sudo adduser --disabled-password --gecos "" pi
sudo adduser pi sudo
2018-10-13 22:43:07 +02:00
fi
# special prepare when Raspbian
if [ "${baseimage}" = "raspios_arm64" ] || [ "${baseimage}" = "debian_rpi64" ]; then
2021-08-19 16:04:13 +02:00
echo -e "\n*** PREPARE RASPBERRY OS VARIANTS ***"
sudo apt install -y raspi-config
2018-10-13 22:43:07 +02:00
# do memory split (16MB)
sudo raspi-config nonint do_memory_split 16
# set to wait until network is available on boot (0 seems to yes)
sudo raspi-config nonint do_boot_wait 0
2018-10-19 15:35:38 +02:00
# set WIFI country so boot does not block
# this will undo the softblock of rfkill on RaspiOS
[ "${modeWifi}" != "false" ] && sudo raspi-config nonint do_wifi_country $modeWifi
2019-03-14 13:14:04 +01:00
# see https://github.com/rootzoll/raspiblitz/issues/428#issuecomment-472822840
configFile="/boot/config.txt"
max_usb_current="max_usb_current=1"
2021-03-23 14:03:03 +01:00
max_usb_currentDone=$(grep -c "$max_usb_current" $configFile)
if [ ${max_usb_currentDone} -eq 0 ]; then
echo | sudo tee -a $configFile
2021-03-23 14:03:03 +01:00
echo "# Raspiblitz" | sudo tee -a $configFile
echo "$max_usb_current" | sudo tee -a $configFile
else
echo "$max_usb_current already in $configFile"
fi
2020-07-16 15:20:33 +02:00
# run fsck on sd root partition on every startup to prevent "maintenance login" screen
# see: https://github.com/rootzoll/raspiblitz/issues/782#issuecomment-564981630
2020-03-19 06:57:12 +01:00
# see https://github.com/rootzoll/raspiblitz/issues/1053#issuecomment-600878695
# use command to check last fsck check: sudo tune2fs -l /dev/mmcblk0p2
if [ "${tweakBootdrives}" == "true" ]; then
echo "* running tune2fs"
sudo tune2fs -c 1 /dev/mmcblk0p2
else
echo "* skipping tweakBootdrives"
fi
# edit kernel parameters
kernelOptionsFile=/boot/cmdline.txt
fsOption1="fsck.mode=force"
fsOption2="fsck.repair=yes"
2021-03-23 14:03:03 +01:00
fsOption1InFile=$(grep -c ${fsOption1} ${kernelOptionsFile})
fsOption2InFile=$(grep -c ${fsOption2} ${kernelOptionsFile})
if [ ${fsOption1InFile} -eq 0 ]; then
sudo sed -i "s/^/$fsOption1 /g" "$kernelOptionsFile"
echo "$fsOption1 added to $kernelOptionsFile"
else
echo "$fsOption1 already in $kernelOptionsFile"
fi
if [ ${fsOption2InFile} -eq 0 ]; then
sudo sed -i "s/^/$fsOption2 /g" "$kernelOptionsFile"
echo "$fsOption2 added to $kernelOptionsFile"
else
echo "$fsOption2 already in $kernelOptionsFile"
fi
2019-04-14 12:08:18 +02:00
fi
2019-10-06 12:57:48 +02:00
# special prepare when Nvidia Jetson Nano
if [ $(uname -a | grep -c 'tegra') -gt 0 ] ; then
2021-08-19 16:04:13 +02:00
echo "Nvidia --> disable GUI on boot"
sudo systemctl set-default multi-user.target
fi
echo -e "\n*** CONFIG ***"
# based on https://raspibolt.github.io/raspibolt/raspibolt_20_pi.html#raspi-config
2018-08-06 01:03:17 +02:00
# set new default password for root user
2018-08-06 01:03:17 +02:00
echo "root:raspiblitz" | sudo chpasswd
echo "pi:raspiblitz" | sudo chpasswd
# prepare auto-start of 00infoLCD.sh script on pi user login (just kicks in if auto-login of pi is activated in HDMI or LCD mode)
if [ "${baseimage}" = "raspios_arm64" ] || [ "${baseimage}" = "debian_rpi64" ] || \
[ "${baseimage}" = "armbian" ] || [ "${baseimage}" = "ubuntu" ]; then
homeFile=/home/pi/.bashrc
autostartDone=$(grep -c "automatic start the LCD" $homeFile)
if [ ${autostartDone} -eq 0 ]; then
# bash autostart for pi
# run as exec to dont allow easy physical access by keyboard
# see https://github.com/rootzoll/raspiblitz/issues/54
sudo bash -c 'echo "# automatic start the LCD info loop" >> /home/pi/.bashrc'
sudo bash -c 'echo "SCRIPT=/home/admin/00infoLCD.sh" >> /home/pi/.bashrc'
sudo bash -c 'echo "# replace shell with script => logout when exiting script" >> /home/pi/.bashrc'
sudo bash -c 'echo "exec \$SCRIPT" >> /home/pi/.bashrc'
echo "autostart LCD added to $homeFile"
2021-04-08 00:02:57 +02:00
else
echo "autostart LCD already in $homeFile"
fi
2021-04-08 00:02:57 +02:00
else
echo "WARN: Script Autostart not available for baseimage(${baseimage}) - may just run on 'headless'"
2019-04-14 12:08:18 +02:00
fi
2019-03-13 17:00:44 +01:00
# change log rotates
# see https://github.com/rootzoll/raspiblitz/issues/394#issuecomment-471535483
echo "
/var/log/syslog
{
rotate 7
daily
missingok
notifempty
delaycompress
compress
postrotate
invoke-rc.d rsyslog rotate > /dev/null
endscript
}
/var/log/mail.info
/var/log/mail.warn
/var/log/mail.err
/var/log/mail.log
/var/log/daemon.log
{
rotate 4
size=100M
missingok
notifempty
compress
delaycompress
sharedscripts
postrotate
invoke-rc.d rsyslog rotate > /dev/null
enscript
}
/var/log/kern.log
/var/log/auth.log
{
rotate 4
size=100M
missingok
notifempty
compress
delaycompress
sharedscripts
postrotate
invoke-rc.d rsyslog rotate > /dev/null
endscript
}
/var/log/user.log
/var/log/lpr.log
/var/log/cron.log
/var/log/debug
/var/log/messages
{
rotate 4
weekly
missingok
notifempty
compress
delaycompress
sharedscripts
postrotate
invoke-rc.d rsyslog rotate > /dev/null
endscript
}
" | sudo tee ./rsyslog
2019-03-13 17:00:44 +01:00
sudo mv ./rsyslog /etc/logrotate.d/rsyslog
sudo chown root:root /etc/logrotate.d/rsyslog
sudo service rsyslog restart
echo -e "\n*** ADDING MAIN USER admin ***"
# based on https://stadicus.github.io/RaspiBolt/raspibolt_20_pi.html#add-users
2018-08-06 01:03:17 +02:00
# using the default password 'raspiblitz'
2021-12-12 19:19:16 +01:00
sudo adduser --disabled-password --gecos "" admin
2018-08-06 01:03:17 +02:00
echo "admin:raspiblitz" | sudo chpasswd
sudo adduser admin sudo
sudo chsh admin -s /bin/bash
# configure sudo for usage without password entry
2018-08-06 21:33:16 +02:00
echo '%sudo ALL=(ALL) NOPASSWD:ALL' | sudo EDITOR='tee -a' visudo
# check if group "admin" was created
if [ $(sudo cat /etc/group | grep -c "^admin") -lt 1 ]; then
echo -e "\nMissing group admin - creating it ..."
sudo /usr/sbin/groupadd --force --gid 1002 admin
sudo usermod -a -G admin admin
else
echo -e "\nOK group admin exists"
fi
2018-08-06 01:03:17 +02:00
echo -e "\n*** ADDING SERVICE USER bitcoin"
# based on https://stadicus.github.io/RaspiBolt/raspibolt_20_pi.html#add-users
2018-08-06 01:03:17 +02:00
# create user and set default password for user
sudo adduser --disabled-password --gecos "" bitcoin
echo "bitcoin:raspiblitz" | sudo chpasswd
# make home directory readable
sudo chmod 755 /home/bitcoin
2018-08-06 01:03:17 +02:00
# WRITE BASIC raspiblitz.info to sdcard
# if further info gets added .. make sure to keep that on: blitz.preparerelease.sh
sudo touch /home/admin/raspiblitz.info
echo "baseimage=${baseimage}" | tee raspiblitz.info
echo "cpu=${cpu}" | tee -a raspiblitz.info
echo "displayClass=headless" | tee -a raspiblitz.info
sudo mv raspiblitz.info /home/admin/
sudo chmod 755 /home/admin/raspiblitz.info
echo -e "\n*** ADDING GROUPS FOR CREDENTIALS STORE ***"
# access to credentials (e.g. macaroon files) in a central location is managed with unix groups and permissions
sudo /usr/sbin/groupadd --force --gid 9700 lndadmin
sudo /usr/sbin/groupadd --force --gid 9701 lndinvoice
sudo /usr/sbin/groupadd --force --gid 9702 lndreadonly
sudo /usr/sbin/groupadd --force --gid 9703 lndinvoices
sudo /usr/sbin/groupadd --force --gid 9704 lndchainnotifier
sudo /usr/sbin/groupadd --force --gid 9705 lndsigner
sudo /usr/sbin/groupadd --force --gid 9706 lndwalletkit
sudo /usr/sbin/groupadd --force --gid 9707 lndrouter
echo -e "\n*** SHELL SCRIPTS & ASSETS ***"
# copy raspiblitz repo from github
cd /home/admin/ || exit 1
sudo -u admin git config --global user.name "${githubUser}"
sudo -u admin git config --global user.email "johndoe@example.com"
sudo -u admin rm -rf /home/admin/raspiblitz
sudo -u admin git clone -b "${githubBranch}" https://github.com/${githubUser}/raspiblitz.git
sudo -u admin cp -r /home/admin/raspiblitz/home.admin/*.* /home/admin
sudo -u admin cp /home/admin/raspiblitz/home.admin/.tmux.conf /home/admin
sudo -u admin cp -r /home/admin/raspiblitz/home.admin/assets /home/admin/
sudo -u admin chmod +x *.sh
sudo -u admin cp -r /home/admin/raspiblitz/home.admin/config.scripts /home/admin/
sudo -u admin chmod +x /home/admin/config.scripts/*.sh
sudo -u admin cp -r /home/admin/raspiblitz/home.admin/setup.scripts /home/admin/
sudo -u admin chmod +x /home/admin/setup.scripts/*.sh
# install newest version of BlitzPy
blitzpy_wheel=$(ls -tR /home/admin/raspiblitz/home.admin/BlitzPy/dist | grep -E "any.whl" | tail -n 1)
blitzpy_version=$(echo "${blitzpy_wheel}" | grep -oE "([0-9]\.[0-9]\.[0-9])")
echo -e "\n*** INSTALLING BlitzPy Version: ${blitzpy_version} ***"
sudo -H /usr/bin/python -m pip install "/home/admin/raspiblitz/home.admin/BlitzPy/dist/${blitzpy_wheel}" >/dev/null 2>&1
# make sure lndlibs are patched for compatibility for both Python2 and Python3
file="/home/admin/config.scripts/lndlibs/rpc_pb2_grpc.py"
! grep -Fxq "from __future__ import absolute_import" "${file}" && sed -i -E '1 a from __future__ import absolute_import' "${file}"
! grep -Eq "^from . import.*" "${file}" && sed -i -E 's/^(import.*_pb2)/from . \1/' "${file}"
# add /sbin to path for all
sudo bash -c "echo 'PATH=\$PATH:/sbin' >> /etc/profile"
2021-09-06 16:44:12 +02:00
# replace boot splash image when raspbian
[ "${baseimage}" = "raspios_arm64" ] && { echo "* replacing boot splash"; sudo cp /home/admin/raspiblitz/pictures/splash.png /usr/share/plymouth/themes/pix/splash.png; }
echo -e "\n*** RASPIBLITZ EXTRAS ***"
# screen for background processes
# tmux for multiple (detachable/background) sessions when using SSH https://github.com/rootzoll/raspiblitz/issues/990
# fzf install a command-line fuzzy finder (https://github.com/junegunn/fzf)
sudo apt -y install tmux screen fzf
2021-12-08 17:04:30 +01:00
sudo bash -c "echo '' >> /home/admin/.bashrc"
sudo bash -c "echo '# https://github.com/rootzoll/raspiblitz/issues/1784' >> /home/admin/.bashrc"
sudo bash -c "echo 'NG_CLI_ANALYTICS=ci' >> /home/admin/.bashrc"
2021-12-09 18:15:25 +01:00
# raspiblitz custom command prompt #2400
if ! grep -Eq "^[[:space:]]*PS1.*₿" /home/admin/.bashrc; then
sudo sed -i '/^unset color_prompt force_color_prompt$/i # raspiblitz custom command prompt https://github.com/rootzoll/raspiblitz/issues/2400' /home/admin/.bashrc
sudo sed -i '/^unset color_prompt force_color_prompt$/i raspiIp=$(hostname -I | cut -d " " -f1)' /home/admin/.bashrc
sudo sed -i '/^unset color_prompt force_color_prompt$/i if [ "$color_prompt" = yes ]; then' /home/admin/.bashrc
sudo sed -i '/^unset color_prompt force_color_prompt$/i \ PS1=\x27${debian_chroot:+($debian_chroot)}\\[\\033[00;33m\\]\\u@$raspiIp:\\[\\033[00;34m\\]\\w\\[\\033[01;35m\\]$(__git_ps1 "(%s)") \\[\\033[01;33m\\]₿\\[\\033[00m\\] \x27' /home/admin/.bashrc
sudo sed -i '/^unset color_prompt force_color_prompt$/i else' /home/admin/.bashrc
sudo sed -i '/^unset color_prompt force_color_prompt$/i \ PS1=\x27${debian_chroot:+($debian_chroot)}\\u@$raspiIp:\\w₿ \x27' /home/admin/.bashrc
sudo sed -i '/^unset color_prompt force_color_prompt$/i fi' /home/admin/.bashrc
fi
echo -e "\n*** FUZZY FINDER KEY BINDINGS ***"
2021-12-08 17:04:30 +01:00
homeFile=/home/admin/.bashrc
keyBindingsDone=$(grep -c "source /usr/share/doc/fzf/examples/key-bindings.bash" $homeFile)
2021-12-08 17:04:30 +01:00
if [ ${keyBindingsDone} -eq 0 ]; then
sudo bash -c "echo 'source /usr/share/doc/fzf/examples/key-bindings.bash' >> /home/admin/.bashrc"
echo "key-bindings added to $homeFile"
else
echo "key-bindings already in $homeFile"
fi
echo -e "\n*** AUTOSTART ADMIN SSH MENUS ***"
2021-12-08 17:04:30 +01:00
homeFile=/home/admin/.bashrc
autostartDone=$(grep -c "automatically start main menu" $homeFile)
2021-12-08 17:04:30 +01:00
if [ ${autostartDone} -eq 0 ]; then
# bash autostart for admin
sudo bash -c "echo '# shortcut commands' >> /home/admin/.bashrc"
sudo bash -c "echo 'source /home/admin/_commands.sh' >> /home/admin/.bashrc"
sudo bash -c "echo '# automatically start main menu for admin unless' >> /home/admin/.bashrc"
sudo bash -c "echo '# when running in a tmux session' >> /home/admin/.bashrc"
sudo bash -c "echo 'if [ -z \"\$TMUX\" ]; then' >> /home/admin/.bashrc"
sudo bash -c "echo ' ./00raspiblitz.sh newsshsession' >> /home/admin/.bashrc"
2021-12-08 17:04:30 +01:00
sudo bash -c "echo 'fi' >> /home/admin/.bashrc"
echo "autostart added to $homeFile"
else
echo "autostart already in $homeFile"
fi
echo -e "\n*** SWAP FILE ***"
# based on https://stadicus.github.io/RaspiBolt/raspibolt_20_pi.html#move-swap-file
2021-12-08 17:04:30 +01:00
# but just deactivating and deleting old (will be created alter when user adds HDD)
sudo dphys-swapfile swapoff
sudo dphys-swapfile uninstall
echo -e "\n*** INCREASE OPEN FILE LIMIT ***"
# based on https://stadicus.github.io/RaspiBolt/raspibolt_21_security.html#increase-your-open-files-limit
2021-12-19 16:40:08 +01:00
sudo sed --in-place -i "56s/.*/* soft nofile 256000/" /etc/security/limits.conf
sudo bash -c "echo '* hard nofile 256000' >> /etc/security/limits.conf"
sudo bash -c "echo 'root soft nofile 256000' >> /etc/security/limits.conf"
sudo bash -c "echo 'root hard nofile 256000' >> /etc/security/limits.conf"
2021-12-08 17:04:30 +01:00
sudo bash -c "echo '# End of file' >> /etc/security/limits.conf"
sudo sed --in-place -i "23s/.*/session required pam_limits.so/" /etc/pam.d/common-session
sudo sed --in-place -i "25s/.*/session required pam_limits.so/" /etc/pam.d/common-session-noninteractive
sudo bash -c "echo '# end of pam-auth-update config' >> /etc/pam.d/common-session-noninteractive"
# *** fail2ban ***
# based on https://raspibolt.github.io/raspibolt/raspibolt_21_security.html#fail2ban
echo "*** HARDENING ***"
sudo apt install -y --no-install-recommends python3-systemd fail2ban
2021-12-08 17:04:30 +01:00
# *** CACHE DISK IN RAM & KEYVALUE-STORE***
2021-12-08 17:04:30 +01:00
echo "Activating CACHE RAM DISK ... "
sudo /home/admin/_cache.sh ramdisk on
sudo /home/admin/_cache.sh keyvalue on
# *** Wifi, Bluetooth & other RaspberryPi configs ***
if [ "${baseimage}" = "raspios_arm64" ] || [ "${baseimage}" = "debian_rpi64" ]; then
2021-12-08 17:04:30 +01:00
if [ "${modeWifi}" == "false" ]; then
echo -e "\n*** DISABLE WIFI ***"
2021-12-08 17:04:30 +01:00
sudo systemctl disable wpa_supplicant.service
sudo ifconfig wlan0 down
fi
echo -e "\n*** DISABLE BLUETOOTH ***"
2021-12-08 17:04:30 +01:00
configFile="/boot/config.txt"
disableBT="dtoverlay=disable-bt"
disableBTDone=$(grep -c "$disableBT" $configFile)
if [ "${disableBTDone}" -eq 0 ]; then
2021-12-08 17:04:30 +01:00
# disable bluetooth module
echo "" | sudo tee -a $configFile
echo "# Raspiblitz" | sudo tee -a $configFile
2021-12-08 17:04:30 +01:00
echo 'dtoverlay=pi3-disable-bt' | sudo tee -a $configFile
echo 'dtoverlay=disable-bt' | sudo tee -a $configFile
else
echo "disable BT already in $configFile"
fi
# remove bluetooth services
sudo systemctl disable bluetooth.service
sudo systemctl disable hciuart.service
# remove bluetooth packages
sudo apt remove -y --purge pi-bluetooth bluez bluez-firmware
# disable audio
echo -e "\n*** DISABLE AUDIO (snd_bcm2835) ***"
2021-12-08 17:04:30 +01:00
sudo sed -i "s/^dtparam=audio=on/# dtparam=audio=on/g" /boot/config.txt
2021-12-08 17:04:30 +01:00
# disable DRM VC4 V3D
echo -e "\n*** DISABLE DRM VC4 V3D driver ***"
2021-12-08 17:04:30 +01:00
dtoverlay=vc4-fkms-v3d
sudo sed -i "s/^dtoverlay=${dtoverlay}/# dtoverlay=${dtoverlay}/g" /boot/config.txt
2021-12-08 17:04:30 +01:00
# I2C fix (make sure dtparam=i2c_arm is not on)
# see: https://github.com/rootzoll/raspiblitz/issues/1058#issuecomment-739517713
sudo sed -i "s/^dtparam=i2c_arm=.*//g" /boot/config.txt
2021-12-08 17:04:30 +01:00
fi
# *** FATPACK *** (can be activated by parameter - see details at start of script)
if [ "${fatpack}" == "true" ]; then
echo -e "\n*** FATPACK ***"
2021-12-08 17:04:30 +01:00
echo "* Adding nodeJS Framework ..."
sudo /home/admin/config.scripts/bonus.nodejs.sh on
if [ "$?" != "0" ]; then
echo "FATPACK FAILED"
exit 1
fi
echo "* Optional Packages (may be needed for extended features)"
sudo apt install -y qrencode btrfs-tools secure-delete fbi ssmtp unclutter xterm python3-pyqt5 xfonts-terminus apache2-utils nginx python3-jinja2 socat libatlas-base-dev hexyl autossh
2021-12-08 17:04:30 +01:00
# *** UPDATE FALLBACK NODE LIST (only as part of fatpack) *** see https://github.com/rootzoll/raspiblitz/issues/1888
echo "*** FALLBACK NODE LIST ***"
sudo -u admin curl -H "Accept: application/json; indent=4" https://bitnodes.io/api/v1/snapshots/latest/ -o /home/admin/fallback.nodes
byteSizeList=$(sudo -u admin stat -c %s /home/admin/fallback.nodes)
if [ ${#byteSizeList} -eq 0 ] || [ ${byteSizeList} -lt 10240 ]; then
2021-12-08 17:04:30 +01:00
echo "WARN: Failed downloading fresh FALLBACK NODE LIST --> https://bitnodes.io/api/v1/snapshots/latest/"
sudo rm /home/admin/fallback.nodes 2>/dev/null
sudo cp /home/admin/assets/fallback.nodes /home/admin/fallback.nodes
fi
sudo chown admin:admin /home/admin/fallback.nodes
else
echo "* skipping FATPACK"
fi
# *** BOOTSTRAP ***
echo -e "\n*** RASPI BOOTSTRAP SERVICE ***"
2021-12-08 17:04:30 +01:00
sudo chmod +x /home/admin/_bootstrap.sh
sudo cp /home/admin/assets/bootstrap.service /etc/systemd/system/bootstrap.service
sudo systemctl enable bootstrap
# *** BACKGROUND TASKS ***
echo -e "\n*** RASPI BACKGROUND SERVICE ***"
2021-12-08 17:04:30 +01:00
sudo chmod +x /home/admin/_background.sh
sudo cp /home/admin/assets/background.service /etc/systemd/system/background.service
sudo systemctl enable background
# *** BACKGROUND SCAN ***
/home/admin/_background.scan.sh install
2021-12-08 17:04:30 +01:00
#######
# TOR #
2021-12-08 17:04:30 +01:00
#######
echo
/home/admin/config.scripts/tor.install.sh install || exit 1
###########
# BITCOIN #
###########
echo
/home/admin/config.scripts/bitcoin.install.sh install || exit 1
2019-05-07 02:42:51 +02:00
#######
# LND #
#######
echo
if [ "${fatpack}" == "true" ]; then
/home/admin/config.scripts/lnd.install.sh install || exit 1
else
echo -e "\nSkipping LND install - let user install later if needed ..."
fi
###############
# C-LIGHTNING #
###############
echo
if [ "${fatpack}" == "true" ]; then
/home/admin/config.scripts/cl.install.sh install || exit 1
else
echo -e "\nSkipping c-lightning install - let user install later if needed ..."
fi
echo
2021-04-08 00:02:57 +02:00
echo "*** raspiblitz.info ***"
sudo cat /home/admin/raspiblitz.info
2021-04-08 00:02:57 +02:00
# *** RASPIBLITZ IMAGE READY INFO ***
echo -e "\n**********************************************"
2021-04-08 00:02:57 +02:00
echo "BASIC SD CARD BUILD DONE"
echo -e "**********************************************\n"
2021-04-08 00:02:57 +02:00
echo "Your SD Card Image for RaspiBlitz is ready (might still do display config)."
echo "Take the chance & look thru the output above if you can spot any errors or warnings."
echo -e "\nIMPORTANT IF WANT TO MAKE A RELEASE IMAGE FROM THIS BUILD:"
2021-04-08 00:02:57 +02:00
echo "1. login fresh --> user:admin password:raspiblitz"
echo -e "2. run --> release\n"
2021-04-08 00:02:57 +02:00
# (do last - because might trigger reboot)
if [ "${displayClass}" != "headless" ] || [ "${baseimage}" = "raspios_arm64" ]; then
2021-04-08 00:02:57 +02:00
echo "*** ADDITIONAL DISPLAY OPTIONS ***"
echo "- calling: blitz.display.sh set-display ${displayClass}"
sudo /home/admin/config.scripts/blitz.display.sh set-display ${displayClass}
2021-09-05 12:45:03 +02:00
sudo /home/admin/config.scripts/blitz.display.sh rotate 1
2021-08-17 19:02:53 +02:00
fi
echo "# BUILD DONE - see above"