From e87a59acec963cdeafa9f0d478eab47f581dacd0 Mon Sep 17 00:00:00 2001 From: Josef-MrBeam Date: Fri, 24 Nov 2023 08:57:12 +0100 Subject: [PATCH 01/35] prepare proof of concept migration OS --- .github/workflows/build.yml | 4 +- src/modules/beamos/config | 18 +- .../analytics/root/etc/logrotate.d/analytics | 13 - .../beamos/filesystem/home/pi/.bash_history | 37 - src/modules/beamos/filesystem/home/pi/.bashrc | 79 -- .../beamos/filesystem/home/pi/.config/aliases | 54 -- .../filesystem/home/pi/.config/disclaimer | 1 - .../filesystem/home/pi/.config/htop/htoprc | 25 - .../filesystem/home/pi/.config/logo_ascii | 12 - .../home/pi/.config/neofetch/config.conf | 787 ------------------ .../beamos/filesystem/home/pi/.config/shellrc | 62 -- .../beamos/filesystem/home/pi/.hushlogin | 0 .../filesystem/home/pi/.octoprint/config.yaml | 31 - .../home/pi/.octoprint/config.yaml.dev | 20 - .../pi/.octoprint/uploads/Focus_Lehre.svg | 467 ----------- .../home/pi/.octoprint/uploads/MrBeam.svg | 26 - .../pi/.octoprint/uploads/MrBeam_Logo.svg | 38 - .../Schlu\314\210sselanha\314\210nger.svg" | 48 -- .../home/pi/.octoprint/users-dev.yaml | 19 - .../home/pi/scripts/fake-hwclock_cron_job | 1 - .../home/pi/scripts/reset_script.sh | 55 -- .../iobeam/root/etc/logrotate.d/iobeam | 11 - .../root/etc/systemd/system/iobeam.service | 11 - .../beamos/filesystem/known_hosts_bitbucket | 2 - .../mount_manager/home/pi/usb_mount/README.md | 1 - .../root/etc/logrotate.d/mount_manager | 12 - .../systemd/system/mount_manager_add.service | 6 - .../system/mount_manager_clear.service | 10 - .../system/mount_manager_remove.service | 3 - .../mount_manager_remove_before_octo.service | 10 - .../root/usr/share/mount_manager/pubkey.asc | 31 - .../mrb_check/root/etc/logrotate.d/mrb_check | 12 - .../mrb_check/root/usr/share/mrb_check.yaml | 29 - .../root/etc/logrotate.d/netconnectd | 11 - .../beamos/filesystem/repos/mount_manager | 1 - src/modules/beamos/filesystem/repos/mrb_check | 1 - .../root/etc/init.d/beamos_first_boot | 28 - .../filesystem/root/usr/bin/beamos_hostname | 52 -- .../filesystem/root/usr/bin/beamos_serial | 19 - .../filesystem/ssh/.ssh/authorized_keys | 1 - src/modules/octopi/config | 2 +- src/variants/beamos/config | 8 +- 42 files changed, 16 insertions(+), 2042 deletions(-) delete mode 100644 src/modules/beamos/filesystem/analytics/root/etc/logrotate.d/analytics delete mode 100644 src/modules/beamos/filesystem/home/pi/.bash_history delete mode 100644 src/modules/beamos/filesystem/home/pi/.bashrc delete mode 100644 src/modules/beamos/filesystem/home/pi/.config/aliases delete mode 100644 src/modules/beamos/filesystem/home/pi/.config/disclaimer delete mode 100644 src/modules/beamos/filesystem/home/pi/.config/htop/htoprc delete mode 100644 src/modules/beamos/filesystem/home/pi/.config/logo_ascii delete mode 100644 src/modules/beamos/filesystem/home/pi/.config/neofetch/config.conf delete mode 100644 src/modules/beamos/filesystem/home/pi/.config/shellrc delete mode 100644 src/modules/beamos/filesystem/home/pi/.hushlogin delete mode 100644 src/modules/beamos/filesystem/home/pi/.octoprint/config.yaml delete mode 100644 src/modules/beamos/filesystem/home/pi/.octoprint/config.yaml.dev delete mode 100644 src/modules/beamos/filesystem/home/pi/.octoprint/uploads/Focus_Lehre.svg delete mode 100644 src/modules/beamos/filesystem/home/pi/.octoprint/uploads/MrBeam.svg delete mode 100644 src/modules/beamos/filesystem/home/pi/.octoprint/uploads/MrBeam_Logo.svg delete mode 100644 "src/modules/beamos/filesystem/home/pi/.octoprint/uploads/Schlu\314\210sselanha\314\210nger.svg" delete mode 100644 src/modules/beamos/filesystem/home/pi/.octoprint/users-dev.yaml delete mode 100644 src/modules/beamos/filesystem/home/pi/scripts/fake-hwclock_cron_job delete mode 100755 src/modules/beamos/filesystem/home/pi/scripts/reset_script.sh delete mode 100644 src/modules/beamos/filesystem/iobeam/root/etc/logrotate.d/iobeam delete mode 100644 src/modules/beamos/filesystem/iobeam/root/etc/systemd/system/iobeam.service delete mode 100644 src/modules/beamos/filesystem/known_hosts_bitbucket delete mode 100644 src/modules/beamos/filesystem/mount_manager/home/pi/usb_mount/README.md delete mode 100644 src/modules/beamos/filesystem/mount_manager/root/etc/logrotate.d/mount_manager delete mode 100644 src/modules/beamos/filesystem/mount_manager/root/etc/systemd/system/mount_manager_add.service delete mode 100644 src/modules/beamos/filesystem/mount_manager/root/etc/systemd/system/mount_manager_clear.service delete mode 100644 src/modules/beamos/filesystem/mount_manager/root/etc/systemd/system/mount_manager_remove.service delete mode 100644 src/modules/beamos/filesystem/mount_manager/root/etc/systemd/system/mount_manager_remove_before_octo.service delete mode 100644 src/modules/beamos/filesystem/mount_manager/root/usr/share/mount_manager/pubkey.asc delete mode 100644 src/modules/beamos/filesystem/mrb_check/root/etc/logrotate.d/mrb_check delete mode 100644 src/modules/beamos/filesystem/mrb_check/root/usr/share/mrb_check.yaml delete mode 100644 src/modules/beamos/filesystem/netconnectd/root/etc/logrotate.d/netconnectd delete mode 160000 src/modules/beamos/filesystem/repos/mount_manager delete mode 160000 src/modules/beamos/filesystem/repos/mrb_check delete mode 100755 src/modules/beamos/filesystem/root/usr/bin/beamos_hostname delete mode 100755 src/modules/beamos/filesystem/root/usr/bin/beamos_serial delete mode 100644 src/modules/beamos/filesystem/ssh/.ssh/authorized_keys diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8d7ca5dc..597ae1ed 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,7 +35,7 @@ jobs: else flavors='{"flavor":"2Q"},{"flavor":"2R"}' fi - echo "::set-output name=matrix::{\"include\":[$flavors]}" + echo "matrix={\"include\":[$flavors]}" >> $GITHUB_OUTPUT build: needs: set_matrix @@ -142,7 +142,7 @@ jobs: cp repository/src/workspace/*.img $IMAGE.img fi - echo "::set-output name=image::$IMAGE" + echo "image=$IMAGE" >> $GITHUB_OUTPUT # # artifact upload will take care of zipping for us # - uses: actions/upload-artifact@v1 diff --git a/src/modules/beamos/config b/src/modules/beamos/config index 61a33c10..d79d5712 100755 --- a/src/modules/beamos/config +++ b/src/modules/beamos/config @@ -25,7 +25,7 @@ TRUE_USER=pi [ -n "$BEAMOS_NETCONNECTD_WIFI_REPO_BRANCH" ] || BEAMOS_NETCONNECTD_WIFI_REPO_BRANCH=master # MrBeamPlugin -[ -n "$BEAMOS_INCLUDE_MRBEAMPLUGIN" ] || BEAMOS_INCLUDE_MRBEAMPLUGIN=yes +[ -n "$BEAMOS_INCLUDE_MRBEAMPLUGIN" ] || BEAMOS_INCLUDE_MRBEAMPLUGIN=no # This uses the latest release as an archive # [ -n "$BEAMOS_MRBEAMPLUGIN_ARCHIVE" ] || export BEAMOS_MRBEAMPLUGIN_ARCHIVE=$(wget -q -O - https://api.github.com/repos/mrbeam/MrBeamPlugin/releases/latest | grep "zipball_url" | cut -d : -f 2,3 | tr -d \" | tr -d ,) [ -n "$BEAMOS_MRBEAMPLUGIN_ARCHIVE" ] || BEAMOS_MRBEAMPLUGIN_ARCHIVE=https://github.com/mrbeam/MrBeamPlugin/archive/$BEAMOS_MRBEAMPLUGIN_REPO_BRANCH.zip @@ -38,13 +38,13 @@ TRUE_USER=pi [ -n "$BEAMOS_MRBEAMPLUGIN_DOCS_REPO_BUILD" ] || BEAMOS_MRBEAMPLUGIN_DOCS_REPO_BUILD=https://github.com/mrbeam/MrBeamDoc.git # OctoPrint-Camera -[ -n "$BEAMOS_INCLUDE_CAMERA" ] || BEAMOS_INCLUDE_CAMERA=yes +[ -n "$BEAMOS_INCLUDE_CAMERA" ] || BEAMOS_INCLUDE_CAMERA=no [ -n "$BEAMOS_CAMERA_ARCHIVE" ] || BEAMOS_CAMERA_ARCHIVE=https://github.com/mrbeam/OctoPrint-Camera/archive/$BEAMOS_CAMERA_REPO_BRANCH.zip [ -n "$BEAMOS_CAMERA_REPO_BUILD" ] || BEAMOS_CAMERA_REPO_BUILD=https://github.com/mrbeam/OctoPrint-Camera.git [ -n "$BEAMOS_CAMERA_REPO_SHIP" ] || BEAMOS_CAMERA_REPO_SHIP=https://github.com/mrbeam/OctoPrint-Camera.git # IOBeam -[ -n "$BEAMOS_INCLUDE_IOBEAM" ] || BEAMOS_INCLUDE_IOBEAM=yes +[ -n "$BEAMOS_INCLUDE_IOBEAM" ] || BEAMOS_INCLUDE_IOBEAM=no [ -n "$BEAMOS_IOBEAM_ARCHIVE" ] || BEAMOS_IOBEAM_ARCHIVE=git+ssh://git@bitbucket.org/mrbeam/iobeam.git@$BEAMOS_IOBEAM_REPO_BRANCH [ -n "$BEAMOS_IOBEAM_REPO_BUILD" ] || BEAMOS_IOBEAM_REPO_BUILD=git+ssh://git@bitbucket.org/mrbeam/iobeam.git [ -n "$BEAMOS_IOBEAM_REPO_SHIP" ] || BEAMOS_IOBEAM_REPO_SHIP=git+ssh://git@bitbucket.org/mrbeam/iobeam.git @@ -59,7 +59,7 @@ TRUE_USER=pi [ -n "$BEAMOS_RPI_WS281X_ARCHIVE" ] || BEAMOS_RPI_WS281X_ARCHIVE=rpi-ws281x # Netconnectd and Netconnectd plugin -[ -n "$BEAMOS_INCLUDE_NETCONNECTD" ] || BEAMOS_INCLUDE_NETCONNECTD=yes +[ -n "$BEAMOS_INCLUDE_NETCONNECTD" ] || BEAMOS_INCLUDE_NETCONNECTD=no # Wifi package for netconnectd [ -n "$BEAMOS_NETCONNECTD_WIFI_ARCHIVE" ] || BEAMOS_NETCONNECTD_WIFI_ARCHIVE=https://github.com/mrbeam/wifi/archive/$BEAMOS_NETCONNECTD_WIFI_REPO_BRANCH.zip [ -n "$BEAMOS_NETCONNECTD_ARCHIVE" ] || BEAMOS_NETCONNECTD_ARCHIVE=https://github.com/mrbeam/netconnectd_mrbeam/archive/$BEAMOS_NETCONNECTD_REPO_BRANCH.zip @@ -71,27 +71,27 @@ TRUE_USER=pi [ -n "$BEAMOS_NETCONNECTD_PLUGIN_REPO_BUILD" ] || BEAMOS_NETCONNECTD_PLUGIN_REPO_BUILD=https://github.com/mrbeam/OctoPrint-Netconnectd.git [ -n "$BEAMOS_NETCONNECTD_PLUGIN_REPO_SHIP" ] || BEAMOS_NETCONNECTD_PLUGIN_REPO_SHIP=https://github.com/mrbeam/OctoPrint-Netconnectd.git -[ -n "$BEAMOS_INCLUDE_FINDMYMRBEAM" ] || BEAMOS_INCLUDE_FINDMYMRBEAM=yes +[ -n "$BEAMOS_INCLUDE_FINDMYMRBEAM" ] || BEAMOS_INCLUDE_FINDMYMRBEAM=no [ -n "$BEAMOS_FINDMYMRBEAM_ARCHIVE" ] || BEAMOS_FINDMYMRBEAM_ARCHIVE=https://github.com/mrbeam/OctoPrint-FindMyMrBeam/archive/$BEAMOS_FINDMYMRBEAM_REPO_BRANCH.zip [ -n "$BEAMOS_FINDMYMRBEAM_REPO_BUILD" ] || BEAMOS_FINDMYMRBEAM_REPO_BUILD=https://github.com/mrbeam/OctoPrint-FindMyMrBeam.git [ -n "$BEAMOS_FINDMYMRBEAM_REPO_SHIP" ] || BEAMOS_FINDMYMRBEAM_REPO_SHIP=https://github.com/mrbeam/OctoPrint-FindMyMrBeam.git -[ -n "$BEAMOS_INCLUDE_SHIELDFLASHER" ] || BEAMOS_INCLUDE_SHIELDFLASHER=yes +[ -n "$BEAMOS_INCLUDE_SHIELDFLASHER" ] || BEAMOS_INCLUDE_SHIELDFLASHER=no [ -n "$BEAMOS_SHIELDFLASHER_ARCHIVE" ] || BEAMOS_SHIELDFLASHER_ARCHIVE=https://github.com/mrbeam/shield_flasher/archive/$BEAMOS_SHIELDFLASHER_REPO_BRANCH.zip [ -n "$BEAMOS_SHIELDFLASHER_REPO_BUILD" ] || BEAMOS_SHIELDFLASHER_REPO_BUILD=https://github.com/mrbeam/shield_flasher.git [ -n "$BEAMOS_SHIELDFLASHER_REPO_SHIP" ] || BEAMOS_SHIELDFLASHER_REPO_SHIP=https://github.com/mrbeam/shield_flasher.git -[ -n "$BEAMOS_INCLUDE_MOUNTMANAGER" ] || BEAMOS_INCLUDE_MOUNTMANAGER=yes +[ -n "$BEAMOS_INCLUDE_MOUNTMANAGER" ] || BEAMOS_INCLUDE_MOUNTMANAGER=no [ -n "$BEAMOS_MOUNTMANAGER_ARCHIVE" ] || BEAMOS_MOUNTMANAGER_ARCHIVE=https://github.com/mrbeam/usb_mount_manager/archive/$BEAMOS_MOUNTMANAGER_REPO_BRANCH.zip [ -n "$BEAMOS_MOUNTMANAGER_REPO_BUILD" ] || BEAMOS_MOUNTMANAGER_REPO_BUILD=git+ssh://git@bitbucket.org/mrbeam/usb_mount_manager.git [ -n "$BEAMOS_MOUNTMANAGER_REPO_SHIP" ] || BEAMOS_MOUNTMANAGER_REPO_SHIP=git+ssh://git@bitbucket.org/mrbeam/usb_mount_manager.git -[ -n "$BEAMOS_INCLUDE_CHECK" ] || BEAMOS_INCLUDE_CHECK=yes +[ -n "$BEAMOS_INCLUDE_CHECK" ] || BEAMOS_INCLUDE_CHECK=no [ -n "$BEAMOS_CHECK_ARCHIVE" ] || BEAMOS_CHECK_ARCHIVE=https://github.com/mrbeam/mrb_check/archive/$BEAMOS_CHECK_REPO_BRANCH.zip [ -n "$BEAMOS_CHECK_REPO_BUILD" ] || BEAMOS_CHECK_REPO_BUILD=git+ssh://git@github.com:mrbeam/mrb_check.git [ -n "$BEAMOS_CHECK_REPO_SHIP" ] || BEAMOS_CHECK_REPO_SHIP=git+ssh://git@github.com:mrbeam/mrb_check.git ### Misc -[ -n "$BEAMOS_DEV" ] || BEAMOS_DEV=yes +[ -n "$BEAMOS_DEV" ] || BEAMOS_DEV=no [ -n "$BEAMOS_I2C_BAUDRATE" ] || BEAMOS_I2C_BAUDRATE=64000 [ -n "$BEAMOS_MODEL" ] || BEAMOS_MODEL=MRBEAM2_DC_S diff --git a/src/modules/beamos/filesystem/analytics/root/etc/logrotate.d/analytics b/src/modules/beamos/filesystem/analytics/root/etc/logrotate.d/analytics deleted file mode 100644 index c0728c66..00000000 --- a/src/modules/beamos/filesystem/analytics/root/etc/logrotate.d/analytics +++ /dev/null @@ -1,13 +0,0 @@ -# rotated files won't get uploaded. But rotation is a kind of safetynet to avoid analysis file from growing indefinitely -# in case the upload never happens - -/home/pi/.octoprint/analytics/analytics_log.json { - size 100M - rotate 3 - compress - delaycompress - missingok - notifempty - dateext - dateformat .%Y-%m-%d -} diff --git a/src/modules/beamos/filesystem/home/pi/.bash_history b/src/modules/beamos/filesystem/home/pi/.bash_history deleted file mode 100644 index 29ad8e23..00000000 --- a/src/modules/beamos/filesystem/home/pi/.bash_history +++ /dev/null @@ -1,37 +0,0 @@ -mrbeam_ledstrips_cli flash_white -mrbeam_ledstrips_cli -i2cset 0x2a 0x81 0x64 # Exhaust 100% -i2cset 0x2a 0x81 0x00 # Exhaust off -i2cset 0x2c 0x82 0x64 # Compressor 200 mbar -i2cset 0x2c 0x82 0x00 # Compressor off -i2cset 0x2c 0x87 0x64 # Ozon 100 PPM -i2cset 0x2c 0x87 0x00 # Ozon off -i2cdetect -netconnectcli status -tail -f -n200 /var/log/mount_manager.log -tail -f -n200 /var/log/netconnectd.log -tail -f -n200 /var/log/mrbeam_ledstrips.log -tail -f -n200 /var/log/iobeam.log -tail -f -n200 /var/log/mrb_check.log -tail -f -n200 ~/.octoprint/logs/octoprint.log -workon oprint -sudo shutdown now -sudo reboot -systemctl restart netconnectd # pi user has permission to use systemd -systemctl restart mrbeam_ledstrips # pi user has permission to use systemd -systemctl restart iobeam # pi user has permission to use systemd -systemctl restart octoprint # pi user has permission to use systemd -systemctl status octoprint # pi user has permission to use systemd -restart_iobeam -restart_mrbeam_ledstrips -restart_netconnectd -restart_octoprint -iobeamcli info -iobeamcli fan -c off -iobeamcli fan -c on 100 -iobeamcli -sudo nano /etc/mrbeam # uses micro, use Ctrl + q to quit, Ctrl + g for shortcut list -sudo nano ~/.octoprint/config.yaml # uses micro, use Ctrl + q to quit, Ctrl + g for shortcut list -nano /etc/mrbeam # uses micro, use Ctrl + q to quit, Ctrl + g for shortcut list -nano ~/.octoprint/config.yaml # uses micro, use Ctrl + q to quit, Ctrl + g for shortcut list -yq e ~/.octoprint/config.yaml # inspect config.yaml diff --git a/src/modules/beamos/filesystem/home/pi/.bashrc b/src/modules/beamos/filesystem/home/pi/.bashrc deleted file mode 100644 index dc9ba7b2..00000000 --- a/src/modules/beamos/filesystem/home/pi/.bashrc +++ /dev/null @@ -1,79 +0,0 @@ -# ~/.bashrc: executed by bash(1) for non-login shells. -# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) -# for examples - -# Run this when starting a shell -# If not running interactively, don't do anything -case $- in - *i*) ;; - *) return;; -esac - -# don't put duplicate lines or lines starting with space in the history. -# See bash(1) for more options -HISTCONTROL=ignoreboth - -# append to the history file, don't overwrite it -shopt -s histappend - -# for setting history length see HISTSIZE and HISTFILESIZE in bash(1) -HISTSIZE=1000 -HISTFILESIZE=2000 - -# check the window size after each command and, if necessary, -# update the values of LINES and COLUMNS. -shopt -s checkwinsize - -# If set, the pattern "**" used in a pathname expansion context will -# match all files and zero or more directories and subdirectories. -#shopt -s globstar - -# make less more friendly for non-text input files, see lesspipe(1) -#[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" - - -# set a fancy prompt (non-color, unless we know we "want" color) -case "$TERM" in - xterm-color) color_prompt=yes;; -esac - -# uncomment for a colored prompt, if the terminal has the capability; turned -# off by default to not distract the user: the focus in a terminal window -# should be on the output of commands, not on the prompt -force_color_prompt=yes - -if [ -n "$force_color_prompt" ]; then - if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then - # We have color support; assume it's compliant with Ecma-48 - # (ISO/IEC-6429). (Lack of such support is extremely rare, and such - # a case would tend to support setf rather than setaf.) - color_prompt=yes - else - color_prompt= - fi -fi - -if [ "$color_prompt" = yes ]; then - PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w \$\[\033[00m\] ' -else - PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' -fi -unset color_prompt force_color_prompt - -# enable programmable completion features (you don't need to enable -# this, if it's already enabled in /etc/bash.bashrc and /etc/profile -# sources /etc/bash.bashrc). -if ! shopt -oq posix; then - if [ -f /usr/share/bash-completion/bash_completion ]; then - . /usr/share/bash-completion/bash_completion - elif [ -f /etc/bash_completion ]; then - . /etc/bash_completion - fi -fi - -# suse style shell history browsing -bind '"\e[A"':history-search-backward -bind '"\e[B"':history-search-forward - -# Run the cross-shell behaviour -[ -f ~/.config/shellrc ] && . ~/.config/shellrc diff --git a/src/modules/beamos/filesystem/home/pi/.config/aliases b/src/modules/beamos/filesystem/home/pi/.config/aliases deleted file mode 100644 index 22c16f92..00000000 --- a/src/modules/beamos/filesystem/home/pi/.config/aliases +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/sh - -# Common aliases -alias ..="cd .." -alias ...="cd ../.." -alias ll="ls -l" -alias l="ls -al" - -# Systemd aliases -alias restart_octoprint='sudo systemctl restart octoprint.service' -alias restart_iobeam='sudo systemctl restart iobeam.service' -alias restart_mrbeam_ledstrips='sudo systemctl restart mrbeam_ledstrips.service' -alias restart_netconnectd='sudo systemctl restart netconnectd.service' - -alias stop_octoprint='sudo systemctl stop octoprint.service' -alias stop_iobeam='sudo systemctl stop iobeam.service' -alias stop_mrbeam_ledstrips='sudo systemctl stop mrbeam_ledstrips.service' -alias stop_netconnectd='sudo systemctl stop netconnectd.service' -alias nano="micro" - -alias kill_octoprint='killall -9 /home/pi/oprint/bin/python2' - -# Seems to return bash errors. -# # use i2c bus 1 by default -# -# i2cdetect() { -# if [ $1 = "-y" ]; then -# bus=$2 -# shift 2 -# else -# bus=1 -# fi -# i2cdetect -y $bus $@ -# } -# i2cset() { -# if [ $1 = "-y" ]; then -# bus=$2 -# shift 2 -# else -# bus=1 -# fi -# i2cset -y $bus $@ -# } - -workon() { - help() { echo "Usage: $0 [-h, --help] venv-name" && echo "Activates a Python venv located in HOME or give path"; } - [ -z "$1" ] && help && return 1 - { [ "$1" = "-h" ] || [ "$1" = "--help" ];} && help && return 0 - if [ -f "$1/bin/activate" ]; then - . "$1/bin/activate" - else - . "$HOME/$1/bin/activate" - fi -} diff --git a/src/modules/beamos/filesystem/home/pi/.config/disclaimer b/src/modules/beamos/filesystem/home/pi/.config/disclaimer deleted file mode 100644 index 425bef26..00000000 --- a/src/modules/beamos/filesystem/home/pi/.config/disclaimer +++ /dev/null @@ -1 +0,0 @@ -You have accessed a restricted system of the Mr Beam. If you chose to continue, Mr Beam Lasers GmbH will not support any claims and is not obligated to fullfil any warranty. diff --git a/src/modules/beamos/filesystem/home/pi/.config/htop/htoprc b/src/modules/beamos/filesystem/home/pi/.config/htop/htoprc deleted file mode 100644 index 28f358c2..00000000 --- a/src/modules/beamos/filesystem/home/pi/.config/htop/htoprc +++ /dev/null @@ -1,25 +0,0 @@ -# Beware! This file is rewritten by htop when settings are changed in the interface. -# The parser is also very primitive, and not human-friendly. -fields=0 48 17 18 38 39 40 2 46 47 49 1 -sort_key=49 -sort_direction=1 -hide_threads=0 -hide_kernel_threads=1 -hide_userland_threads=0 -shadow_other_users=0 -show_thread_names=1 -highlight_base_name=0 -highlight_megabytes=1 -highlight_threads=0 -tree_view=1 -header_margin=1 -detailed_cpu_time=0 -cpu_count_from_zero=0 -update_process_names=0 -account_guest_in_cpu_meter=0 -color_scheme=0 -delay=15 -left_meters=AllCPUs Memory Swap -left_meter_modes=1 1 1 -right_meters=Tasks LoadAverage Uptime -right_meter_modes=2 2 2 diff --git a/src/modules/beamos/filesystem/home/pi/.config/logo_ascii b/src/modules/beamos/filesystem/home/pi/.config/logo_ascii deleted file mode 100644 index 31b0a66f..00000000 --- a/src/modules/beamos/filesystem/home/pi/.config/logo_ascii +++ /dev/null @@ -1,12 +0,0 @@ - -.:**************. .**************:. - "mm "mrbeamm" mm" - "m. *mm*mm* .m" - m* .mm" "mm. *m - "m. .mm mm. .m" - *********** *********** - - .*mm*. .*mm*. - .mrbeam*mrbeam. - *m**mrbeam* *mrbeam**m* - "**mm**" "**mm**" diff --git a/src/modules/beamos/filesystem/home/pi/.config/neofetch/config.conf b/src/modules/beamos/filesystem/home/pi/.config/neofetch/config.conf deleted file mode 100644 index f4282283..00000000 --- a/src/modules/beamos/filesystem/home/pi/.config/neofetch/config.conf +++ /dev/null @@ -1,787 +0,0 @@ -# See this wiki page for more info: -# https://github.com/dylanaraps/neofetch/wiki/Customizing-Info - -sysd_status() { - systemctl show -qp SubState $@ | cut -f2 -d"="; -} - -device_info() { - ret="$(grep $1 /etc/mrbeam | cut -f2 --delimiter='=')" - if [ -z $ret ]; then - echo "" - else - echo $ret - fi -} - -beamos_version() { - echo "$(cat /etc/beamos_version)" -} - -print_info() { - info title - info underline - - info "OS" distro - prin "Serial Number" "$(device_info serial)" - prin "Beam OS Identifier" "$(device_info octopi)" - prin "Beam OS version" $(beamos_version) - info "Host" model - info "Local IP" local_ip - info "Packages" packages - info "Memory" memory - prin "--Systemd status--" - prin "OctoPrint" $(sysd_status octoprint) - prin "LED Strips" $(sysd_status mrbeam_ledstrips) - prin "IO Beam" $(sysd_status iobeam) - prin "Netconnectd" $(sysd_status netconnectd) - - #info "Resolution" resolution - #info "DE" de - #info "WM" wm - #info "WM Theme" wm_theme - #info "Theme" theme - #info "Icons" icons - #info "Terminal" term - #info "Terminal Font" term_font - #info "CPU" cpu - #info "GPU" gpu - # info "Kernel" kernel - # info "Shell" shell - # info "Uptime" uptime - # info "GPU Driver" gpu_driver # Linux/macOS only - # info "CPU Usage" cpu_usage - # info "Disk" disk - # info "Battery" battery - # info "Font" font - # info "Song" song - # [[ $player ]] && prin "Music Player" "$player" - # info "Public IP" public_ip - # info "Users" users - # info "Locale" locale # This only works on glibc systems. - - # info cols # Terminal colors -} - - -# Kernel - - -# Shorten the output of the kernel function. -# -# Default: 'on' -# Values: 'on', 'off' -# Flag: --kernel_shorthand -# Supports: Everything except *BSDs (except PacBSD and PC-BSD) -# -# Example: -# on: '4.8.9-1-ARCH' -# off: 'Linux 4.8.9-1-ARCH' -kernel_shorthand="on" - - -# Distro - - -# Shorten the output of the distro function -# -# Default: 'off' -# Values: 'on', 'off', 'tiny' -# Flag: --distro_shorthand -# Supports: Everything except Windows and Haiku -distro_shorthand="off" - -# Show/Hide OS Architecture. -# Show 'x86_64', 'x86' and etc in 'Distro:' output. -# -# Default: 'on' -# Values: 'on', 'off' -# Flag: --os_arch -# -# Example: -# on: 'Arch Linux x86_64' -# off: 'Arch Linux' -os_arch="on" - - -# Uptime - - -# Shorten the output of the uptime function -# -# Default: 'on' -# Values: 'on', 'off', 'tiny' -# Flag: --uptime_shorthand -# -# Example: -# on: '2 days, 10 hours, 3 mins' -# off: '2 days, 10 hours, 3 minutes' -# tiny: '2d 10h 3m' -uptime_shorthand="on" - - -# Memory - - -# Show memory pecentage in output. -# -# Default: 'off' -# Values: 'on', 'off' -# Flag: --memory_percent -# -# Example: -# on: '1801MiB / 7881MiB (22%)' -# off: '1801MiB / 7881MiB' -memory_percent="off" - - -# Packages - - -# Show/Hide Package Manager names. -# -# Default: 'tiny' -# Values: 'on', 'tiny' 'off' -# Flag: --package_managers -# -# Example: -# on: '998 (pacman), 8 (flatpak), 4 (snap)' -# tiny: '908 (pacman, flatpak, snap)' -# off: '908' -package_managers="on" - - -# Shell - - -# Show the path to $SHELL -# -# Default: 'off' -# Values: 'on', 'off' -# Flag: --shell_path -# -# Example: -# on: '/bin/bash' -# off: 'bash' -shell_path="off" - -# Show $SHELL version -# -# Default: 'on' -# Values: 'on', 'off' -# Flag: --shell_version -# -# Example: -# on: 'bash 4.4.5' -# off: 'bash' -shell_version="on" - - -# CPU - - -# CPU speed type -# -# Default: 'bios_limit' -# Values: 'scaling_cur_freq', 'scaling_min_freq', 'scaling_max_freq', 'bios_limit'. -# Flag: --speed_type -# Supports: Linux with 'cpufreq' -# NOTE: Any file in '/sys/devices/system/cpu/cpu0/cpufreq' can be used as a value. -speed_type="bios_limit" - -# CPU speed shorthand -# -# Default: 'off' -# Values: 'on', 'off'. -# Flag: --speed_shorthand -# NOTE: This flag is not supported in systems with CPU speed less than 1 GHz -# -# Example: -# on: 'i7-6500U (4) @ 3.1GHz' -# off: 'i7-6500U (4) @ 3.100GHz' -speed_shorthand="off" - -# Enable/Disable CPU brand in output. -# -# Default: 'on' -# Values: 'on', 'off' -# Flag: --cpu_brand -# -# Example: -# on: 'Intel i7-6500U' -# off: 'i7-6500U (4)' -cpu_brand="on" - -# CPU Speed -# Hide/Show CPU speed. -# -# Default: 'on' -# Values: 'on', 'off' -# Flag: --cpu_speed -# -# Example: -# on: 'Intel i7-6500U (4) @ 3.1GHz' -# off: 'Intel i7-6500U (4)' -cpu_speed="on" - -# CPU Cores -# Display CPU cores in output -# -# Default: 'logical' -# Values: 'logical', 'physical', 'off' -# Flag: --cpu_cores -# Support: 'physical' doesn't work on BSD. -# -# Example: -# logical: 'Intel i7-6500U (4) @ 3.1GHz' (All virtual cores) -# physical: 'Intel i7-6500U (2) @ 3.1GHz' (All physical cores) -# off: 'Intel i7-6500U @ 3.1GHz' -cpu_cores="logical" - -# CPU Temperature -# Hide/Show CPU temperature. -# Note the temperature is added to the regular CPU function. -# -# Default: 'off' -# Values: 'C', 'F', 'off' -# Flag: --cpu_temp -# Supports: Linux, BSD -# NOTE: For FreeBSD and NetBSD-based systems, you'll need to enable -# coretemp kernel module. This only supports newer Intel processors. -# -# Example: -# C: 'Intel i7-6500U (4) @ 3.1GHz [27.2°C]' -# F: 'Intel i7-6500U (4) @ 3.1GHz [82.0°F]' -# off: 'Intel i7-6500U (4) @ 3.1GHz' -cpu_temp="off" - - -# GPU - - -# Enable/Disable GPU Brand -# -# Default: 'on' -# Values: 'on', 'off' -# Flag: --gpu_brand -# -# Example: -# on: 'AMD HD 7950' -# off: 'HD 7950' -gpu_brand="on" - -# Which GPU to display -# -# Default: 'all' -# Values: 'all', 'dedicated', 'integrated' -# Flag: --gpu_type -# Supports: Linux -# -# Example: -# all: -# GPU1: AMD HD 7950 -# GPU2: Intel Integrated Graphics -# -# dedicated: -# GPU1: AMD HD 7950 -# -# integrated: -# GPU1: Intel Integrated Graphics -gpu_type="all" - - -# Resolution - - -# Display refresh rate next to each monitor -# Default: 'off' -# Values: 'on', 'off' -# Flag: --refresh_rate -# Supports: Doesn't work on Windows. -# -# Example: -# on: '1920x1080 @ 60Hz' -# off: '1920x1080' -refresh_rate="off" - - -# Gtk Theme / Icons / Font - - -# Shorten output of GTK Theme / Icons / Font -# -# Default: 'off' -# Values: 'on', 'off' -# Flag: --gtk_shorthand -# -# Example: -# on: 'Numix, Adwaita' -# off: 'Numix [GTK2], Adwaita [GTK3]' -gtk_shorthand="off" - - -# Enable/Disable gtk2 Theme / Icons / Font -# -# Default: 'on' -# Values: 'on', 'off' -# Flag: --gtk2 -# -# Example: -# on: 'Numix [GTK2], Adwaita [GTK3]' -# off: 'Adwaita [GTK3]' -gtk2="on" - -# Enable/Disable gtk3 Theme / Icons / Font -# -# Default: 'on' -# Values: 'on', 'off' -# Flag: --gtk3 -# -# Example: -# on: 'Numix [GTK2], Adwaita [GTK3]' -# off: 'Numix [GTK2]' -gtk3="on" - - -# IP Address - - -# Website to ping for the public IP -# -# Default: 'http://ident.me' -# Values: 'url' -# Flag: --ip_host -public_ip_host="http://ident.me" - -# Public IP timeout. -# -# Default: '2' -# Values: 'int' -# Flag: --ip_timeout -public_ip_timeout=2 - - -# Disk - - -# Which disks to display. -# The values can be any /dev/sdXX, mount point or directory. -# NOTE: By default we only show the disk info for '/'. -# -# Default: '/' -# Values: '/', '/dev/sdXX', '/path/to/drive'. -# Flag: --disk_show -# -# Example: -# disk_show=('/' '/dev/sdb1'): -# 'Disk (/): 74G / 118G (66%)' -# 'Disk (/mnt/Videos): 823G / 893G (93%)' -# -# disk_show=('/'): -# 'Disk (/): 74G / 118G (66%)' -# -disk_show=('/') - -# Disk subtitle. -# What to append to the Disk subtitle. -# -# Default: 'mount' -# Values: 'mount', 'name', 'dir' -# Flag: --disk_subtitle -# -# Example: -# name: 'Disk (/dev/sda1): 74G / 118G (66%)' -# 'Disk (/dev/sdb2): 74G / 118G (66%)' -# -# mount: 'Disk (/): 74G / 118G (66%)' -# 'Disk (/mnt/Local Disk): 74G / 118G (66%)' -# 'Disk (/mnt/Videos): 74G / 118G (66%)' -# -# dir: 'Disk (/): 74G / 118G (66%)' -# 'Disk (Local Disk): 74G / 118G (66%)' -# 'Disk (Videos): 74G / 118G (66%)' -disk_subtitle="mount" - - -# Song - - -# Manually specify a music player. -# -# Default: 'auto' -# Values: 'auto', 'player-name' -# Flag: --music_player -# -# Available values for 'player-name': -# -# amarok -# audacious -# banshee -# bluemindo -# clementine -# cmus -# deadbeef -# deepin-music -# dragon -# elisa -# exaile -# gnome-music -# gmusicbrowser -# guayadeque -# iTunes -# juk -# lollypop -# mocp -# mopidy -# mpd -# netease-cloud-music -# pogo -# pragha -# qmmp -# quodlibet -# rhythmbox -# sayonara -# smplayer -# spotify -# tomahawk -# vlc -# xmms2d -# yarock -music_player="auto" - -# Format to display song information. -# -# Default: '%artist% - %album% - %title%' -# Values: '%artist%', '%album%', '%title%' -# Flag: --song_format -# -# Example: -# default: 'Song: Jet - Get Born - Sgt Major' -song_format="%artist% - %album% - %title%" - -# Print the Artist, Album and Title on separate lines -# -# Default: 'off' -# Values: 'on', 'off' -# Flag: --song_shorthand -# -# Example: -# on: 'Artist: The Fratellis' -# 'Album: Costello Music' -# 'Song: Chelsea Dagger' -# -# off: 'Song: The Fratellis - Costello Music - Chelsea Dagger' -song_shorthand="off" - -# 'mpc' arguments (specify a host, password etc). -# -# Default: '' -# Example: mpc_args=(-h HOST -P PASSWORD) -mpc_args=() - - -# Text Colors - - -# Text Colors -# -# Default: 'distro' -# Values: 'distro', 'num' 'num' 'num' 'num' 'num' 'num' -# Flag: --colors -# -# Each number represents a different part of the text in -# this order: 'title', '@', 'underline', 'subtitle', 'colon', 'info' -# -# Example: -# colors=(distro) - Text is colored based on Distro colors. -# colors=(4 6 1 8 8 6) - Text is colored in the order above. -colors=(distro) - - -# Text Options - - -# Toggle bold text -# -# Default: 'on' -# Values: 'on', 'off' -# Flag: --bold -bold="on" - -# Enable/Disable Underline -# -# Default: 'on' -# Values: 'on', 'off' -# Flag: --underline -underline_enabled="on" - -# Underline character -# -# Default: '-' -# Values: 'string' -# Flag: --underline_char -underline_char="-" - - -# Info Separator -# Replace the default separator with the specified string. -# -# Default: ':' -# Flag: --separator -# -# Example: -# separator="->": 'Shell-> bash' -# separator=" =": 'WM = dwm' -separator=":" - - -# Color Blocks - - -# Color block range -# The range of colors to print. -# -# Default: '0', '7' -# Values: 'num' -# Flag: --block_range -# -# Example: -# -# Display colors 0-7 in the blocks. (8 colors) -# neofetch --block_range 0 7 -# -# Display colors 0-15 in the blocks. (16 colors) -# neofetch --block_range 0 15 -block_range=(0 7) - -# Toggle color blocks -# -# Default: 'on' -# Values: 'on', 'off' -# Flag: --color_blocks -color_blocks="on" - -# Color block width in spaces -# -# Default: '3' -# Values: 'num' -# Flag: --block_width -block_width=3 - -# Color block height in lines -# -# Default: '1' -# Values: 'num' -# Flag: --block_height -block_height=1 - - -# Progress Bars - - -# Bar characters -# -# Default: '-', '=' -# Values: 'string', 'string' -# Flag: --bar_char -# -# Example: -# neofetch --bar_char 'elapsed' 'total' -# neofetch --bar_char '-' '=' -bar_char_elapsed="-" -bar_char_total="=" - -# Toggle Bar border -# -# Default: 'on' -# Values: 'on', 'off' -# Flag: --bar_border -bar_border="on" - -# Progress bar length in spaces -# Number of chars long to make the progress bars. -# -# Default: '15' -# Values: 'num' -# Flag: --bar_length -bar_length=15 - -# Progress bar colors -# When set to distro, uses your distro's logo colors. -# -# Default: 'distro', 'distro' -# Values: 'distro', 'num' -# Flag: --bar_colors -# -# Example: -# neofetch --bar_colors 3 4 -# neofetch --bar_colors distro 5 -bar_color_elapsed="distro" -bar_color_total="distro" - - -# Info display -# Display a bar with the info. -# -# Default: 'off' -# Values: 'bar', 'infobar', 'barinfo', 'off' -# Flags: --cpu_display -# --memory_display -# --battery_display -# --disk_display -# -# Example: -# bar: '[---=======]' -# infobar: 'info [---=======]' -# barinfo: '[---=======] info' -# off: 'info' -cpu_display="off" -memory_display="off" -battery_display="off" -disk_display="off" - - -# Backend Settings - - -# Image backend. -# -# Default: 'ascii' -# Values: 'ascii', 'caca', 'chafa', 'jp2a', 'iterm2', 'off', -# 'termpix', 'pixterm', 'tycat', 'w3m', 'kitty' -# Flag: --backend -image_backend="ascii" - -# Image Source -# -# Which image or ascii file to display. -# -# Default: 'auto' -# Values: 'auto', 'ascii', 'wallpaper', '/path/to/img', '/path/to/ascii', '/path/to/dir/' -# 'command output (neofetch --ascii "$(fortune | cowsay -W 30)")' -# Flag: --source -# -# NOTE: 'auto' will pick the best image source for whatever image backend is used. -# In ascii mode, distro ascii art will be used and in an image mode, your -# wallpaper will be used. -image_source='auto' - - -# Ascii Options - - -# Ascii distro -# Which distro's ascii art to display. -# -# Default: 'auto' -# Values: 'auto', 'distro_name' -# Flag: --ascii_distro -# -# NOTE: Arch and Ubuntu have 'old' logo variants. -# Change this to 'arch_old' or 'ubuntu_old' to use the old logos. -# NOTE: Ubuntu has flavor variants. -# Change this to 'Lubuntu', 'Xubuntu', 'Ubuntu-GNOME' or 'Ubuntu-Budgie' to use the flavors. -# NOTE: Arch, Crux and Gentoo have a smaller logo variant. -# Change this to 'arch_small', 'crux_small' or 'gentoo_small' to use the small logos. -ascii_distro="auto" - -# Ascii Colors -# -# Default: 'distro' -# Values: 'distro', 'num' 'num' 'num' 'num' 'num' 'num' -# Flag: --ascii_colors -# -# Example: -# ascii_colors=(distro) - Ascii is colored based on Distro colors. -# ascii_colors=(4 6 1 8 8 6) - Ascii is colored using these colors. -ascii_colors=(distro) - -# Bold ascii logo -# Whether or not to bold the ascii logo. -# -# Default: 'on' -# Values: 'on', 'off' -# Flag: --ascii_bold -ascii_bold="on" - - -# Image Options - - -# Image loop -# Setting this to on will make neofetch redraw the image constantly until -# Ctrl+C is pressed. This fixes display issues in some terminal emulators. -# -# Default: 'off' -# Values: 'on', 'off' -# Flag: --loop -image_loop="off" - -# Thumbnail directory -# -# Default: '~/.cache/thumbnails/neofetch' -# Values: 'dir' -thumbnail_dir="${XDG_CACHE_HOME:-${HOME}/.cache}/thumbnails/neofetch" - -# Crop mode -# -# Default: 'normal' -# Values: 'normal', 'fit', 'fill' -# Flag: --crop_mode -# -# See this wiki page to learn about the fit and fill options. -# https://github.com/dylanaraps/neofetch/wiki/What-is-Waifu-Crop%3F -crop_mode="normal" - -# Crop offset -# Note: Only affects 'normal' crop mode. -# -# Default: 'center' -# Values: 'northwest', 'north', 'northeast', 'west', 'center' -# 'east', 'southwest', 'south', 'southeast' -# Flag: --crop_offset -crop_offset="center" - -# Image size -# The image is half the terminal width by default. -# -# Default: 'auto' -# Values: 'auto', '00px', '00%', 'none' -# Flags: --image_size -# --size -image_size="auto" - -# Gap between image and text -# -# Default: '3' -# Values: 'num', '-num' -# Flag: --gap -gap=3 - -# Image offsets -# Only works with the w3m backend. -# -# Default: '0' -# Values: 'px' -# Flags: --xoffset -# --yoffset -yoffset=0 -xoffset=0 - -# Image background color -# Only works with the w3m backend. -# -# Default: '' -# Values: 'color', 'blue' -# Flag: --bg_color -background_color= - - -# Misc Options - -# Stdout mode -# Turn off all colors and disables image backend (ASCII/Image). -# Useful for piping into another command. -# Default: 'off' -# Values: 'on', 'off' -stdout="off" diff --git a/src/modules/beamos/filesystem/home/pi/.config/shellrc b/src/modules/beamos/filesystem/home/pi/.config/shellrc deleted file mode 100644 index 47aeded3..00000000 --- a/src/modules/beamos/filesystem/home/pi/.config/shellrc +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/sh -# set variable identifying the chroot you work in (used in the prompt below) -if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then - debian_chroot=$(cat /etc/debian_chroot) -fi - -# If this is an xterm set the title to user@host:dir -case "$TERM" in -xterm*|rxvt*) - PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1" - ;; -*) - ;; -esac - -# enable color support of ls and also add handy aliases -if [ -x /usr/bin/dircolors ]; then - test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" - alias ls='ls --color=auto' - alias dir='dir --color=auto' - alias vdir='vdir --color=auto' - - alias grep='grep --color=auto' - alias fgrep='fgrep --color=auto' - alias egrep='egrep --color=auto' -fi - -# Alias definitions. -# See /usr/share/doc/bash-doc/examples in the bash-doc package. -if [ -f ~/.config/aliases ]; then - . ~/.config/aliases -fi - -## git -parse_git_branch() { - git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' -} - -# Extend PATH -export PATH="$HOME/.local/bin:$PATH" - -# prompt - -RED="\[\033[0;31m\]" -YELLOW="\[\033[0;33m\]" -GREEN="\[\033[0;32m\]" -NO_COLOUR="\[\033[0m\]" - -PS1="$GREEN\u@\h$NO_COLOUR:\w$YELLOW\$(parse_git_branch)$NO_COLOUR\> " - -# Show some fun(ctional) stuff when opening a shell -## Banner -figlet -cf slant BeamOS 2>/dev/null || echo "Welcome to beamOS!" -## Disclaimer in Red -{ { [ -f ~/.disclaimer ] && disc="$HOME/.disclaimer";} || { [ -f ~/.config/disclaimer ] && disc="$HOME/.config/disclaimer";};} && \ - printf "\033[0;31m" && cat "$disc" && printf "\033[0;0m" -# Show detailed info about the systemd status of these services -#systemctl --no-pager status -n 0 mrbeam_ledstrips netconnectd iobeam octoprint - -# nice neofetch greeting - a bit slow though -echo # Extra newline for stylezz -neofetch --ascii "$(cat /home/pi/.config/logo_ascii)" 2>/dev/null diff --git a/src/modules/beamos/filesystem/home/pi/.hushlogin b/src/modules/beamos/filesystem/home/pi/.hushlogin deleted file mode 100644 index e69de29b..00000000 diff --git a/src/modules/beamos/filesystem/home/pi/.octoprint/config.yaml b/src/modules/beamos/filesystem/home/pi/.octoprint/config.yaml deleted file mode 100644 index dcf37352..00000000 --- a/src/modules/beamos/filesystem/home/pi/.octoprint/config.yaml +++ /dev/null @@ -1,31 +0,0 @@ -webcam: - stream: plugin/mrbeam/static/img/test.jpg -plugins: - discovery: - publicPort: 80 - mrbeam: - dev: - env: PROD - software_tier: PROD - netconnectd: - socket: /var/run/netconnectd.sock - softwareupdate: - checks: - octoprint: - pip: https://github.com/mrbeam/OctoPrint/archive/{target_version}.zip - user: mrbeam -serial: - additionalPorts: - - /dev/ttyAMA* - autoconnect: true - baudrate: 115200 - port: /dev/ttyAMA0 -server: - commands: - serverRestartCommand: sudo systemctl restart octoprint.service - systemRestartCommand: sudo shutdown -r now - systemShutdownCommand: sudo shutdown -h now - onlineCheck: - enabled: true - host: find.mr-beam.org - port: '80' diff --git a/src/modules/beamos/filesystem/home/pi/.octoprint/config.yaml.dev b/src/modules/beamos/filesystem/home/pi/.octoprint/config.yaml.dev deleted file mode 100644 index 5d1eef9a..00000000 --- a/src/modules/beamos/filesystem/home/pi/.octoprint/config.yaml.dev +++ /dev/null @@ -1,20 +0,0 @@ -accessControl: - salt: 2Ajc3zpiF780TsPGa7bElcwy41Ml0y5c -devel: - analyticsEnabled: false - cache: - enabled: false - webassets: - bundle: false - clean_on_startup: true - minify: false -plugins: - mrbeam: - dev: - env: DEV - software_tier: DEV - terminal: true -server: - firstRun: false - seenWizards: - mrbeam: 19 diff --git a/src/modules/beamos/filesystem/home/pi/.octoprint/uploads/Focus_Lehre.svg b/src/modules/beamos/filesystem/home/pi/.octoprint/uploads/Focus_Lehre.svg deleted file mode 100644 index 5db47c63..00000000 --- a/src/modules/beamos/filesystem/home/pi/.octoprint/uploads/Focus_Lehre.svg +++ /dev/null @@ -1,467 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/modules/beamos/filesystem/home/pi/.octoprint/uploads/MrBeam.svg b/src/modules/beamos/filesystem/home/pi/.octoprint/uploads/MrBeam.svg deleted file mode 100644 index 1e2e926b..00000000 --- a/src/modules/beamos/filesystem/home/pi/.octoprint/uploads/MrBeam.svg +++ /dev/null @@ -1,26 +0,0 @@ - -image/svg+xml \ No newline at end of file diff --git a/src/modules/beamos/filesystem/home/pi/.octoprint/uploads/MrBeam_Logo.svg b/src/modules/beamos/filesystem/home/pi/.octoprint/uploads/MrBeam_Logo.svg deleted file mode 100644 index dc2c42cd..00000000 --- a/src/modules/beamos/filesystem/home/pi/.octoprint/uploads/MrBeam_Logo.svg +++ /dev/null @@ -1,38 +0,0 @@ - -image/svg+xml \ No newline at end of file diff --git "a/src/modules/beamos/filesystem/home/pi/.octoprint/uploads/Schlu\314\210sselanha\314\210nger.svg" "b/src/modules/beamos/filesystem/home/pi/.octoprint/uploads/Schlu\314\210sselanha\314\210nger.svg" deleted file mode 100644 index 68f7838e..00000000 --- "a/src/modules/beamos/filesystem/home/pi/.octoprint/uploads/Schlu\314\210sselanha\314\210nger.svg" +++ /dev/null @@ -1,48 +0,0 @@ - -image/svg+xml \ No newline at end of file diff --git a/src/modules/beamos/filesystem/home/pi/.octoprint/users-dev.yaml b/src/modules/beamos/filesystem/home/pi/.octoprint/users-dev.yaml deleted file mode 100644 index 42eac0ef..00000000 --- a/src/modules/beamos/filesystem/home/pi/.octoprint/users-dev.yaml +++ /dev/null @@ -1,19 +0,0 @@ -dev@mr-beam.org: - active: true - apikey: null - password: e07e596d4a958ec6c957bbcd25a4c1088435d37a941d825c0bcfb51ab89a7ec0b8f08115587985969dd4af4c5e4c05bf5c33bc059fcc419015aa5f8b1124c387 - roles: - - user - - admin - settings: - mrbeam: - design_store_email: dev@mr-beam.org - lasersafety: - sent_to_cloud: 1616676592.602827 - show_again: false - messages: - lastId: 1 - unreadIds: - - 1 - ts: 1616676592.686951 - version: 0.8.1.1 diff --git a/src/modules/beamos/filesystem/home/pi/scripts/fake-hwclock_cron_job b/src/modules/beamos/filesystem/home/pi/scripts/fake-hwclock_cron_job deleted file mode 100644 index 8a8038bd..00000000 --- a/src/modules/beamos/filesystem/home/pi/scripts/fake-hwclock_cron_job +++ /dev/null @@ -1 +0,0 @@ -*/5 * * * * /sbin/fake-hwclock save diff --git a/src/modules/beamos/filesystem/home/pi/scripts/reset_script.sh b/src/modules/beamos/filesystem/home/pi/scripts/reset_script.sh deleted file mode 100755 index 9d251d02..00000000 --- a/src/modules/beamos/filesystem/home/pi/scripts/reset_script.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/bash - -# in case of an error, flash red -trap signal_err ERR - -signal_err() { - mrbeam_ledstrips_cli flash_red - sleep 1 - mrbeam_ledstrips_cli red - exit 1 -} - -siganl_ok() { - mrbeam_ledstrips_cli flash_green - sleep 1 - mrbeam_ledstrips_cli green -} - -sudo systemctl stop octoprint.service - -pushd /home/pi/.octoprint - # Cleanup entries in the config.yaml - sed -i '/firstRun:/d' config.yaml - sed -i '/secretKey:/d' config.yaml - sed -i '/upnpUuid:/d' config.yaml - sed -i '/seenWizards:/,+1d' config.yaml - sed -i '/api:/,+1d' config.yaml - sed -i '/accessControl:/,+1d' config.yaml - - # Delete users.yaml - rm -f users.yaml - - pushd uploads - # Cleanup the uploads dir (delete all files but the listed) - find . -maxdepth 1 -type f \ - -not -name 'Focus_Lehre*.svg' \ - -not -name 'MrBeam.svg' \ - -not -name 'MrBeam_Logo.svg' \ - -not -name 'Schlusselanhanger.svg' \ - -delete - - rm cam/* - rm local/* - popd -popd - -pushd /etc/network/ - # Delete configured Wifi - sudo sed -i '/wlan0-netconnectd_wifi/,+3d' interfaces -popd - -# flash green -siganl_ok - - diff --git a/src/modules/beamos/filesystem/iobeam/root/etc/logrotate.d/iobeam b/src/modules/beamos/filesystem/iobeam/root/etc/logrotate.d/iobeam deleted file mode 100644 index d02feb87..00000000 --- a/src/modules/beamos/filesystem/iobeam/root/etc/logrotate.d/iobeam +++ /dev/null @@ -1,11 +0,0 @@ -/var/log/iobeam.log { - size 2M - rotate 3 - compress - delaycompress - missingok - notifempty - copytruncate - dateext - dateformat .%Y-%m-%d -} diff --git a/src/modules/beamos/filesystem/iobeam/root/etc/systemd/system/iobeam.service b/src/modules/beamos/filesystem/iobeam/root/etc/systemd/system/iobeam.service deleted file mode 100644 index f635e081..00000000 --- a/src/modules/beamos/filesystem/iobeam/root/etc/systemd/system/iobeam.service +++ /dev/null @@ -1,11 +0,0 @@ -[Unit] -Description=Mr Beam II iobeam Daemon -After=socket.target - -[Service] -Type=idle -ExecStart=/usr/local/iobeam/venv/bin/iobeam -PIDFile=/var/run/iobeam.pid - -[Install] -WantedBy=multi-user.target diff --git a/src/modules/beamos/filesystem/known_hosts_bitbucket b/src/modules/beamos/filesystem/known_hosts_bitbucket deleted file mode 100644 index af50ebf7..00000000 --- a/src/modules/beamos/filesystem/known_hosts_bitbucket +++ /dev/null @@ -1,2 +0,0 @@ -bitbucket.org,2406:da00:ff00::6b17:d1f5 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAubiN81eDcafrgMeLzaFPsw2kNvEcqTKl/VqLat/MaB33pZy0y3rJZtnqwR2qOOvbwKZYKiEO1O6VqNEBxKvJJelCq0dTXWT5pbO2gDXC6h6QDXCaHo6pOHGPUy+YBaGQRGuSusMEASYiWunYN0vCAI8QaXnWMXNMdFP3jHAJH0eDsoiGnLPBlBp4TNm6rYI74nMzgz3B9IikW4WVK+dc8KZJZWYjAuORU3jc1c/NPskD2ASinf8v3xnfXeukU0sJ5N6m5E8VLjObPEO+mN2t/FZTMZLiFqPWc/ALSqnMnnhwrNi2rbfg/rd/IpL8Le3pSBne8+seeFVBoGqzHM9yXw== - diff --git a/src/modules/beamos/filesystem/mount_manager/home/pi/usb_mount/README.md b/src/modules/beamos/filesystem/mount_manager/home/pi/usb_mount/README.md deleted file mode 100644 index 3b02ae57..00000000 --- a/src/modules/beamos/filesystem/mount_manager/home/pi/usb_mount/README.md +++ /dev/null @@ -1 +0,0 @@ -This is where the mount_manager shell script will mount the usb keys provided that they contain the correct key signature. diff --git a/src/modules/beamos/filesystem/mount_manager/root/etc/logrotate.d/mount_manager b/src/modules/beamos/filesystem/mount_manager/root/etc/logrotate.d/mount_manager deleted file mode 100644 index 342119ce..00000000 --- a/src/modules/beamos/filesystem/mount_manager/root/etc/logrotate.d/mount_manager +++ /dev/null @@ -1,12 +0,0 @@ -/var/log/mount_manager.log { - size 2M - rotate 3 - compress - delaycompress - missingok - notifempty - copytruncate - create 644 root root - dateext - dateformat .%Y-%m-%d -} diff --git a/src/modules/beamos/filesystem/mount_manager/root/etc/systemd/system/mount_manager_add.service b/src/modules/beamos/filesystem/mount_manager/root/etc/systemd/system/mount_manager_add.service deleted file mode 100644 index d34012ff..00000000 --- a/src/modules/beamos/filesystem/mount_manager/root/etc/systemd/system/mount_manager_add.service +++ /dev/null @@ -1,6 +0,0 @@ -[Service] -Type=oneshot -ExecStart=/usr/bin/mount_manager add - -[Unit] -After=mount_manager_remove.service diff --git a/src/modules/beamos/filesystem/mount_manager/root/etc/systemd/system/mount_manager_clear.service b/src/modules/beamos/filesystem/mount_manager/root/etc/systemd/system/mount_manager_clear.service deleted file mode 100644 index da871007..00000000 --- a/src/modules/beamos/filesystem/mount_manager/root/etc/systemd/system/mount_manager_clear.service +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=runs the mount_manager clear command -Before=shutdown.target - -[Service] -Type=oneshot -ExecStart=/usr/bin/mount_manager clear - -[Install] -WantedBy=shutdown.target \ No newline at end of file diff --git a/src/modules/beamos/filesystem/mount_manager/root/etc/systemd/system/mount_manager_remove.service b/src/modules/beamos/filesystem/mount_manager/root/etc/systemd/system/mount_manager_remove.service deleted file mode 100644 index 1113c67e..00000000 --- a/src/modules/beamos/filesystem/mount_manager/root/etc/systemd/system/mount_manager_remove.service +++ /dev/null @@ -1,3 +0,0 @@ -[Service] -Type=oneshot -ExecStart=/usr/bin/mount_manager remove diff --git a/src/modules/beamos/filesystem/mount_manager/root/etc/systemd/system/mount_manager_remove_before_octo.service b/src/modules/beamos/filesystem/mount_manager/root/etc/systemd/system/mount_manager_remove_before_octo.service deleted file mode 100644 index 019259b9..00000000 --- a/src/modules/beamos/filesystem/mount_manager/root/etc/systemd/system/mount_manager_remove_before_octo.service +++ /dev/null @@ -1,10 +0,0 @@ -[Service] -Type=oneshot -ExecStart=/usr/bin/mount_manager remove - -[Unit] -Description=runs mount_manager remove as a tartup process before OctoPrint. -Before=octoprint.service - -[Install] -WantedBy=multi-user.target diff --git a/src/modules/beamos/filesystem/mount_manager/root/usr/share/mount_manager/pubkey.asc b/src/modules/beamos/filesystem/mount_manager/root/usr/share/mount_manager/pubkey.asc deleted file mode 100644 index ed9e6b0d..00000000 --- a/src/modules/beamos/filesystem/mount_manager/root/usr/share/mount_manager/pubkey.asc +++ /dev/null @@ -1,31 +0,0 @@ ------BEGIN PGP PUBLIC KEY BLOCK----- - -mQENBFkwBHYBCACxVnIexv+XV8Viv6bZ43pPu1BAhIacfNH6BPtoeudkd45V8ag5 -tgoezX80/+U7OPbbAt+AuJks3gm4GDgU0B7m/IF5h4ey36z4DjF0EtQjpQnyMCVj -buZrO4oBlfiCqfvcuH9ylKkGxOpLbSr+3O7HmWUjc9Rfy1o7LdmqInVUPG6qyIOc -iiDDU/sNUmqULUBSkmsGKfNsEsWYlx4rJS3W4EkCslw3VwHDeihzr07T4lUI1d/T -GWE/lBxUv7apkymLH22k0yqhJDOmDesbpeH5xrrR/qPaI7I1tWuKcRB8qcILmBMK -yYKRV0FZHxsHVwW8ETZZk3Suw9PYKG1HBaQzABEBAAG0Q01yIEJlYW0gKEtleSBw -YWlyIGZvciBNckJlYW1zIFVTQiBhdXRvIGV4ZWN1dGlvbikgPGRldkBtci1iZWFt -Lm9yZz6JAU4EEwEIADgWIQS4cmKoAHzh2E5M5W2FBqEr5zvwbQUCWTAEdgIbAwUL -CQgHAgYVCAkKCwIEFgIDAQIeAQIXgAAKCRCFBqEr5zvwbV3aB/wPAzPIK8F58BZA -NRF2ZvXi1AtIJZHrqJsXBemruza607Byb6o6QycSRAdW5RBGg8mBoGDcRqx8IcTc -9+0h0j/CmfUec7nHRA61BXxeBXyN8l6PGG9gZ4Xj/8zcUUGt7YTZllPYdb+ojDai -5eB2t1cWOG8X5E/QOC4ZZWW1R1xBxqgklefpCj/wdykOr3SCuqvSKy5pseoab8J+ -9NHv16g6ZY72h/HMtXSu3kKC/BqoGIpaYXN+cpq2BqfcaIVhRAPkLy6UuuKlAYvt -anZP36kdQpC5ppWwyUJ1VzzLHhjlXkfTkBsTQMerIzjK+QXwKSugOpmdrcZ6JRC3 -JZYy4Bq1uQENBFkwBHYBCADG87xvEvZQ87lLSxut3G6tRvuK773Qj1dVAYpZNDP6 -+wnyOdMAMFNOfkqw/kc4XMb4iW+ufeNTzYIOUVHXVQwg06OeyRCN450BMGNhe2Eo -kNdrkmxEzSKXRgxtC0IoXNoUq9X29yJ56lDWZTmC4NSaJQfbc4mgbAOvZNT3oNI6 -rCfAG89SBOJ5R05iLzNWaN5pFJP7CY3wpYw/OnzuXGxS38wxlaK9xDayqwDgzqAD -8Nd+8qe3MIPPPYyzhG7k6x7mCmrw0mwSxI7lQn8jBl/MkiNpR5O77pc+bPMKOOKM -1QoUK1nJg5t16al2zr2/v1S9/aEw77hBR28g2fj0xj9RABEBAAGJATYEGAEIACAW -IQS4cmKoAHzh2E5M5W2FBqEr5zvwbQUCWTAEdgIbDAAKCRCFBqEr5zvwbfxFCACn -lBoX1Pf2UvZiPpDYgvJpkSW2Ws/icQgwTyoL6bYpowqdaOZObXT63uVp5aSCjMhm -MK2DMI0HMF7kOYWvSfWaGB7UGmv/6HN3OaFxT2oTmINtRVv7eCSa1V9kLFbuWYnB -2Qbk9k4gc6i8cf98bFsmjK5Kk8ZSW3SLR5J8u0wiYmEF+app8v7ArBz63Zm2P/wH -9lZCWHLC+npQh49QG7KSgU/QbxBzT3TMngeYoBOfbqZJtorN3Dpst2f1YbhdxSFW -wgogAomT5SsxPnhAlHq8qXxBOwGxqZ9ONpadbERQKJt88bqnCnbCjMzc7hLW9f5h -09lQLqMPfQmerVOy4Pd/ -=gUJs ------END PGP PUBLIC KEY BLOCK----- diff --git a/src/modules/beamos/filesystem/mrb_check/root/etc/logrotate.d/mrb_check b/src/modules/beamos/filesystem/mrb_check/root/etc/logrotate.d/mrb_check deleted file mode 100644 index 19798fb3..00000000 --- a/src/modules/beamos/filesystem/mrb_check/root/etc/logrotate.d/mrb_check +++ /dev/null @@ -1,12 +0,0 @@ -/var/log/mrb_check.log { - size 5M - rotate 3 - compress - delaycompress - missingok - notifempty - copytruncate - create 644 root root - dateext - dateformat .%Y-%m-%d -} diff --git a/src/modules/beamos/filesystem/mrb_check/root/usr/share/mrb_check.yaml b/src/modules/beamos/filesystem/mrb_check/root/usr/share/mrb_check.yaml deleted file mode 100644 index 580e4a84..00000000 --- a/src/modules/beamos/filesystem/mrb_check/root/usr/share/mrb_check.yaml +++ /dev/null @@ -1,29 +0,0 @@ -env: - env: PROD-S-DC-WATTEROTT -device_info: - type: MrBeam2S - series: 2S - model: MRBEAM2_DC - model_force: MRBEAM2_DC -modules: - - check_0009_i2c - - check_0010_environment - - check_0015_room_environment - - check_0020_leds - - check_0030_iobeam_static - - check_0040_gpg - - check_0045_serial_grbl_programmer - - check_0050_grbl - - check_0060_config_yaml - - check_0070_iobeam_dynamic_auto - - check_0080_iobeam_compressor - - check_0090_iobeam_smart_reedswitches - - check_0110_iobeam_dynamic_manual - - check_0120_movement - - check_0130_laser_temp - - check_0140_save_to_file - - check_0250_calibration_markers -compressor: - required: true -smart_reedswitch: - required: true diff --git a/src/modules/beamos/filesystem/netconnectd/root/etc/logrotate.d/netconnectd b/src/modules/beamos/filesystem/netconnectd/root/etc/logrotate.d/netconnectd deleted file mode 100644 index 8fd9067b..00000000 --- a/src/modules/beamos/filesystem/netconnectd/root/etc/logrotate.d/netconnectd +++ /dev/null @@ -1,11 +0,0 @@ -/var/log/netconnectd.log { - size 2M - rotate 3 - compress - delaycompress - missingok - notifempty - copytruncate - dateext - dateformat .%Y-%m-%d -} diff --git a/src/modules/beamos/filesystem/repos/mount_manager b/src/modules/beamos/filesystem/repos/mount_manager deleted file mode 160000 index b0137a84..00000000 --- a/src/modules/beamos/filesystem/repos/mount_manager +++ /dev/null @@ -1 +0,0 @@ -Subproject commit b0137a84be1438302e0b8837dba09642ea329871 diff --git a/src/modules/beamos/filesystem/repos/mrb_check b/src/modules/beamos/filesystem/repos/mrb_check deleted file mode 160000 index 7139b5ac..00000000 --- a/src/modules/beamos/filesystem/repos/mrb_check +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7139b5ac95cd8fb139e4ca363833d230ff2368a9 diff --git a/src/modules/beamos/filesystem/root/etc/init.d/beamos_first_boot b/src/modules/beamos/filesystem/root/etc/init.d/beamos_first_boot index 3897d880..19596b62 100755 --- a/src/modules/beamos/filesystem/root/etc/init.d/beamos_first_boot +++ b/src/modules/beamos/filesystem/root/etc/init.d/beamos_first_boot @@ -19,34 +19,6 @@ do_start () { REBOOT=false logfile=/var/log/beamos_first_boot.log - BEAMOS_HOSTNAME_BIN=/usr/bin/beamos_hostname - #load current saved vars - SERIAL=$(crudini --get /etc/mrbeam 'Mr Beam' serial 2>/dev/null ) - HOSTNAME=$(crudini --get /etc/mrbeam 'Mr Beam' hostname 2>/dev/null ) - if [ -x $BEAMOS_HOSTNAME_BIN ] && [ -z "$HOSTNAME" ]; then - echo "$(timestamp) Setting the device hostname..." >> $logfile - $BEAMOS_HOSTNAME_BIN >> $logfile - REBOOT=true - fi - BEAMOS_SERIAL_BIN=/usr/bin/beamos_serial - if [ -x $BEAMOS_SERIAL_BIN ] && [ -z "$SERIAL" ]; then - echo "$(timestamp) Setting the Device Serial name..." >> $logfile - $BEAMOS_SERIAL_BIN >> $logfile - fi - - # enable the usb mount manager udev rules - # rm /etc/udev/rules.d/00-mount_manager.rules - - # enable the i2c bus - # Disabled for now - activated during image creation - #sudo raspi-config nonint do_i2c 0 - # enable the uart / hw serial port - # Disabled for now - activated during image creation - #sudo raspi-config nonint do_serial 2 - if $REBOOT; then - echo "$(timestamp) Reboot device to apply changes" >> $logfile - /sbin/reboot - fi } case "$1" in diff --git a/src/modules/beamos/filesystem/root/usr/bin/beamos_hostname b/src/modules/beamos/filesystem/root/usr/bin/beamos_hostname deleted file mode 100755 index 4cc90a12..00000000 --- a/src/modules/beamos/filesystem/root/usr/bin/beamos_hostname +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env bash - -if [ "$1" = "-h" -o "$1" = "--help" ]; then - echo "Usage: $0 [new-hostname-id]" - echo "Set the machine hostname using\n - 1. The provided hostname ID\n - 2. Use the hostname written in /etc/mrbeam\n - 3. auto generate the hostname as a signature of the RPi device." - echo "Must be run as root." - exit 0 -fi - -. /lib/lsb/init-functions - -# The hostname -CONFIG_HOSTNAME="$(crudini --get /etc/mrbeam 'Mr Beam' hostname 2>/dev/null )" - -if [ -n "$1" ]; then - new_hostname="MrBeam-$1" -elif [ -n "$CONFIG_HOSTNAME" ]; then - new_hostname="$CONFIG_HOSTNAME" -else - # rev allows to use cut for cutting out the last 4 characters. - # And thus making it more POSIX compliant and legacy compatible. - ID=$( - grep Serial /proc/cpuinfo | \ - awk '{print toupper($3)}' | \ - sha1sum | \ - cut -d ' ' -f1 | \ - rev | \ - cut -c -4 | \ - rev | \ - awk '{print toupper($0)}' - ) - [ -z "$ID" ] && log_failure_msg "Failed to generate ID." && exit 1 - new_hostname="MrBeam-$ID" -fi - - -old_hostname="$(hostname)" -# make sure we do have a valid hostname here (see RFC 952 and 1123, a-zA-Z0-9 only) -sanitized_hostname=`echo "$new_hostname" | tr -cd '[[:alnum:]]-'` -if [ "$new_hostname" = "$sanitized_hostname" ]; then - echo "$new_hostname" > /etc/hostname - sed -i -e "s/$old_hostname/$new_hostname/g" /etc/hosts - hostname "$new_hostname" - crudini --set /etc/mrbeam "Mr Beam" hostname $new_hostname - log_success_msg "Host name changed to $new_hostname , reboot to apply..." -else - log_failure_msg "Hostname $new_hostname contains invalid characters (only a-zA-Z0-9 are allowed), refusing to change" - exit 2 -fi diff --git a/src/modules/beamos/filesystem/root/usr/bin/beamos_serial b/src/modules/beamos/filesystem/root/usr/bin/beamos_serial deleted file mode 100755 index d70ffd61..00000000 --- a/src/modules/beamos/filesystem/root/usr/bin/beamos_serial +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh -if [ -n "$1" ]; then - echo "Generate the device serial number from the cpu" - echo "serial number and the device series; then" - echo "(over)write it into /etc/mrbeam" - echo " Does not take any arguments." - exit 1 -fi - -SERIES="$(grep device_series /etc/mrbeam | cut -f2 -d '=')" -CPU_SERIAL=$(grep Serial /proc/cpuinfo | awk '{print toupper($3)}') -if [ -n "$SERIES" ]; then - SERIAL=$CPU_SERIAL-$SERIES -else - SERIAL=$CPU_SERIAL -fi -echo "Setting device serial to $SERIAL" - -crudini --set /etc/mrbeam "Mr Beam" serial $SERIAL diff --git a/src/modules/beamos/filesystem/ssh/.ssh/authorized_keys b/src/modules/beamos/filesystem/ssh/.ssh/authorized_keys deleted file mode 100644 index 8e2b54d9..00000000 --- a/src/modules/beamos/filesystem/ssh/.ssh/authorized_keys +++ /dev/null @@ -1 +0,0 @@ -ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDUZuRVGow10Wm42ZGQ1hWI84dE8nsibsdOED0xsCbpNm+PzSf+/IklyI82YHawcI5Vggi59zQCGh9VN6g5X+ttzUpmiiT8YpRG241Li0g9bacWvMEEuC+975gpV5yfMMu5Tgr8NHcrIDJ64bF8P37RXoJZ78ghIYCQyPUJs1dD7msCL+GWGgPDmObny3ffIwAYvQvocZXIyRAvG/jW3GKZROKsjX8jiqXBHXQHiXrrgsoGKuPpUkqBxPWFNlrQikrcOpoYRwDPuUGnMPHX5L/xzIgYNKYifCfLr3xyx1iXmwCoP+8HntP219xrduC17g61UZ71ktbY508KtGwzOOHd mrbeam_rsa diff --git a/src/modules/octopi/config b/src/modules/octopi/config index 703d5732..59bac2cd 100755 --- a/src/modules/octopi/config +++ b/src/modules/octopi/config @@ -4,7 +4,7 @@ # OctoPrint archive [ -n "$OCTOPI_OCTOPRINT_ARCHIVE" ] || OCTOPI_OCTOPRINT_ARCHIVE=$(wget -q -O - https://api.github.com/repos/foosel/OctoPrint/releases/latest | grep "zipball_url" | cut -d : -f 2,3 | tr -d \" | tr -d ,) [ -n "$OCTOPI_OCTOPRINT_REPO_SHIP" ] || OCTOPI_OCTOPRINT_REPO_SHIP=https://github.com/foosel/OctoPrint.git -[ -n "$OCTOPI_INCLUDE_OCTOPRINT" ] || OCTOPI_INCLUDE_OCTOPRINT=yes +[ -n "$OCTOPI_INCLUDE_OCTOPRINT" ] || OCTOPI_INCLUDE_OCTOPRINT=no # CuraEngine archive & version [ -n "$OCTOPI_CURAENGINE_VERSION" ] || OCTOPI_CURAENGINE_VERSION=15.04.6 diff --git a/src/variants/beamos/config b/src/variants/beamos/config index edf5b100..6308075a 100755 --- a/src/variants/beamos/config +++ b/src/variants/beamos/config @@ -1,9 +1,9 @@ #!/bin/sh # variant mrbeam, flavor default: override hostname & custom config setting -export DIST_NAME=BeamOS -export DIST_VERSION=0.20.3 -export BASE_OVERRIDE_HOSTNAME=MrBeam-XXXX -export BASE_IMAGE_ENLARGEROOT=1700 +export DIST_NAME=MigrationOS +export DIST_VERSION=0.1.0 +export BASE_OVERRIDE_HOSTNAME=MigrationOS +#export BASE_IMAGE_ENLARGEROOT=1700 export BEAMOS_DEV=no export MODULES="base(raspicam, network, disable-services(dev-libs(octopi, beamos)))" From b4d8e9664451448c85bc63decdda21e6d908dff9 Mon Sep 17 00:00:00 2001 From: Josef-MrBeam Date: Fri, 24 Nov 2023 10:09:56 +0100 Subject: [PATCH 02/35] fix missing home --- src/modules/beamos/start_chroot_script | 1 - 1 file changed, 1 deletion(-) diff --git a/src/modules/beamos/start_chroot_script b/src/modules/beamos/start_chroot_script index 62888fa7..a3ef013d 100755 --- a/src/modules/beamos/start_chroot_script +++ b/src/modules/beamos/start_chroot_script @@ -196,7 +196,6 @@ set_plugin_update_conf_remote() { } # Unpack the regular files -unpack /filesystem/home /home/ pi unpack /filesystem/root / root # Install a more feature-fool alternative to nano : micro From b4a04a4badaa1369eed5f58fb89144be733502c9 Mon Sep 17 00:00:00 2001 From: Josef-MrBeam Date: Fri, 24 Nov 2023 12:47:20 +0100 Subject: [PATCH 03/35] fix ssh error --- src/variants/beamos/config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/variants/beamos/config b/src/variants/beamos/config index 6308075a..293b70ec 100755 --- a/src/variants/beamos/config +++ b/src/variants/beamos/config @@ -31,4 +31,4 @@ export OCTOPI_PYTHON_VERSION=python2 export DEV_LIBS_EXTRA="python2-dev libxml2-dev libxslt1-dev" # Dev allow ssh for now -export BEAMOS_INCLUDE_SSH=yes +export BEAMOS_INCLUDE_SSH=no From ab7cb2d68d04e097585643ec048b7fb8e2323b41 Mon Sep 17 00:00:00 2001 From: Josef-MrBeam Date: Fri, 24 Nov 2023 16:03:21 +0100 Subject: [PATCH 04/35] enable ssh again --- src/modules/beamos/filesystem/ssh/.ssh/authorized_keys | 1 + src/variants/beamos/config | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 src/modules/beamos/filesystem/ssh/.ssh/authorized_keys diff --git a/src/modules/beamos/filesystem/ssh/.ssh/authorized_keys b/src/modules/beamos/filesystem/ssh/.ssh/authorized_keys new file mode 100644 index 00000000..8e2b54d9 --- /dev/null +++ b/src/modules/beamos/filesystem/ssh/.ssh/authorized_keys @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDUZuRVGow10Wm42ZGQ1hWI84dE8nsibsdOED0xsCbpNm+PzSf+/IklyI82YHawcI5Vggi59zQCGh9VN6g5X+ttzUpmiiT8YpRG241Li0g9bacWvMEEuC+975gpV5yfMMu5Tgr8NHcrIDJ64bF8P37RXoJZ78ghIYCQyPUJs1dD7msCL+GWGgPDmObny3ffIwAYvQvocZXIyRAvG/jW3GKZROKsjX8jiqXBHXQHiXrrgsoGKuPpUkqBxPWFNlrQikrcOpoYRwDPuUGnMPHX5L/xzIgYNKYifCfLr3xyx1iXmwCoP+8HntP219xrduC17g61UZ71ktbY508KtGwzOOHd mrbeam_rsa diff --git a/src/variants/beamos/config b/src/variants/beamos/config index 293b70ec..6308075a 100755 --- a/src/variants/beamos/config +++ b/src/variants/beamos/config @@ -31,4 +31,4 @@ export OCTOPI_PYTHON_VERSION=python2 export DEV_LIBS_EXTRA="python2-dev libxml2-dev libxslt1-dev" # Dev allow ssh for now -export BEAMOS_INCLUDE_SSH=no +export BEAMOS_INCLUDE_SSH=yes From cde21fc7973f32745c52e32717b5ae326e92119a Mon Sep 17 00:00:00 2001 From: Josef-MrBeam Date: Fri, 24 Nov 2023 16:06:26 +0100 Subject: [PATCH 05/35] create migration os flavor --- .github/workflows/build.yml | 2 +- src/variants/beamos/config.migrationOS | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 src/variants/beamos/config.migrationOS diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 597ae1ed..ff979640 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -33,7 +33,7 @@ jobs: then flavors='{"flavor":"alpha 2Q"}' else - flavors='{"flavor":"2Q"},{"flavor":"2R"}' + flavors='{"flavor":"migrationOS"}' fi echo "matrix={\"include\":[$flavors]}" >> $GITHUB_OUTPUT diff --git a/src/variants/beamos/config.migrationOS b/src/variants/beamos/config.migrationOS new file mode 100644 index 00000000..5a6a21e3 --- /dev/null +++ b/src/variants/beamos/config.migrationOS @@ -0,0 +1,3 @@ +#!/bin/sh +export BEAMOS_DEVICE_MODEL="NONE" +export BEAMOS_MODEL="NONE" From a6458bfd5e7774097ff860117d04a15e9f29031c Mon Sep 17 00:00:00 2001 From: Josef-MrBeam Date: Fri, 24 Nov 2023 16:07:31 +0100 Subject: [PATCH 06/35] fix folder --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ff979640..70f29353 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -158,7 +158,7 @@ jobs: - name: Create env variable for upload folder in gcloud bucket run: | # Use the last letter of the flavor for the directory name - echo "DIR=$(echo ${{ matrix.flavor }} | rev | cut -c 1)" >> $GITHUB_ENV + echo "DIR=$(echo ${{ matrix.flavor }})" >> $GITHUB_ENV - uses: actions-hub/gcloud@master env: PROJECT_ID: devpi-310008 From 5a38e95386c55001b131746d9b37f73956cfa401 Mon Sep 17 00:00:00 2001 From: Josef-MrBeam Date: Wed, 6 Dec 2023 11:12:33 +0100 Subject: [PATCH 07/35] install bmaptool --- src/modules/beamos/start_chroot_script | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/modules/beamos/start_chroot_script b/src/modules/beamos/start_chroot_script index a3ef013d..bcbd9c78 100755 --- a/src/modules/beamos/start_chroot_script +++ b/src/modules/beamos/start_chroot_script @@ -526,6 +526,10 @@ if [ -n "$BEAMOS_DEVICE_MODEL" ]; then set_field device_type "MrBeam$BEAMOS_DEVICE_MODEL" /etc/mrbeam fi +######Migration OS stuff##### +sudo apt-get install -y bmap-tools +#TODO download image into /home/pi/image + ##################################################################### ### setup systemd units/services From 2dcf6050147592564985fa364abd25e17953ad89 Mon Sep 17 00:00:00 2001 From: caglarkilimci <110826807+caglarkilimci@users.noreply.github.com> Date: Wed, 13 Dec 2023 13:32:08 +0100 Subject: [PATCH 08/35] SW-4170 Add migration os to beam os 2 flashing script (#109) * SW-4170 Add migration os to beam os 2 flashing script * SW-4170 Fix typo --- .../filesystem/migration/usr/bin/migration.sh | 504 ++++++++++++++++++ .../usr/bin/migrationos_to_beamos2.sh | 72 +++ src/modules/beamos/start_chroot_script | 8 +- 3 files changed, 583 insertions(+), 1 deletion(-) create mode 100755 src/modules/beamos/filesystem/migration/usr/bin/migration.sh create mode 100755 src/modules/beamos/filesystem/migration/usr/bin/migrationos_to_beamos2.sh diff --git a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh new file mode 100755 index 00000000..6ac00d3e --- /dev/null +++ b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh @@ -0,0 +1,504 @@ +#!/bin/bash +# bash required for array syntax support. +# This is a copy of the migration.sh script from the mrb3-usb-stick-builder repo. + +echo "Beam OS1 to Beam OS2 Migration Script" + +usage () { + echo "Beam OS1 to Beam OS2 Migration Script v1.0.0 " + echo " " + echo "OPTIONS: " + echo " " + echo " --help Print this help message and exit. " + echo " " + echo "COMMANDS: " + echo " precondition-checks Checks the sw and hw components so that Mr Beam can be upgrade or not. " + echo " flash Flashes the with using . " + echo " - can be \"beamos2\" or \"migrationos\". " + echo " - can be \"sd-card\" or device path like \"/dev/sda\". " + echo " mount Mounts the partitions of . " + echo " - can be \"sd-card\" or device path like \"/dev/sda\". " + echo " preserve-data Preserves sensitive data into USB with . " + echo " - is the path of usb device mounted like \"/mnt/usb\". " + echo " restore-data Restores sensitive data into SD-Card. " + echo " set-status Sets the of LED. can be one of the following: " + echo " - success " + echo " - fail " + echo " - in-progress " + echo " config-boot-usb Configures Mr Beam to be able to boot from USB. " + echo " shutdown Shutdown Mr Beam. " + +} + +timestamp() +{ + date +"%Y-%m-%d %T" +} + +do_precondition_checks () { + echo "$(timestamp) $0: precondition-checks" + + # Get the list of USB block devices with sizes in bytes + USB_DRIVES=$(lsblk -o NAME,SIZE,TYPE,TRAN -dn --bytes | grep 'usb' | awk '{print $1,$2}') + + # Check if there are any USB drives + if [ -z "$USB_DRIVES" ]; then + echo "$(timestamp) $0: No USB drives found." + exit 1 + fi + + while read -r line; do + DEVICE_SIZE_BYTES=$(echo "$line" | awk '{print $2}') + + # Check if the size is greater than 4GB + if [ "$DEVICE_SIZE_BYTES" -gt $((MIN_USB_SIZE_IN_GB * 1024 * 1024 * 1024)) ]; then + DEVICE_SIZE_GIGABYTES=$((DEVICE_SIZE_BYTES / 1024 / 1024 / 1024)) + echo "$(timestamp) $0: USB drive of $DEVICE_SIZE_GIGABYTES GB present." + exit 0 + fi + + done <<< "$USB_DRIVES" + + echo "$(timestamp) $0: No USB drive of size greater than ${MIN_USB_SIZE_IN_GB}GB found." + exit 1 +} + + +find_current_booted_os_version () { + if [ -f /etc/beamos_version ]; then + echo "beamos1" + elif [ -f /etc/migrationos_version ]; then + echo "migrationos" + fi +} + +do_flash () { + OS_TO_BE_FLASHED="$1" + DEVICE_TO_BE_FLASHED="$2" + echo "$(timestamp) $0: flash $OS_TO_BE_FLASHED $DEVICE_TO_BE_FLASHED" + + CURRENT_OS_VERSION=$(find_current_booted_os_version) + echo "$(timestamp) $0: Flashing $OS_TO_BE_FLASHED on $DEVICE_TO_BE_FLASHED from $CURRENT_OS_VERSION" + if [ "$OS_TO_BE_FLASHED" = "beamos2" ] && [ "$DEVICE_TO_BE_FLASHED" = "sd-card" ] && [ "$CURRENT_OS_VERSION" = "migrationos" ]; then + echo "Flashing SD-Card with beamos2" + IMAGE_FILE="${BEAMOS2_IMAGE}" + # check if the image is there + if [ ! -f ${IMAGE_FILE} ]; then + echo "$(timestamp) $0: Image not found: ${IMAGE_FILE}" + exit 1 + fi + sudo umount ${SD_CARD_DEVICE}* || true + sudo bmaptool copy ${IMAGE_FILE} ${SD_CARD_DEVICE} + STATUS=$? + elif [ "$OS_TO_BE_FLASHED" = "migrationos" ] && [ "$CURRENT_OS_VERSION" = "beamos1" ];then + # check if the image is there + IMAGE_FILE="${MIGRATION_IMAGE}" + if [ ! -f ${IMAGE_FILE} ]; then + echo "$(timestamp) $0: Image not found: ${IMAGE_FILE}" + exit 1 + fi + echo "$(timestamp) $0: Flashing USB with migrationos" + sudo umount ${DEVICE_TO_BE_FLASHED}* || true + sudo dd if=${IMAGE_FILE} of=${DEVICE_TO_BE_FLASHED} bs=4M status=progress conv=fsync + STATUS=$? + else + echo "$(timestamp) $0: Check inputs to the function flash" + exit 1 + fi + + # check status of flashing + if [ $STATUS -ne 0 ]; then + echo "$(timestamp) $0: Flashing Failed - $OS_TO_BE_FLASHED on $DEVICE_TO_BE_FLASHED from $CURRENT_OS_VERSION" + exit 1 + fi + + sudo sync + + echo "$(timestamp) $0: Flashing Successful - $OS_TO_BE_FLASHED flashed into $DEVICE_TO_BE_FLASHED " + exit 0 +} + +do_mount () { + DEVICE_TO_BE_MOUNTED="$1" + echo "$(timestamp) $0: mount $DEVICE_TO_BE_MOUNTED" # "sd-card" or usb path like "/dev/sda" + CURRENT_OS_VERSION=$(find_current_booted_os_version) + + if [ "$DEVICE_TO_BE_MOUNTED" = "sd-card" ] && [ "$CURRENT_OS_VERSION" = "migrationos" ]; then + # Mounting the SD-Card + DEVICE_PARTITIONS=( + ${SDCARD_ROOTFS_A} + ${SDCARD_ROOTFS_B} + ${SDCARD_HOME} + ) + + MOUNT_DIRS=( + ${SDCARD_ROOTFS_A_PATH} + ${SDCARD_ROOTFS_B_PATH} + ${SDCARD_HOME_PATH} + ) + elif [ "$DEVICE_TO_BE_MOUNTED" != "sd-card" ] && [ "$CURRENT_OS_VERSION" = "beamos1" ];then + # Mounting the USB with migrationos + # There are 2 partitions on the USB. The first one is the boot partition and the second one is the rootfs. + DEVICE_PARTITION=${DEVICE_TO_BE_MOUNTED}2 + MOUNT_DIR="/mnt/usb" + + DEVICE_PARTITIONS=( + ${DEVICE_PARTITION} + ) + + MOUNT_DIRS=( + ${MOUNT_DIR} + ) + else + echo "$(timestamp) $0: Check inputs to the function mount" + exit 1 + fi + + for i in "${!DEVICE_PARTITIONS[@]}"; do + sudo mkdir -p ${MOUNT_DIRS[$i]} + echo "$(timestamp) $0: Mounting ${DEVICE_PARTITIONS[$i]} on ${MOUNT_DIRS[$i]}" + sudo mount ${DEVICE_PARTITIONS[$i]} ${MOUNT_DIRS[$i]} + # Check if the mount is successful + if [ $? -ne 0 ]; then + echo "$(timestamp) $0: Can't mount ${DEVICE_PARTITIONS[$i]}" + exit 1 + fi + done + + echo "Mounting Successful - $DEVICE_TO_BE_MOUNTED" + + + exit 0 +} + + +do_preserve_data () { + local USB_MOUNT_PATH="$1" + echo "$(timestamp) $0: preserve-data $USB_MOUNT_PATH" # path like "/mnt/usb" + if [ -z "${USB_MOUNT_PATH}" ]; then + echo "$(timestamp) $0: No suitable backup partition found. Exiting..." + exit 1 + fi + + # Create a backup directory (if it doesn't exist) + BACKUP_BASE="${USB_MOUNT_PATH}${BACKUP_PATH}" + + # Check if the folder exists, backup if yes. + if [ -d "${BACKUP_BASE}" ]; then + # Get the creation time of the folder + creation_time=$(stat -c %W "${BACKUP_BASE}") + + # Format the creation time as a timestamp + timestamp=$(date -d "@$creation_time" +"%Y%m%d_%H%M%S") + + # Rename the folder by adding the timestamp + new_folder_name="${BACKUP_BASE}_backup_${timestamp}" + mv "${BACKUP_BASE}" "${new_folder_name}" + + echo "$(timestamp) $0: ${BACKUP_BASE} exists. Moved it to: ${new_folder_name}" + fi + + mkdir -p "$BACKUP_BASE" + + SKIPPED=0 + + # Loop through each file in the array and create a backup copy + for FILE in "${DATA_TO_PRESERVE[@]}"; do + if [ -f "${FILE}" ] || [ -d "${FILE}" ]; then + TARGET_DIR="${BACKUP_BASE}/$(dirname "${FILE}")" + mkdir -p ${TARGET_DIR} + TARGET="${TARGET_DIR}/$(basename "${FILE}")" + cp -r "${FILE}" "${TARGET}" + echo "$(timestamp) $0: Success - copied '${FILE}' to '${TARGET}'" + else + echo "$(timestamp) $0: Warning - File '${FILE}' not found. Skipping." + ((SKIPPED++)) + fi + done + + echo "$(timestamp) $0: Backup process completed. Backup copies are stored in '$BACKUP_BASE'." + if [ "${SKIPPED}" -gt 0 ]; then + echo "$(timestamp) $0: Warning - ${SKIPPED} files were skipped - Please check syslog." + # exit 1 + fi + + exit 0 +} + +do_restore_data () { + echo "$(timestamp) $0: restore-data" + + # /etc/hostname -> Rootfs A and B -> /etc/hostname + echo "$(timestamp) $0: Restoring /etc/hostname to Rootfs A and B /etc/hostname" + sudo cp ${BACKUP_PATH}/etc/hostname ${SDCARD_ROOTFS_A_PATH}/etc/hostname + sudo cp ${BACKUP_PATH}/etc/hostname ${SDCARD_ROOTFS_B_PATH}/etc/hostname + + # /etc/hosts -> Home -> /home/root/mrbeam-base-files/hosts + echo "$(timestamp) $0: Restoring /etc/hosts to Home /home/root/mrbeam-base-files/hosts" + sudo cp ${BACKUP_PATH}/etc/hosts ${SDCARD_HOME_PATH}/root/mrbeam-base-files/hosts + + # /etc/mrbeam -> Home -> /home/pi/mrbeam-id/mrbeam + # We need to understand backed up from beamos0 or beamos1 + echo "$(timestamp) $0: Restoring /etc/mrbeam to Home /home/pi/mrbeam-id/mrbeam" + local MRBEAM_SECTION="Mr Beam" + sudo crudini --get "${BACKUP_PATH}/etc/mrbeam" "$MRBEAM_SECTION" "production_date" + if [ $? -ne 0 ]; then + # We are migrating from beamos0 + echo "$(timestamp) $0: Migrating from beamos0" + SECTION="" + else + # We are migrating from beamos1 + echo "$(timestamp) $0: Migrating from beamos1" + SECTION="Mr Beam" + fi + # Below params will be set to the new mrbeam file + PARAMS="production_date hostname device_series device_type serial model" + for param in $PARAMS; do + local VALUE=$(sudo crudini --get "${BACKUP_PATH}/etc/mrbeam" "$SECTION" "$param") + echo "$(timestamp) $0: Setting $param to $VALUE" + sudo crudini --set "${SDCARD_HOME_PATH}/pi/mrbeam-id/mrbeam" "$MRBEAM_SECTION" "$param" "${VALUE}" + done + local OCTOPI=$(sudo crudini --get "${BACKUP_PATH}/etc/mrbeam" "$SECTION" "octopi") + # Set migrated_from param + echo "$(timestamp) $0: Setting migrated_from to $OCTOPI" + sudo crudini --set "${SDCARD_HOME_PATH}/pi/mrbeam-id/mrbeam" "$MRBEAM_SECTION" "migrated_from" "${OCTOPI}" + # Set need_reboot param + sudo crudini --set "${SDCARD_HOME_PATH}/pi/mrbeam-id/mrbeam" "$MRBEAM_SECTION" "need_reboot" true + + # .octoprint/config.yaml -> Home -> /home/pi/.octoprint/config.yaml + # We need to copy fields from the backup to the new config.yaml + backupfolder="${BACKUP_PATH}" + applyfolder="${SDCARD_HOME_PATH}/.." + configfile="/home/pi/.octoprint/config.yaml" + backupfile="${backupfolder}${configfile}" + applyfile="${applyfolder}${configfile}" + #accessControl needed for users.yaml + echo "$(timestamp) $0: Restoring accessControl for /home/pi/.octoprint/config.yaml" + sudo cat $backupfile | sudo yq ea -i 'select(fileIndex==0) * {"accessControl":select(fileIndex==1).accessControl}' $applyfile - + + #plugins.findmymrbeam + echo "$(timestamp) $0: Restoring plugins.findmymrbeam for /home/pi/.octoprint/config.yaml" + sudo cat $backupfile | sudo yq ea -i 'select(fileIndex==0) * {"plugins":{"findmymrbeam":select(fileIndex==1).plugins.findmymrbeam}}' $applyfile - + + #plugins.mrbeam.analyticsEnabled + echo "$(timestamp) $0: Restoring plugins.mrbeam.analyticsEnabled for /home/pi/.octoprint/config.yaml" + sudo cat $backupfile | sudo yq ea -i 'select(fileIndex==0) * {"plugins":{"mrbeam":{"analyticsEnabled":select(fileIndex==1).plugins.mrbeam.analyticsEnabled}}}' $applyfile - + + #plugins.mrbeam.review + echo "$(timestamp) $0: Restoring plugins.mrbeam.review for /home/pi/.octoprint/config.yaml" + sudo cat $backupfile | sudo yq ea -i 'select(fileIndex==0) * {"plugins":{"mrbeam":{"review":select(fileIndex==1).plugins.mrbeam.review}}}' $applyfile - + + # Loop through the rest of the files and folders in the array and copy backed up files + echo "$(timestamp) $0: Restoring the rest of the files to Home" + for FILE in "${DATA_TO_RESTORE[@]}"; do + BACKUP_FILE="${BACKUP_PATH}/home/pi/${FILE}" + if [ -f "${BACKUP_FILE}" ] || [ -d "${BACKUP_FILE}" ]; then + TARGET_DIR="${SDCARD_HOME_PATH}/pi/$(dirname "${FILE}")" + sudo mkdir -p ${TARGET_DIR} + TARGET="${TARGET_DIR}/$(basename "${FILE}")" + echo "$(timestamp) $0: Restoring ${BACKUP_FILE} to ${TARGET}" + sudo cp -r "${BACKUP_FILE}" "${TARGET}" + else + echo "$(timestamp) $0: Restore data: Warning - File '${FILE}' not found. Skipping." + fi + done + + echo "$(timestamp) $0: Restore data: Restore process completed." + exit 0 +} + +set_status_success() { + echo "$(timestamp) $0: status_success" + mrbeam_ledstrips_cli flash_green + sleep 1 + mrbeam_ledstrips_cli green +} + +set_status_fail () { + echo "$(timestamp) $0: status_fail" + mrbeam_ledstrips_cli flash_red + sleep 1 + mrbeam_ledstrips_cli red +} + +set_status_in_progress () { + echo "$(timestamp) $0: status_in_progress" + mrbeam_ledstrips_cli flash_color:120:120:120:4; + sleep 0.4 ; + mrbeam_ledstrips_cli flash_color:40:40:40:5 +} + +do_set_status () { + STATUS="$1" + echo "$(timestamp) $0: set-status ${STATUS}" + if [ "${STATUS}" = "success" ]; then + echo "${STATUS}" + set_status_success + elif [ "${STATUS}" = "fail" ]; then + echo "${STATUS}" + set_status_fail + elif [ "${STATUS}" = "in-progress" ]; then + echo "${STATUS}" + set_status_in_progress + else + echo "$(timestamp) $0: Unknown status [${STATUS}]" + set_status_fail + fi + exit 0 +} + +do_config_boot_usb () { + echo "$(timestamp) $0: config-boot-usb" + echo program_usb_boot_mode=1 | sudo tee -a /boot/config.txt + sudo sed -i '$ s|$| root=/dev/sda2|' /boot/cmdline.txt + echo "$(timestamp) $0: Device configured to boot from USB." + exit 0 +} + +do_shutdown () { + echo "$(timestamp) $0: shutdown" + sudo shutdown now + exit 0 +} + + +do_exit () { + RET_CODE="$?" + echo "$0: Exitting. ${RET_CODE}" + if [ "$RET_CODE" -eq 0 ]; then + echo "$0: Normal exiting." + else + echo "$0: Exiting with error code [${RET_CODE}]" + set_status_fail + fi +} + +################################################################################ +## migration.sh script configuration +################################################################################ + +IMAGE_DIR="/home/pi/image" +MIGRATION_IMAGE="${IMAGE_DIR}/migrationos.img" +BEAMOS2_IMAGE="${IMAGE_DIR}/beamos2.wic.bz2" +MIN_USB_SIZE_IN_GB=4 +BACKUP_PATH="/mrbeam/preserve-data" + +# There are 8 partitions on the SD-Card. +# Root filesystems are on partition 2 and 3. +# Home is on partition 8. +SD_CARD_DEVICE="/dev/mmcblk0" +SDCARD_ROOTFS_A="${SD_CARD_DEVICE}p2" +SDCARD_ROOTFS_B="${SD_CARD_DEVICE}p3" +SDCARD_HOME="${SD_CARD_DEVICE}p8" + +SDCARD_ROOTFS_A_PATH="/mnt/sd-card/rootfs_a" +SDCARD_ROOTFS_B_PATH="/mnt/sd-card/rootfs_b" +SDCARD_HOME_PATH="/mnt/sd-card/home" + +# list of files treated by preserve-data and restore-data +DATA_TO_PRESERVE=( + "/home/pi/.octoprint/cam" # is a folder + "/home/pi/.octoprint/analytics/usage.yaml" + "/home/pi/.octoprint/users.yaml" + "/home/pi/.octoprint/users-dev.yaml" + "/home/pi/.octoprint/material.yaml" + "/home/pi/.octoprint/laser_heads.yaml" + "/home/pi/.octoprint/config.yaml" + "/etc/mrbeam" + "/etc/network/interfaces" + "/etc/hostname" + "/etc/hosts" + "/etc/network/interfaces.d/wlan0-netconnectd_wifi" + # Add more file paths as needed +) + +DATA_TO_RESTORE=( + ".octoprint/cam" # is a folder + ".octoprint/analytics/usage.yaml" + ".octoprint/users.yaml" + ".octoprint/users-dev.yaml" + ".octoprint/material.yaml" + # Other files are required manual intervention to restore +) + + +################################################################################ +## Main +################################################################################ + + +# Present usage. +if [ $# -eq 0 ]; then + usage + exit 0 +fi + +while getopts ":h?:" opt; do + case "$opt" in + h|\?) + usage + exit 0 + ;; + esac +done + +# Set trap before EXIT +trap do_exit EXIT + +# Process all commands. +while true ; do + case "$1" in + precondition-checks) + do_precondition_checks + shift + break + ;; + flash) + do_flash "$2" "$3" + shift + shift + shift + break + ;; + mount) + do_mount "$2" + shift + shift + break + ;; + preserve-data) + do_preserve_data "$2" + shift + shift + break + ;; + restore-data) + do_restore_data + shift + break + ;; + set-status) + do_set_status "$2" + shift + shift + break + ;; + config-boot-usb) + do_config_boot_usb + shift + break + ;; + shutdown) + do_shutdown + shift + break + ;; + *) + if [[ -n "$1" ]]; then + echo "$0: Unknown command [${1}]" + usage + fi + break + ;; + esac +done diff --git a/src/modules/beamos/filesystem/migration/usr/bin/migrationos_to_beamos2.sh b/src/modules/beamos/filesystem/migration/usr/bin/migrationos_to_beamos2.sh new file mode 100755 index 00000000..8c356e11 --- /dev/null +++ b/src/modules/beamos/filesystem/migration/usr/bin/migrationos_to_beamos2.sh @@ -0,0 +1,72 @@ +#!/bin/bash + +BASEDIR="/usr/bin" + +# This script is used to flash the Beam OS 2 to the SD-Card. +# Then the Mr Beam will start to Beam OS 2. + +# This script uses migration.sh script + +# Usage: +# Flash the SD-Card +# Mount the SD-Card +# Restore Sensitive Data +# Set LED Status Success/Fail +# Shutdown the device + +# Exit immediately if a command exits with a non-zero status. +set -e + +timestamp() +{ + date +"%Y-%m-%d %T" +} + +do_exit() +{ + RET_CODE="$?" + echo "$(timestamp) $0: Exitting. ${RET_CODE}" + if [ "$RET_CODE" -eq 0 ]; then + echo "$0: Normal exiting." + else + echo "$0: Exiting with error code [${RET_CODE}]" + sudo bash ${BASEDIR}/migration.sh set-status fail + fi +} + + +############################################### +# Constants +############################################### +IMAGE_DIR="/home/pi/image" +BEAMOS2_IMAGE="${IMAGE_DIR}/beamos2.wic.bz2" + + +############################################### +# Main function +############################################### + +# Set trap before EXIT +trap do_exit EXIT + +# Flash the SD-Card +echo "$(timestamp) $0: Flashing the SD-Card" +sudo bash ${BASEDIR}/migration.sh set-status in-progress +sudo bash ${BASEDIR}/migration.sh flash beamos2 sd-card + +# Mount the SD-Card +echo "$(timestamp) $0: Mounting the SD-Card" +sudo bash ${BASEDIR}/migration.sh set-status in-progress +sudo bash ${BASEDIR}/migration.sh mount sd-card + +# Restore Sensitive Data +echo "$(timestamp) $0: Restoring Sensitive Data" +sudo bash ${BASEDIR}/migration.sh set-status in-progress +sudo bash ${BASEDIR}/migration.sh restore-data + +# Shutdown the device +echo "$(timestamp) $0: Shutdown the device" +sudo bash ${BASEDIR}/migration.sh set-status success +sudo bash ${BASEDIR}/migration.sh shutdown + +exit 0 diff --git a/src/modules/beamos/start_chroot_script b/src/modules/beamos/start_chroot_script index bcbd9c78..fe96b086 100755 --- a/src/modules/beamos/start_chroot_script +++ b/src/modules/beamos/start_chroot_script @@ -527,9 +527,15 @@ if [ -n "$BEAMOS_DEVICE_MODEL" ]; then fi ######Migration OS stuff##### +# Install bmap-tools for flashing the beamos2 image sudo apt-get install -y bmap-tools -#TODO download image into /home/pi/image +# TODO: SW-3164 Download image into /home/pi/image + +# Copy migrationos.sh and migrationos_to_beamos2.sh to /usr/bin +unpack /filesystem/migration / root + +# TODO: SW-4169 Add migration service to run migrationos_to_beamos2.sh on boot ##################################################################### ### setup systemd units/services From e4e898d091491aca456a4809d24baf7f5414f4b3 Mon Sep 17 00:00:00 2001 From: amrithvenkat <110397957+amrithvenkat@users.noreply.github.com> Date: Wed, 13 Dec 2023 16:20:39 +0100 Subject: [PATCH 09/35] SW-4209 Set a field to identify first boot after upgrade (#111) * Set the key server.firstBootAfterUpgrade to true * use the $configfile variable --- .../filesystem/migration/usr/bin/migration.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh index 6ac00d3e..53f4d9b9 100755 --- a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh +++ b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh @@ -273,21 +273,26 @@ do_restore_data () { backupfile="${backupfolder}${configfile}" applyfile="${applyfolder}${configfile}" #accessControl needed for users.yaml - echo "$(timestamp) $0: Restoring accessControl for /home/pi/.octoprint/config.yaml" + echo "$(timestamp) $0: Restoring accessControl for $configfile" sudo cat $backupfile | sudo yq ea -i 'select(fileIndex==0) * {"accessControl":select(fileIndex==1).accessControl}' $applyfile - #plugins.findmymrbeam - echo "$(timestamp) $0: Restoring plugins.findmymrbeam for /home/pi/.octoprint/config.yaml" + echo "$(timestamp) $0: Restoring plugins.findmymrbeam for $configfile" sudo cat $backupfile | sudo yq ea -i 'select(fileIndex==0) * {"plugins":{"findmymrbeam":select(fileIndex==1).plugins.findmymrbeam}}' $applyfile - #plugins.mrbeam.analyticsEnabled - echo "$(timestamp) $0: Restoring plugins.mrbeam.analyticsEnabled for /home/pi/.octoprint/config.yaml" + echo "$(timestamp) $0: Restoring plugins.mrbeam.analyticsEnabled for $configfile" sudo cat $backupfile | sudo yq ea -i 'select(fileIndex==0) * {"plugins":{"mrbeam":{"analyticsEnabled":select(fileIndex==1).plugins.mrbeam.analyticsEnabled}}}' $applyfile - #plugins.mrbeam.review - echo "$(timestamp) $0: Restoring plugins.mrbeam.review for /home/pi/.octoprint/config.yaml" + echo "$(timestamp) $0: Restoring plugins.mrbeam.review for $configfile" sudo cat $backupfile | sudo yq ea -i 'select(fileIndex==0) * {"plugins":{"mrbeam":{"review":select(fileIndex==1).plugins.mrbeam.review}}}' $applyfile - + #We now set a field to identify this as a first boot after upgrade + #server.firstBootAfterUpgrade + echo "$(timestamp) $0: Set server.firstBootAfterUpgrade for $configfile" + sudo yq eval -i '.server.firstBootAfterUpgrade = true' $applyfile + # Loop through the rest of the files and folders in the array and copy backed up files echo "$(timestamp) $0: Restoring the rest of the files to Home" for FILE in "${DATA_TO_RESTORE[@]}"; do From e61c0e862cf1bce03558fc765dfcc4263a0a3f51 Mon Sep 17 00:00:00 2001 From: caglarkilimci <110826807+caglarkilimci@users.noreply.github.com> Date: Thu, 14 Dec 2023 12:23:40 +0100 Subject: [PATCH 10/35] SW-3164 Create a Migration OS that includes Beam OS 2 (#110) * SW-3164 Download the latest stable image and place into /home/pi/image * SW-3164 Fix the bucket path * SW-3164 Update Google Application Credentials for downloading * SW-3164 Use different method for downloading the image * SW-3164 Set BASE_IMAGE_ENLARGEROOT to create enough space for Beam OS 2 image * SW-3164 Get the Beam OS 2 image name from secrets --- .github/workflows/build.yml | 26 +++++++++++++++++++ .../filesystem/migration/home/pi/image/README | 11 ++++++++ src/modules/beamos/start_chroot_script | 2 -- src/variants/beamos/config | 2 +- 4 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 src/modules/beamos/filesystem/migration/home/pi/image/README diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 70f29353..c3e51b87 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -115,6 +115,32 @@ jobs: run: | echo "OCTOPI_APTMIRROR=http://mirror.us.leaseweb.net/raspbian/raspbian" > repository/src/config.local + - name: Download the Beam OS 2 Image + uses: actions-hub/gcloud@master + env: + PROJECT_ID: devpi-310008 + APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_DOWNLOAD }} + with: + args: cp "${{ secrets.BEAMOS2_IMAGE }}" repository/src/image/ + cli: gsutil + + - name: Extract the Beam OS 2 Image + id: extract_the_image + run: | + # Set the image file + the_image=$(basename "${{ secrets.BEAMOS2_IMAGE }}") + source_dir="repository/src/image" + echo "The Beam OS 2 Image: ${the_image}" + target_dir="repository/src/modules/beamos/filesystem/migration/home/pi/image" + target_name="beamos2.wic" + # Extract bz2 file into target_dir + tar -xjf ${source_dir}/${the_image} -C $target_dir + # Rename the extracted image to beamos2.wic[bz2, bmap] and remove other files + mv ${target_dir}/mrbeam-image-*.wic.bz2 ${target_dir}/${target_name}.bz2 + mv ${target_dir}/mrbeam-image-*.wic.bmap ${target_dir}/${target_name}.bmap + rm ${target_dir}/mrbeam-* + echo "Placed the image in ${target_dir}/${target_name}.bz2 with bmap file" + - name: Build Image (MrBeam Variant) run: | sudo modprobe loop diff --git a/src/modules/beamos/filesystem/migration/home/pi/image/README b/src/modules/beamos/filesystem/migration/home/pi/image/README new file mode 100644 index 00000000..fb7b2992 --- /dev/null +++ b/src/modules/beamos/filesystem/migration/home/pi/image/README @@ -0,0 +1,11 @@ +# Beam OS 2 Image and bmap File + +This directory is intended for storing the "Beam OS 2" image and bmap file. Please follow the instructions below: + +1. Place the "Beam OS 2" image file here. The name of the image file should be: `beamos2.wic.bz2`. +2. Place the bmap file here. The name of the bmap file should be: `beamos2.wic.bmap`. +3. Use the `migrationos_to_beamos2.sh` script to flash the SD card with the Beam OS 2 image. +4. The migration service will automatically run the `migrationos_to_beamos2.sh` script. +5. No manual interaction is required during the migration process. + +For any further assistance, please refer to the documentation or contact the support team. diff --git a/src/modules/beamos/start_chroot_script b/src/modules/beamos/start_chroot_script index fe96b086..2938ce8f 100755 --- a/src/modules/beamos/start_chroot_script +++ b/src/modules/beamos/start_chroot_script @@ -530,8 +530,6 @@ fi # Install bmap-tools for flashing the beamos2 image sudo apt-get install -y bmap-tools -# TODO: SW-3164 Download image into /home/pi/image - # Copy migrationos.sh and migrationos_to_beamos2.sh to /usr/bin unpack /filesystem/migration / root diff --git a/src/variants/beamos/config b/src/variants/beamos/config index 6308075a..8c1eaed8 100755 --- a/src/variants/beamos/config +++ b/src/variants/beamos/config @@ -3,7 +3,7 @@ export DIST_NAME=MigrationOS export DIST_VERSION=0.1.0 export BASE_OVERRIDE_HOSTNAME=MigrationOS -#export BASE_IMAGE_ENLARGEROOT=1700 +export BASE_IMAGE_ENLARGEROOT=2250 export BEAMOS_DEV=no export MODULES="base(raspicam, network, disable-services(dev-libs(octopi, beamos)))" From fb1d732da9f0a95bc4df86ea7014c45ad76adf27 Mon Sep 17 00:00:00 2001 From: amrithvenkat <110397957+amrithvenkat@users.noreply.github.com> Date: Thu, 14 Dec 2023 15:02:20 +0100 Subject: [PATCH 11/35] SW-4169 add migration service (#112) * Add a service to run on boot of migrationos. * The service triggers the migrationos_to_beamos2.sh * Add to the chroot script to include in build. * Start migration service after ledstrips are on. --- .../systemd/system/migrationos_to_beamos2.service | 12 ++++++++++++ src/modules/beamos/start_chroot_script | 3 +-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 src/modules/beamos/filesystem/migration/etc/systemd/system/migrationos_to_beamos2.service diff --git a/src/modules/beamos/filesystem/migration/etc/systemd/system/migrationos_to_beamos2.service b/src/modules/beamos/filesystem/migration/etc/systemd/system/migrationos_to_beamos2.service new file mode 100644 index 00000000..212659f0 --- /dev/null +++ b/src/modules/beamos/filesystem/migration/etc/systemd/system/migrationos_to_beamos2.service @@ -0,0 +1,12 @@ +[Unit] +Description=Migration Service +After=mrbeam_ledstrips.service socket.service + +[Service] +Type=simple +# add a delay to make sure ledstrips are up and running +ExecStartPre=/bin/sleep 10 +ExecStart=/usr/bin/migrationos_to_beamos2.sh + +[Install] +WantedBy=multi-user.target diff --git a/src/modules/beamos/start_chroot_script b/src/modules/beamos/start_chroot_script index 2938ce8f..4f516b64 100755 --- a/src/modules/beamos/start_chroot_script +++ b/src/modules/beamos/start_chroot_script @@ -532,8 +532,7 @@ sudo apt-get install -y bmap-tools # Copy migrationos.sh and migrationos_to_beamos2.sh to /usr/bin unpack /filesystem/migration / root - -# TODO: SW-4169 Add migration service to run migrationos_to_beamos2.sh on boot +systemctl_if_exists enable migrationos_to_beamos2.service ##################################################################### ### setup systemd units/services From feb682223388f0c5ee404490bfbeabca63fb27bf Mon Sep 17 00:00:00 2001 From: amrithvenkat <110397957+amrithvenkat@users.noreply.github.com> Date: Mon, 18 Dec 2023 10:51:02 +0100 Subject: [PATCH 12/35] SW-4141 component improvements (#113) * Add materials.yaml to the backup and restore list. * Add mount_manager.log to the backup list. * Add section for giving all known users admin permission during restore data. --- .../filesystem/migration/usr/bin/migration.sh | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh index 53f4d9b9..c6300c4c 100755 --- a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh +++ b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh @@ -308,6 +308,40 @@ do_restore_data () { fi done + # Give admin permission to all users in the users.yaml file + # This is default in our implementation of OctoPrint access control + usersyamlfilelist=( + "${SDCARD_HOME_PATH}/pi/.octoprint/users.yaml" + "${SDCARD_HOME_PATH}/pi/.octoprint/users-dev.yaml" + ) + + for usersyamlfile in "${usersyamlfilelist[@]}"; do + if [ ! -f "$usersyamlfile" ]; then + echo "$(timestamp) $0: Restore data: Warning - File '${usersyamlfile}' not found. Skipping." + continue + fi + # Extract email addresses with a trailing colon + email_list=$(grep -E -o '\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b:' "$usersyamlfile" | sed 's/:$//') + + for email in $email_list; do + # Check if 'admin' role already exists for the email + admin_exists=$(sudo yq eval ".\"$email\".roles | select(.[] == \"admin\")" "$usersyamlfile") + + # If 'admin' role does not exist, append it + if [ -z "$admin_exists" ]; then + sudo yq eval -i ".\"$email\".roles += [\"admin\"]" "$usersyamlfile" + fi + + # Check if 'groups' field exists for the email + groups_exists=$(yq eval ".\"$email\".groups" "$usersyamlfile") + + # If 'groups' field does not exist, add it with specified values + if [ "$groups_exists" == "null" ]; then + sudo yq eval -i ".\"$email\".groups = [\"admins\", \"users\"]" "$usersyamlfile" + fi + done + done + echo "$(timestamp) $0: Restore data: Restore process completed." exit 0 } @@ -406,7 +440,7 @@ DATA_TO_PRESERVE=( "/home/pi/.octoprint/analytics/usage.yaml" "/home/pi/.octoprint/users.yaml" "/home/pi/.octoprint/users-dev.yaml" - "/home/pi/.octoprint/material.yaml" + "/home/pi/.octoprint/materials.yaml" "/home/pi/.octoprint/laser_heads.yaml" "/home/pi/.octoprint/config.yaml" "/etc/mrbeam" @@ -414,6 +448,7 @@ DATA_TO_PRESERVE=( "/etc/hostname" "/etc/hosts" "/etc/network/interfaces.d/wlan0-netconnectd_wifi" + "/var/log/mount_manager.log" # Add more file paths as needed ) @@ -422,7 +457,7 @@ DATA_TO_RESTORE=( ".octoprint/analytics/usage.yaml" ".octoprint/users.yaml" ".octoprint/users-dev.yaml" - ".octoprint/material.yaml" + ".octoprint/materials.yaml" # Other files are required manual intervention to restore ) From 91e451f759556d099827984407e7b0cc5beef448 Mon Sep 17 00:00:00 2001 From: amrithvenkat <110397957+amrithvenkat@users.noreply.github.com> Date: Fri, 22 Dec 2023 13:43:06 +0100 Subject: [PATCH 13/35] =?UTF-8?q?SW-4209=20Change=20field=20from=20server?= =?UTF-8?q?=20to=20plugins.mrbeam=20for=20the=20firstBootA=E2=80=A6=20(#11?= =?UTF-8?q?4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SW-4209 Change field from server to plugins.mrbeam for the firstBootAfterUpgrade --- .../beamos/filesystem/migration/usr/bin/migration.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh index c6300c4c..c33358aa 100755 --- a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh +++ b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh @@ -289,9 +289,9 @@ do_restore_data () { sudo cat $backupfile | sudo yq ea -i 'select(fileIndex==0) * {"plugins":{"mrbeam":{"review":select(fileIndex==1).plugins.mrbeam.review}}}' $applyfile - #We now set a field to identify this as a first boot after upgrade - #server.firstBootAfterUpgrade - echo "$(timestamp) $0: Set server.firstBootAfterUpgrade for $configfile" - sudo yq eval -i '.server.firstBootAfterUpgrade = true' $applyfile + #plugins.mrbeam.firstBootAfterUpgrade + echo "$(timestamp) $0: Set plugins.mrbeam.firstBootAfterUpgrade for $configfile" + sudo yq eval -i '.plugins.mrbeam.firstBootAfterUpgrade = true' $applyfile # Loop through the rest of the files and folders in the array and copy backed up files echo "$(timestamp) $0: Restoring the rest of the files to Home" From 6060452e79262ce8193f863cd019f5a00ca792ea Mon Sep 17 00:00:00 2001 From: amrithvenkat <110397957+amrithvenkat@users.noreply.github.com> Date: Tue, 2 Jan 2024 13:43:52 +0100 Subject: [PATCH 14/35] SW-4224 SW-4246 precondition check for mrbeamplugin version and backup files condition (#115) * Implement version check for MrBeamPlugin version and fail if less than min version. * Remove the parameter for preserve-data command and associated helper function. * Update usage displayed. * Modify helper method find_usb_device_name to accomodate for legacy image. * Modify dd function call. * Check for salt in accesscontrol of config.yaml. * create a temp file to store list of files to skip persistent. * reuse the file in preserve-data method. * Check for missing values in /etc/mrbeam. * Exit if there are missing values --- .../filesystem/migration/usr/bin/migration.sh | 69 ++++++++++++++++--- 1 file changed, 60 insertions(+), 9 deletions(-) diff --git a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh index c33358aa..8c92f7e5 100755 --- a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh +++ b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh @@ -18,8 +18,7 @@ usage () { echo " - can be \"sd-card\" or device path like \"/dev/sda\". " echo " mount Mounts the partitions of . " echo " - can be \"sd-card\" or device path like \"/dev/sda\". " - echo " preserve-data Preserves sensitive data into USB with . " - echo " - is the path of usb device mounted like \"/mnt/usb\". " + echo " preserve-data Preserves sensitive data into USB at path \"/mnt/usb\". " echo " restore-data Restores sensitive data into SD-Card. " echo " set-status Sets the of LED. can be one of the following: " echo " - success " @@ -38,6 +37,51 @@ timestamp() do_precondition_checks () { echo "$(timestamp) $0: precondition-checks" + configfile="/home/pi/.octoprint/config.yaml" + + local MIN_REQ_MRBEAM_PLUGIN_VERSION="0.15.1" + #Check the MrBeamPlugin version + mrbeam_plugin_version=$(/home/pi/oprint/bin/pip list | grep Mr-Beam | awk '{gsub(/[()]/,""); print $2}') + + if $(dpkg --compare-versions "$mrbeam_plugin_version" "lt" $MIN_REQ_MRBEAM_PLUGIN_VERSION); then + echo "$(timestamp) $0: MrBeamPlugin version - $mrbeam_plugin_version must be greater than $MIN_REQ_MRBEAM_PLUGIN_VERSION for Migration." + exit 1 + fi + echo "$(timestamp) $0: MrBeamPlugin version is $mrbeam_plugin_version. Migration can be done." + + # Create a file to store the list of files to skip backing up + sudo touch ${SKIP_FILE_NAME} || true + echo "" > ${SKIP_FILE_NAME} + # Check if salt is present in config.yaml and decide if users.yaml, users-dev.yaml should be preserved or not + is_salt_in_config=$(( $(sed -n 's/^[[:space:]]*salt:[[:space:]]*\(.*\)/\1/p' "$configfile" | wc -c) > 0 )) + if [ $is_salt_in_config -eq 0 ]; then + echo "$(timestamp) $0: Salt is not present in config.yaml. Files will be skipped in preserve-data." + sed -i -e '$a\' -e '/home\/pi\/.octoprint\/users.yaml' -e '$a\' -e '/home\/pi\/.octoprint\/users-dev.yaml' ${SKIP_FILE_NAME} + fi + + # Verify integrity of /etc/mrbeam file. Fail if any field is empty or file doesnt exist. + # Check if the file exists + if [ ! -f "/etc/mrbeam" ]; then + echo "$(timestamp) $0: /etc/mrbeam file not found." + exit 1 + fi + # Read each line from the file + while IFS= read -r line; do + # Check if the line is not empty + if [ -n "$line" ]; then + # Split the line into key and value + key=$(echo "$line" | cut -d'=' -f1) + value=$(echo "$line" | cut -d'=' -f2-) + + # Check if the value is empty + if [ -z "$value" ]; then + echo "$(timestamp) $0: File /etc/mrbeam is corrupt. Empty value for key: $key" + exit 1 + fi + fi + done < "/etc/mrbeam" + echo "$(timestamp) $0: /etc/mrbeam is valid. No empty fields found." + # Get the list of USB block devices with sizes in bytes USB_DRIVES=$(lsblk -o NAME,SIZE,TYPE,TRAN -dn --bytes | grep 'usb' | awk '{print $1,$2}') @@ -65,7 +109,7 @@ do_precondition_checks () { find_current_booted_os_version () { - if [ -f /etc/beamos_version ]; then + if [ -f /etc/beamos_version ] || [ -f /etc/octopi_version ] ; then echo "beamos1" elif [ -f /etc/migrationos_version ]; then echo "migrationos" @@ -99,7 +143,7 @@ do_flash () { fi echo "$(timestamp) $0: Flashing USB with migrationos" sudo umount ${DEVICE_TO_BE_FLASHED}* || true - sudo dd if=${IMAGE_FILE} of=${DEVICE_TO_BE_FLASHED} bs=4M status=progress conv=fsync + sudo dd if=${IMAGE_FILE} of=${DEVICE_TO_BE_FLASHED} bs=4M conv=fsync STATUS=$? else echo "$(timestamp) $0: Check inputs to the function flash" @@ -140,14 +184,13 @@ do_mount () { # Mounting the USB with migrationos # There are 2 partitions on the USB. The first one is the boot partition and the second one is the rootfs. DEVICE_PARTITION=${DEVICE_TO_BE_MOUNTED}2 - MOUNT_DIR="/mnt/usb" DEVICE_PARTITIONS=( ${DEVICE_PARTITION} ) MOUNT_DIRS=( - ${MOUNT_DIR} + ${USB_MOUNT_PATH} ) else echo "$(timestamp) $0: Check inputs to the function mount" @@ -173,7 +216,6 @@ do_mount () { do_preserve_data () { - local USB_MOUNT_PATH="$1" echo "$(timestamp) $0: preserve-data $USB_MOUNT_PATH" # path like "/mnt/usb" if [ -z "${USB_MOUNT_PATH}" ]; then echo "$(timestamp) $0: No suitable backup partition found. Exiting..." @@ -200,11 +242,18 @@ do_preserve_data () { mkdir -p "$BACKUP_BASE" + mapfile -t LIST_TO_SKIP < ${SKIP_FILE_NAME} + SKIPPED=0 # Loop through each file in the array and create a backup copy for FILE in "${DATA_TO_PRESERVE[@]}"; do if [ -f "${FILE}" ] || [ -d "${FILE}" ]; then + if [[ " ${LIST_TO_SKIP[@]} " =~ " $FILE " ]]; then + echo "$(timestamp) $0: Warning - File ${FILE} skipped as salt is not present in config.yaml" + ((SKIPPED++)) + continue + fi TARGET_DIR="${BACKUP_BASE}/$(dirname "${FILE}")" mkdir -p ${TARGET_DIR} TARGET="${TARGET_DIR}/$(basename "${FILE}")" @@ -421,6 +470,7 @@ MIGRATION_IMAGE="${IMAGE_DIR}/migrationos.img" BEAMOS2_IMAGE="${IMAGE_DIR}/beamos2.wic.bz2" MIN_USB_SIZE_IN_GB=4 BACKUP_PATH="/mrbeam/preserve-data" +SKIP_FILE_NAME="./files_to_skip_preserve_data" # There are 8 partitions on the SD-Card. # Root filesystems are on partition 2 and 3. @@ -434,6 +484,8 @@ SDCARD_ROOTFS_A_PATH="/mnt/sd-card/rootfs_a" SDCARD_ROOTFS_B_PATH="/mnt/sd-card/rootfs_b" SDCARD_HOME_PATH="/mnt/sd-card/home" +USB_MOUNT_PATH="/mnt/usb" + # list of files treated by preserve-data and restore-data DATA_TO_PRESERVE=( "/home/pi/.octoprint/cam" # is a folder @@ -507,8 +559,7 @@ while true ; do break ;; preserve-data) - do_preserve_data "$2" - shift + do_preserve_data shift break ;; From 04b15fd70ab1f380f8ae0918236f21953674b44b Mon Sep 17 00:00:00 2001 From: amrithvenkat <110397957+amrithvenkat@users.noreply.github.com> Date: Tue, 9 Jan 2024 14:54:24 +0100 Subject: [PATCH 15/35] SW-4263 temporary removal of cam folder from backup and restore (#116) * exclude cam folder from backup and restore --- src/modules/beamos/filesystem/migration/usr/bin/migration.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh index 8c92f7e5..f4ec6629 100755 --- a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh +++ b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh @@ -488,7 +488,7 @@ USB_MOUNT_PATH="/mnt/usb" # list of files treated by preserve-data and restore-data DATA_TO_PRESERVE=( - "/home/pi/.octoprint/cam" # is a folder +# "/home/pi/.octoprint/cam" # is a folder "/home/pi/.octoprint/analytics/usage.yaml" "/home/pi/.octoprint/users.yaml" "/home/pi/.octoprint/users-dev.yaml" @@ -505,7 +505,7 @@ DATA_TO_PRESERVE=( ) DATA_TO_RESTORE=( - ".octoprint/cam" # is a folder +# ".octoprint/cam" # is a folder ".octoprint/analytics/usage.yaml" ".octoprint/users.yaml" ".octoprint/users-dev.yaml" From d91e19708f3fb4900d9dd25912e664cdc9b898fd Mon Sep 17 00:00:00 2001 From: amrithvenkat <110397957+amrithvenkat@users.noreply.github.com> Date: Wed, 10 Jan 2024 13:19:21 +0100 Subject: [PATCH 16/35] SW-4263 include cam folder except lens calibration file (#117) * Backup cam folder * Restore cam folder except lens calibration file. --- src/modules/beamos/filesystem/migration/usr/bin/migration.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh index f4ec6629..861104c9 100755 --- a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh +++ b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh @@ -488,7 +488,7 @@ USB_MOUNT_PATH="/mnt/usb" # list of files treated by preserve-data and restore-data DATA_TO_PRESERVE=( -# "/home/pi/.octoprint/cam" # is a folder + "/home/pi/.octoprint/cam" # is a folder "/home/pi/.octoprint/analytics/usage.yaml" "/home/pi/.octoprint/users.yaml" "/home/pi/.octoprint/users-dev.yaml" @@ -506,6 +506,8 @@ DATA_TO_PRESERVE=( DATA_TO_RESTORE=( # ".octoprint/cam" # is a folder + ".octoprint/cam/last_session.yaml" + ".octoprint/cam/pic_settings.yaml" ".octoprint/analytics/usage.yaml" ".octoprint/users.yaml" ".octoprint/users-dev.yaml" From 2d3bc69937c199fd4fe9d8339ad1fcc2c27b95f1 Mon Sep 17 00:00:00 2001 From: Amrith Venkat Kesavamoorthi Date: Wed, 24 Jan 2024 17:14:01 +0100 Subject: [PATCH 17/35] update actions checkout version --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c3e51b87..4a68be09 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -83,14 +83,14 @@ jobs: END - name: Checkout CustomPiOS - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: repository: 'mrbeam/CustomPiOS' path: CustomPiOS ref: 'test_devpi_josef' - name: Checkout Project Repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: submodules: recursive path: repository From 549bad7fa2b58796e0acde699042916d9f6218b8 Mon Sep 17 00:00:00 2001 From: Amrith Venkat Kesavamoorthi Date: Wed, 24 Jan 2024 17:19:26 +0100 Subject: [PATCH 18/35] use environment variable instead of secrets --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4a68be09..e3b7ad2b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -121,14 +121,14 @@ jobs: PROJECT_ID: devpi-310008 APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_DOWNLOAD }} with: - args: cp "${{ secrets.BEAMOS2_IMAGE }}" repository/src/image/ + args: cp "${{ vars.BEAMOS2_IMAGE }}" repository/src/image/ cli: gsutil - name: Extract the Beam OS 2 Image id: extract_the_image run: | # Set the image file - the_image=$(basename "${{ secrets.BEAMOS2_IMAGE }}") + the_image=$(basename "${{ vars.BEAMOS2_IMAGE }}") source_dir="repository/src/image" echo "The Beam OS 2 Image: ${the_image}" target_dir="repository/src/modules/beamos/filesystem/migration/home/pi/image" From 09ed5569c8eedefd6c9ffaf8d3ba1a474de06e17 Mon Sep 17 00:00:00 2001 From: amrithvenkat <110397957+amrithvenkat@users.noreply.github.com> Date: Fri, 26 Jan 2024 12:18:16 +0100 Subject: [PATCH 19/35] SW-4269 handle migration of cam folder without errors (#119) * install numpy * santize_npz.py skeleton * handle pickle error * backup original file before applying transformation. * use right backup module * formatting checks --------- Co-authored-by: Josef-MrBeam --- .../filesystem/migration/usr/bin/migration.sh | 8 +-- .../migration/usr/bin/sanitize_npz.py | 54 +++++++++++++++++++ src/modules/beamos/start_chroot_script | 2 + 3 files changed, 61 insertions(+), 3 deletions(-) create mode 100755 src/modules/beamos/filesystem/migration/usr/bin/sanitize_npz.py diff --git a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh index 861104c9..30b74037 100755 --- a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh +++ b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh @@ -342,6 +342,10 @@ do_restore_data () { echo "$(timestamp) $0: Set plugins.mrbeam.firstBootAfterUpgrade for $configfile" sudo yq eval -i '.plugins.mrbeam.firstBootAfterUpgrade = true' $applyfile + # Run python script to sanitize lens calibration files + echo "$(timestamp) $0: Sanitizing lens calibration files" + sanitize_npz.py + # Loop through the rest of the files and folders in the array and copy backed up files echo "$(timestamp) $0: Restoring the rest of the files to Home" for FILE in "${DATA_TO_RESTORE[@]}"; do @@ -505,9 +509,7 @@ DATA_TO_PRESERVE=( ) DATA_TO_RESTORE=( -# ".octoprint/cam" # is a folder - ".octoprint/cam/last_session.yaml" - ".octoprint/cam/pic_settings.yaml" + ".octoprint/cam" # is a folder ".octoprint/analytics/usage.yaml" ".octoprint/users.yaml" ".octoprint/users-dev.yaml" diff --git a/src/modules/beamos/filesystem/migration/usr/bin/sanitize_npz.py b/src/modules/beamos/filesystem/migration/usr/bin/sanitize_npz.py new file mode 100755 index 00000000..4d30c530 --- /dev/null +++ b/src/modules/beamos/filesystem/migration/usr/bin/sanitize_npz.py @@ -0,0 +1,54 @@ +#!/usr/bin/python3 +""" Module to santitize npz files to be compatible with python 3.x """ +import os +import shutil +import numpy as np + + +PRESERVE_DATA_CAM_DIRECTORY = "/mrbeam/preserve-data/home/pi/.octoprint/cam/" + +BUSTER_FACTORY_LENS_CALIBRATION = "factory_lens_correction.npz" +LEGACY_FACTORY_LENS_CALIBRATION = "lens_correction_2048x1536.npz" +USER_LENS_CALIBRATION = "lens_correction.npz" + +LENS_CALIBRATTION_FILES = [ + BUSTER_FACTORY_LENS_CALIBRATION, + LEGACY_FACTORY_LENS_CALIBRATION, + USER_LENS_CALIBRATION, +] + + +def sanitize_npz(npz_file: str) -> None: + """Sanitize npz files to be compatible with python 3.x. + + Args: + * npz_file (str) : path to the npz file to be sanitized + + Returns: + * None + + Raises: + * np.lib.format.FormatError: if the file is not a valid npz file + """ + print("Sanitizing: " + npz_file) + try: + data = np.load(npz_file, encoding="latin1", allow_pickle=True) + except np.lib.format.FormatError as _e: + print("Error loading file: " + str(_e)) + np.savez_compressed(npz_file, **data) + + +def sanitize_npz_files() -> None: + """Sanitize all npz files in the cam directory""" + for _f in LENS_CALIBRATTION_FILES: + npz_file = os.path.join(PRESERVE_DATA_CAM_DIRECTORY, _f) + if os.path.isfile(npz_file): + # create backup retain the original file + shutil.copy2(npz_file, npz_file + ".original") + sanitize_npz(npz_file) + else: + print("File not found: " + npz_file) + + +if __name__ == "__main__": + sanitize_npz_files() diff --git a/src/modules/beamos/start_chroot_script b/src/modules/beamos/start_chroot_script index 4f516b64..e6de807f 100755 --- a/src/modules/beamos/start_chroot_script +++ b/src/modules/beamos/start_chroot_script @@ -530,6 +530,8 @@ fi # Install bmap-tools for flashing the beamos2 image sudo apt-get install -y bmap-tools +pip3 install numpy + # Copy migrationos.sh and migrationos_to_beamos2.sh to /usr/bin unpack /filesystem/migration / root systemctl_if_exists enable migrationos_to_beamos2.service From f6376e9a1c2bc64a6a2fc96982e20344cabb74b0 Mon Sep 17 00:00:00 2001 From: caglarkilimci <110826807+caglarkilimci@users.noreply.github.com> Date: Fri, 2 Feb 2024 11:15:27 +0100 Subject: [PATCH 20/35] SW-4356 Add migration-operator attribute into config.yaml (#120) * SW-4356 Merge migration-operator attribute with server url and port * SW-4356 Use underscore for the migration operator variable --- .../beamos/filesystem/migration/usr/bin/migration.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh index 30b74037..40627ac8 100755 --- a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh +++ b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh @@ -321,6 +321,7 @@ do_restore_data () { configfile="/home/pi/.octoprint/config.yaml" backupfile="${backupfolder}${configfile}" applyfile="${applyfolder}${configfile}" + migrationoperator="workshop" #accessControl needed for users.yaml echo "$(timestamp) $0: Restoring accessControl for $configfile" sudo cat $backupfile | sudo yq ea -i 'select(fileIndex==0) * {"accessControl":select(fileIndex==1).accessControl}' $applyfile - @@ -337,6 +338,13 @@ do_restore_data () { echo "$(timestamp) $0: Restoring plugins.mrbeam.review for $configfile" sudo cat $backupfile | sudo yq ea -i 'select(fileIndex==0) * {"plugins":{"mrbeam":{"review":select(fileIndex==1).plugins.mrbeam.review}}}' $applyfile - + #plugins.swupdater.attributes.migration_operator + echo "$(timestamp) $0: Save plugins.swupdater.server_url and plugins.swupdater.server_port from $applyfile" + server_url=$(sudo yq eval '.plugins.swupdater.server_url' $applyfile) + server_port=$(sudo yq eval '.plugins.swupdater.server_port' $applyfile) + echo "$(timestamp) $0: Set plugins.swupdater.attributes.migration_operator as $migrationoperator for $configfile" + sudo yq e -i ".plugins.swupdater |= {\"server_url\": \"$server_url\", \"server_port\": $server_port, \"attributes\": {\"migration_operator\": \"$migrationoperator\"}}" $applyfile + #We now set a field to identify this as a first boot after upgrade #plugins.mrbeam.firstBootAfterUpgrade echo "$(timestamp) $0: Set plugins.mrbeam.firstBootAfterUpgrade for $configfile" From aedcec537d1a4fd95ee67fadc6280afe802f2f13 Mon Sep 17 00:00:00 2001 From: amrithvenkat <110397957+amrithvenkat@users.noreply.github.com> Date: Thu, 8 Feb 2024 16:02:11 +0100 Subject: [PATCH 21/35] SW-4370 add migration operator only to the config.yaml (#121) * use same logic in migration.sh for migration_operator as used by the backup_restore stick --- src/modules/beamos/filesystem/migration/usr/bin/migration.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh index 40627ac8..56300453 100755 --- a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh +++ b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh @@ -339,11 +339,8 @@ do_restore_data () { sudo cat $backupfile | sudo yq ea -i 'select(fileIndex==0) * {"plugins":{"mrbeam":{"review":select(fileIndex==1).plugins.mrbeam.review}}}' $applyfile - #plugins.swupdater.attributes.migration_operator - echo "$(timestamp) $0: Save plugins.swupdater.server_url and plugins.swupdater.server_port from $applyfile" - server_url=$(sudo yq eval '.plugins.swupdater.server_url' $applyfile) - server_port=$(sudo yq eval '.plugins.swupdater.server_port' $applyfile) echo "$(timestamp) $0: Set plugins.swupdater.attributes.migration_operator as $migrationoperator for $configfile" - sudo yq e -i ".plugins.swupdater |= {\"server_url\": \"$server_url\", \"server_port\": $server_port, \"attributes\": {\"migration_operator\": \"$migrationoperator\"}}" $applyfile + sudo yq e -i ".plugins.swupdater |= {\"attributes\": {\"migration_operator\": \"$migrationoperator\"}}" $applyfile #We now set a field to identify this as a first boot after upgrade #plugins.mrbeam.firstBootAfterUpgrade From 0daa2f1e9b503e5c39a763fd6df47bbe1fe39d3f Mon Sep 17 00:00:00 2001 From: amrithvenkat <110397957+amrithvenkat@users.noreply.github.com> Date: Fri, 16 Feb 2024 12:01:33 +0100 Subject: [PATCH 22/35] SW-4391 split sig and image files (#122) * Split MigrationOS from the sig file. * Pass USB_ROOT as a parameter to the caller migration script. * Use specific colors in the status fail calls, status progress calls. * Bump version of migration.sh script. * Status fail will alternate indefinitely between specific color and red based on error. * Status progress blue for phase 1 of migration. * Status progress orange for phase 2 of migration. * Add parameter of color in usage() * Correct phase color on not finding image file when trying to flash image. --- .../filesystem/migration/usr/bin/migration.sh | 122 +++++++++++++----- .../usr/bin/migrationos_to_beamos2.sh | 10 +- 2 files changed, 98 insertions(+), 34 deletions(-) diff --git a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh index 56300453..b15f94f2 100755 --- a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh +++ b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh @@ -5,27 +5,31 @@ echo "Beam OS1 to Beam OS2 Migration Script" usage () { - echo "Beam OS1 to Beam OS2 Migration Script v1.0.0 " + echo "Beam OS1 to Beam OS2 Migration Script v1.1.0 " echo " " echo "OPTIONS: " echo " " echo " --help Print this help message and exit. " echo " " echo "COMMANDS: " - echo " precondition-checks Checks the sw and hw components so that Mr Beam can be upgrade or not. " - echo " flash Flashes the with using . " - echo " - can be \"beamos2\" or \"migrationos\". " - echo " - can be \"sd-card\" or device path like \"/dev/sda\". " - echo " mount Mounts the partitions of . " - echo " - can be \"sd-card\" or device path like \"/dev/sda\". " - echo " preserve-data Preserves sensitive data into USB at path \"/mnt/usb\". " - echo " restore-data Restores sensitive data into SD-Card. " - echo " set-status Sets the of LED. can be one of the following: " - echo " - success " - echo " - fail " - echo " - in-progress " - echo " config-boot-usb Configures Mr Beam to be able to boot from USB. " - echo " shutdown Shutdown Mr Beam. " + echo " precondition-checks Checks the sw and hw components so that Mr Beam can be upgrade or not. " + echo " - is derived from the USB_ROOT. " + echo " flash Flashes the with using . " + echo " - can be \"beamos2\" or \"migrationos\". " + echo " - can be \"sd-card\" or device path like \"/dev/sda\". " + echo " mount Mounts the partitions of . " + echo " - can be \"sd-card\" or device path like \"/dev/sda\". " + echo " preserve-data Preserves sensitive data into USB at path \"/mnt/usb\". " + echo " restore-data Restores sensitive data into SD-Card. " + echo " set-status Sets the of LED in a " + echo " can be one of the following: " + echo " - success " + echo " - fail " + echo " - in-progress " + echo " can be one of the following: " + echo " - red,blue,green,orange,(purple,teal-only in specific error cases) " + echo " config-boot-usb Configures Mr Beam to be able to boot from USB. " + echo " shutdown Shutdown Mr Beam. " } @@ -35,7 +39,8 @@ timestamp() } do_precondition_checks () { - echo "$(timestamp) $0: precondition-checks" + MNT_PATH="$1" + echo "$(timestamp) $0: precondition-checks $MNT_PATH." configfile="/home/pi/.octoprint/config.yaml" @@ -45,6 +50,7 @@ do_precondition_checks () { if $(dpkg --compare-versions "$mrbeam_plugin_version" "lt" $MIN_REQ_MRBEAM_PLUGIN_VERSION); then echo "$(timestamp) $0: MrBeamPlugin version - $mrbeam_plugin_version must be greater than $MIN_REQ_MRBEAM_PLUGIN_VERSION for Migration." + do_set_status fail ${FLASH_PURPLE} exit 1 fi echo "$(timestamp) $0: MrBeamPlugin version is $mrbeam_plugin_version. Migration can be done." @@ -63,6 +69,7 @@ do_precondition_checks () { # Check if the file exists if [ ! -f "/etc/mrbeam" ]; then echo "$(timestamp) $0: /etc/mrbeam file not found." + do_set_status fail ${FLASH_PURPLE} exit 1 fi # Read each line from the file @@ -76,6 +83,7 @@ do_precondition_checks () { # Check if the value is empty if [ -z "$value" ]; then echo "$(timestamp) $0: File /etc/mrbeam is corrupt. Empty value for key: $key" + do_set_status fail ${FLASH_PURPLE} exit 1 fi fi @@ -88,6 +96,7 @@ do_precondition_checks () { # Check if there are any USB drives if [ -z "$USB_DRIVES" ]; then echo "$(timestamp) $0: No USB drives found." + do_set_status fail ${FLASH_PURPLE} exit 1 fi @@ -98,13 +107,44 @@ do_precondition_checks () { if [ "$DEVICE_SIZE_BYTES" -gt $((MIN_USB_SIZE_IN_GB * 1024 * 1024 * 1024)) ]; then DEVICE_SIZE_GIGABYTES=$((DEVICE_SIZE_BYTES / 1024 / 1024 / 1024)) echo "$(timestamp) $0: USB drive of $DEVICE_SIZE_GIGABYTES GB present." - exit 0 + else + echo "$(timestamp) $0: No USB drive of size greater than ${MIN_USB_SIZE_IN_GB}GB found." + do_set_status fail ${FLASH_PURPLE} + exit 1 fi done <<< "$USB_DRIVES" - echo "$(timestamp) $0: No USB drive of size greater than ${MIN_USB_SIZE_IN_GB}GB found." - exit 1 + MIGRATIONOS_ENC_PATH="${MNT_PATH}/migrationos.enc" + # Check if valid MigrationOS encrypted is present + if [ -f ${MIGRATIONOS_ENC_PATH} ]; then + echo "$(timestamp) $0: Found valid MigrationOS encrypted: ${MIGRATIONOS_ENC_PATH}" + # verify gpg signature + if gpg --verify "${MIGRATIONOS_ENC_PATH}"; then + echo "$(timestamp) $0: GPG signature verified for ${MIGRATIONOS_ENC_PATH}" + else + echo "$(timestamp) $0: GPG signature verification failed for ${MIGRATIONOS_ENC_PATH}" + do_set_status fail ${FLASH_PURPLE} + exit 1 + fi + else + echo "$(timestamp) $0: MigrationOS encrypted file ${MIGRATIONOS_ENC_PATH} not found" + do_set_status fail ${FLASH_PURPLE} + exit 1 + fi + + # Decryption of migrationos.enc as migrationos.img onto /home/pi/usb_mount directory + echo "$(timestamp) $0: Decrypting ${MIGRATIONOS_ENC_PATH} to ${MIGRATION_IMAGE_BASEDIR}" + gpg --output ${MIGRATION_IMAGE_BASEDIR} --decrypt ${MIGRATIONOS_ENC_PATH} + if [ $? -ne 0 ]; then + echo "$(timestamp) $0: Decryption failed for ${MIGRATIONOS_ENC_PATH}" + do_set_status fail ${FLASH_TEAL} + exit 1 + fi + echo "$(timestamp) $0: Decryption successful for ${MIGRATIONOS_ENC_PATH} to ${MIGRATION_IMAGE_BASEDIR}" + + #Exit on success + exit 0 } @@ -129,30 +169,36 @@ do_flash () { # check if the image is there if [ ! -f ${IMAGE_FILE} ]; then echo "$(timestamp) $0: Image not found: ${IMAGE_FILE}" + do_set_status fail orange exit 1 fi sudo umount ${SD_CARD_DEVICE}* || true sudo bmaptool copy ${IMAGE_FILE} ${SD_CARD_DEVICE} STATUS=$? + FLASH_COLOR_ON_FAIL_TO_FLASH="orange" elif [ "$OS_TO_BE_FLASHED" = "migrationos" ] && [ "$CURRENT_OS_VERSION" = "beamos1" ];then # check if the image is there IMAGE_FILE="${MIGRATION_IMAGE}" if [ ! -f ${IMAGE_FILE} ]; then echo "$(timestamp) $0: Image not found: ${IMAGE_FILE}" + do_set_status fail blue exit 1 fi echo "$(timestamp) $0: Flashing USB with migrationos" sudo umount ${DEVICE_TO_BE_FLASHED}* || true sudo dd if=${IMAGE_FILE} of=${DEVICE_TO_BE_FLASHED} bs=4M conv=fsync STATUS=$? + FLASH_COLOR_ON_FAIL_TO_FLASH="blue" else echo "$(timestamp) $0: Check inputs to the function flash" + do_set_status fail red exit 1 fi # check status of flashing if [ $STATUS -ne 0 ]; then echo "$(timestamp) $0: Flashing Failed - $OS_TO_BE_FLASHED on $DEVICE_TO_BE_FLASHED from $CURRENT_OS_VERSION" + do_set_status fail ${FLASH_COLOR_ON_FAIL_TO_FLASH} exit 1 fi @@ -180,6 +226,7 @@ do_mount () { ${SDCARD_ROOTFS_B_PATH} ${SDCARD_HOME_PATH} ) + FLASH_COLOR_ON_FAIL_TO_MOUNT="orange" elif [ "$DEVICE_TO_BE_MOUNTED" != "sd-card" ] && [ "$CURRENT_OS_VERSION" = "beamos1" ];then # Mounting the USB with migrationos # There are 2 partitions on the USB. The first one is the boot partition and the second one is the rootfs. @@ -192,8 +239,10 @@ do_mount () { MOUNT_DIRS=( ${USB_MOUNT_PATH} ) + FLASH_COLOR_ON_FAIL_TO_MOUNT="blue" else echo "$(timestamp) $0: Check inputs to the function mount" + do_set_status fail red exit 1 fi @@ -204,6 +253,7 @@ do_mount () { # Check if the mount is successful if [ $? -ne 0 ]; then echo "$(timestamp) $0: Can't mount ${DEVICE_PARTITIONS[$i]}" + do_set_status fail ${FLASH_COLOR_ON_FAIL_TO_MOUNT} exit 1 fi done @@ -219,6 +269,7 @@ do_preserve_data () { echo "$(timestamp) $0: preserve-data $USB_MOUNT_PATH" # path like "/mnt/usb" if [ -z "${USB_MOUNT_PATH}" ]; then echo "$(timestamp) $0: No suitable backup partition found. Exiting..." + do_set_status fail blue exit 1 fi @@ -404,6 +455,9 @@ do_restore_data () { exit 0 } +FLASH_PURPLE="color:128:0:128" +FLASH_TEAL="color:10:100:100" + set_status_success() { echo "$(timestamp) $0: status_success" mrbeam_ledstrips_cli flash_green @@ -413,33 +467,38 @@ set_status_success() { set_status_fail () { echo "$(timestamp) $0: status_fail" - mrbeam_ledstrips_cli flash_red - sleep 1 - mrbeam_ledstrips_cli red + while true + do + mrbeam_ledstrips_cli flash_$1:1 + sleep 1 + mrbeam_ledstrips_cli flash_red + sleep 1 + done } set_status_in_progress () { echo "$(timestamp) $0: status_in_progress" - mrbeam_ledstrips_cli flash_color:120:120:120:4; + mrbeam_ledstrips_cli flash_$1:4; sleep 0.4 ; - mrbeam_ledstrips_cli flash_color:40:40:40:5 + mrbeam_ledstrips_cli flash_$1:5 } do_set_status () { STATUS="$1" + COLOR="$2" echo "$(timestamp) $0: set-status ${STATUS}" if [ "${STATUS}" = "success" ]; then echo "${STATUS}" set_status_success elif [ "${STATUS}" = "fail" ]; then echo "${STATUS}" - set_status_fail + set_status_fail "$COLOR" elif [ "${STATUS}" = "in-progress" ]; then echo "${STATUS}" - set_status_in_progress + set_status_in_progress "$COLOR" else echo "$(timestamp) $0: Unknown status [${STATUS}]" - set_status_fail + set_status_fail red fi exit 0 } @@ -474,6 +533,9 @@ do_exit () { ## migration.sh script configuration ################################################################################ +MIGRATIONOS_ENC="migrationos.enc" +BASEDIR="/home/pi/usb_mount" +MIGRATION_IMAGE_BASEDIR=${BASEDIR}/migrationos.img IMAGE_DIR="/home/pi/image" MIGRATION_IMAGE="${IMAGE_DIR}/migrationos.img" BEAMOS2_IMAGE="${IMAGE_DIR}/beamos2.wic.bz2" @@ -550,7 +612,8 @@ trap do_exit EXIT while true ; do case "$1" in precondition-checks) - do_precondition_checks + do_precondition_checks "$2" + shift shift break ;; @@ -578,7 +641,8 @@ while true ; do break ;; set-status) - do_set_status "$2" + do_set_status "$2" "$3" + shift shift shift break diff --git a/src/modules/beamos/filesystem/migration/usr/bin/migrationos_to_beamos2.sh b/src/modules/beamos/filesystem/migration/usr/bin/migrationos_to_beamos2.sh index 8c356e11..3fea2f11 100755 --- a/src/modules/beamos/filesystem/migration/usr/bin/migrationos_to_beamos2.sh +++ b/src/modules/beamos/filesystem/migration/usr/bin/migrationos_to_beamos2.sh @@ -30,7 +30,7 @@ do_exit() echo "$0: Normal exiting." else echo "$0: Exiting with error code [${RET_CODE}]" - sudo bash ${BASEDIR}/migration.sh set-status fail + sudo bash ${BASEDIR}/migration.sh set-status fail orange fi } @@ -51,17 +51,17 @@ trap do_exit EXIT # Flash the SD-Card echo "$(timestamp) $0: Flashing the SD-Card" -sudo bash ${BASEDIR}/migration.sh set-status in-progress +sudo bash ${BASEDIR}/migration.sh set-status in-progress orange sudo bash ${BASEDIR}/migration.sh flash beamos2 sd-card # Mount the SD-Card echo "$(timestamp) $0: Mounting the SD-Card" -sudo bash ${BASEDIR}/migration.sh set-status in-progress -sudo bash ${BASEDIR}/migration.sh mount sd-card +sudo bash ${BASEDIR}/migration.sh set-status in-progress orange +sudo bash ${BASEDIR}/migration.sh mount sd-cards # Restore Sensitive Data echo "$(timestamp) $0: Restoring Sensitive Data" -sudo bash ${BASEDIR}/migration.sh set-status in-progress +sudo bash ${BASEDIR}/migration.sh set-status in-progress orange sudo bash ${BASEDIR}/migration.sh restore-data # Shutdown the device From 5b4780a0439c74b631e513717c963a4dceeeddf4 Mon Sep 17 00:00:00 2001 From: amrithvenkat <110397957+amrithvenkat@users.noreply.github.com> Date: Mon, 19 Feb 2024 12:47:49 +0100 Subject: [PATCH 23/35] SW-4389 Add precondition check for sd card size (#123) * Check for sd-card size greater than 12GB to migrate. * Introduce exit codes for each stage associated with colors on do_exit(). * Remove stray exit 0. * Catch exit codes on error and send exit 100 to to flash orange on phase 2. * Amend wrong parameter to mount function call --- .../filesystem/migration/usr/bin/migration.sh | 94 ++++++++++++------- .../usr/bin/migrationos_to_beamos2.sh | 26 ++++- 2 files changed, 81 insertions(+), 39 deletions(-) diff --git a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh index b15f94f2..a8c43222 100755 --- a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh +++ b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh @@ -5,7 +5,7 @@ echo "Beam OS1 to Beam OS2 Migration Script" usage () { - echo "Beam OS1 to Beam OS2 Migration Script v1.1.0 " + echo "Beam OS1 to Beam OS2 Migration Script v1.2.0 " echo " " echo "OPTIONS: " echo " " @@ -26,6 +26,7 @@ usage () { echo " - success " echo " - fail " echo " - in-progress " + echo " - warn " echo " can be one of the following: " echo " - red,blue,green,orange,(purple,teal-only in specific error cases) " echo " config-boot-usb Configures Mr Beam to be able to boot from USB. " @@ -44,14 +45,25 @@ do_precondition_checks () { configfile="/home/pi/.octoprint/config.yaml" + # Check the size of SD-Card + echo "$(timestamp) $0: Checking the size of SD-Card." + local SD_CARD_SIZE=$(lsblk -b -o SIZE /dev/mmcblk0 | tail -n 1) + SD_CARD_SIZE_GIGABYTES=$((SD_CARD_SIZE / 1024 / 1024 / 1024)) + echo "$(timestamp) $0: SD-Card size - ${SD_CARD_SIZE_GIGABYTES}GB found" + if [ "$SD_CARD_SIZE" -gt $((MIN_SD_SIZE_IN_GB * 1024 * 1024 * 1024)) ]; then + echo "$(timestamp) $0: SD-Card size is greater than ${MIN_SD_SIZE_IN_GB}GB. Migration can be done." + else + echo "$(timestamp) $0: SD-Card size must be greater than ${MIN_SD_SIZE_IN_GB}GB for Migration." + exit 100 + fi + local MIN_REQ_MRBEAM_PLUGIN_VERSION="0.15.1" #Check the MrBeamPlugin version mrbeam_plugin_version=$(/home/pi/oprint/bin/pip list | grep Mr-Beam | awk '{gsub(/[()]/,""); print $2}') if $(dpkg --compare-versions "$mrbeam_plugin_version" "lt" $MIN_REQ_MRBEAM_PLUGIN_VERSION); then echo "$(timestamp) $0: MrBeamPlugin version - $mrbeam_plugin_version must be greater than $MIN_REQ_MRBEAM_PLUGIN_VERSION for Migration." - do_set_status fail ${FLASH_PURPLE} - exit 1 + exit 101 fi echo "$(timestamp) $0: MrBeamPlugin version is $mrbeam_plugin_version. Migration can be done." @@ -69,8 +81,7 @@ do_precondition_checks () { # Check if the file exists if [ ! -f "/etc/mrbeam" ]; then echo "$(timestamp) $0: /etc/mrbeam file not found." - do_set_status fail ${FLASH_PURPLE} - exit 1 + exit 101 fi # Read each line from the file while IFS= read -r line; do @@ -83,8 +94,7 @@ do_precondition_checks () { # Check if the value is empty if [ -z "$value" ]; then echo "$(timestamp) $0: File /etc/mrbeam is corrupt. Empty value for key: $key" - do_set_status fail ${FLASH_PURPLE} - exit 1 + exit 101 fi fi done < "/etc/mrbeam" @@ -96,8 +106,7 @@ do_precondition_checks () { # Check if there are any USB drives if [ -z "$USB_DRIVES" ]; then echo "$(timestamp) $0: No USB drives found." - do_set_status fail ${FLASH_PURPLE} - exit 1 + exit 101 fi while read -r line; do @@ -109,8 +118,7 @@ do_precondition_checks () { echo "$(timestamp) $0: USB drive of $DEVICE_SIZE_GIGABYTES GB present." else echo "$(timestamp) $0: No USB drive of size greater than ${MIN_USB_SIZE_IN_GB}GB found." - do_set_status fail ${FLASH_PURPLE} - exit 1 + exit 101 fi done <<< "$USB_DRIVES" @@ -124,13 +132,11 @@ do_precondition_checks () { echo "$(timestamp) $0: GPG signature verified for ${MIGRATIONOS_ENC_PATH}" else echo "$(timestamp) $0: GPG signature verification failed for ${MIGRATIONOS_ENC_PATH}" - do_set_status fail ${FLASH_PURPLE} - exit 1 + exit 101 fi else echo "$(timestamp) $0: MigrationOS encrypted file ${MIGRATIONOS_ENC_PATH} not found" - do_set_status fail ${FLASH_PURPLE} - exit 1 + exit 101 fi # Decryption of migrationos.enc as migrationos.img onto /home/pi/usb_mount directory @@ -138,8 +144,7 @@ do_precondition_checks () { gpg --output ${MIGRATION_IMAGE_BASEDIR} --decrypt ${MIGRATIONOS_ENC_PATH} if [ $? -ne 0 ]; then echo "$(timestamp) $0: Decryption failed for ${MIGRATIONOS_ENC_PATH}" - do_set_status fail ${FLASH_TEAL} - exit 1 + exit 102 fi echo "$(timestamp) $0: Decryption successful for ${MIGRATIONOS_ENC_PATH} to ${MIGRATION_IMAGE_BASEDIR}" @@ -169,8 +174,7 @@ do_flash () { # check if the image is there if [ ! -f ${IMAGE_FILE} ]; then echo "$(timestamp) $0: Image not found: ${IMAGE_FILE}" - do_set_status fail orange - exit 1 + exit 103 fi sudo umount ${SD_CARD_DEVICE}* || true sudo bmaptool copy ${IMAGE_FILE} ${SD_CARD_DEVICE} @@ -181,8 +185,7 @@ do_flash () { IMAGE_FILE="${MIGRATION_IMAGE}" if [ ! -f ${IMAGE_FILE} ]; then echo "$(timestamp) $0: Image not found: ${IMAGE_FILE}" - do_set_status fail blue - exit 1 + exit 104 fi echo "$(timestamp) $0: Flashing USB with migrationos" sudo umount ${DEVICE_TO_BE_FLASHED}* || true @@ -191,15 +194,17 @@ do_flash () { FLASH_COLOR_ON_FAIL_TO_FLASH="blue" else echo "$(timestamp) $0: Check inputs to the function flash" - do_set_status fail red - exit 1 + exit 105 fi # check status of flashing if [ $STATUS -ne 0 ]; then echo "$(timestamp) $0: Flashing Failed - $OS_TO_BE_FLASHED on $DEVICE_TO_BE_FLASHED from $CURRENT_OS_VERSION" - do_set_status fail ${FLASH_COLOR_ON_FAIL_TO_FLASH} - exit 1 + if [ $FLASH_COLOR_ON_FAIL_TO_FLASH="orange"]; then + exit 103 + elif [ $FLASH_COLOR_ON_FAIL_TO_FLASH="blue"]; then + exit 104 + fi fi sudo sync @@ -242,8 +247,7 @@ do_mount () { FLASH_COLOR_ON_FAIL_TO_MOUNT="blue" else echo "$(timestamp) $0: Check inputs to the function mount" - do_set_status fail red - exit 1 + exit 105 fi for i in "${!DEVICE_PARTITIONS[@]}"; do @@ -253,14 +257,15 @@ do_mount () { # Check if the mount is successful if [ $? -ne 0 ]; then echo "$(timestamp) $0: Can't mount ${DEVICE_PARTITIONS[$i]}" - do_set_status fail ${FLASH_COLOR_ON_FAIL_TO_MOUNT} - exit 1 + if [ $FLASH_COLOR_ON_FAIL_TO_MOUNT="orange"]; then + exit 103 + elif [ $FLASH_COLOR_ON_FAIL_TO_MOUNT="blue"]; then + exit 104 + fi fi done echo "Mounting Successful - $DEVICE_TO_BE_MOUNTED" - - exit 0 } @@ -269,8 +274,7 @@ do_preserve_data () { echo "$(timestamp) $0: preserve-data $USB_MOUNT_PATH" # path like "/mnt/usb" if [ -z "${USB_MOUNT_PATH}" ]; then echo "$(timestamp) $0: No suitable backup partition found. Exiting..." - do_set_status fail blue - exit 1 + exit 104 fi # Create a backup directory (if it doesn't exist) @@ -483,6 +487,11 @@ set_status_in_progress () { mrbeam_ledstrips_cli flash_$1:5 } +set_status_warn () { + echo "$(timestamp) $0: status_warn" + mrbeam_ledstrips_cli flash_$1:1; +} + do_set_status () { STATUS="$1" COLOR="$2" @@ -496,11 +505,13 @@ do_set_status () { elif [ "${STATUS}" = "in-progress" ]; then echo "${STATUS}" set_status_in_progress "$COLOR" + elif [ "${STATUS}" = "warn" ]; then + echo "${STATUS}" + set_status_warn "$COLOR" else echo "$(timestamp) $0: Unknown status [${STATUS}]" set_status_fail red fi - exit 0 } do_config_boot_usb () { @@ -525,7 +536,19 @@ do_exit () { echo "$0: Normal exiting." else echo "$0: Exiting with error code [${RET_CODE}]" - set_status_fail + if [ "${RET_CODE}" -eq 100 ]; then + do_set_status warn ${FLASH_PURPLE} + elif [ "${RET_CODE}" -eq 101 ]; then + do_set_status fail ${FLASH_PURPLE} + elif [ "${RET_CODE}" -eq 102 ]; then + do_set_status fail ${FLASH_TEAL} + elif [ "${RET_CODE}" -eq 103 ]; then + do_set_status fail orange + elif [ "${RET_CODE}" -eq 104 ]; then + do_set_status fail blue + elif [ "${RET_CODE}" -eq 105 ]; then + do_set_status fail red + fi fi } @@ -540,6 +563,7 @@ IMAGE_DIR="/home/pi/image" MIGRATION_IMAGE="${IMAGE_DIR}/migrationos.img" BEAMOS2_IMAGE="${IMAGE_DIR}/beamos2.wic.bz2" MIN_USB_SIZE_IN_GB=4 +MIN_SD_SIZE_IN_GB=12 BACKUP_PATH="/mrbeam/preserve-data" SKIP_FILE_NAME="./files_to_skip_preserve_data" diff --git a/src/modules/beamos/filesystem/migration/usr/bin/migrationos_to_beamos2.sh b/src/modules/beamos/filesystem/migration/usr/bin/migrationos_to_beamos2.sh index 3fea2f11..c2456598 100755 --- a/src/modules/beamos/filesystem/migration/usr/bin/migrationos_to_beamos2.sh +++ b/src/modules/beamos/filesystem/migration/usr/bin/migrationos_to_beamos2.sh @@ -14,9 +14,6 @@ BASEDIR="/usr/bin" # Set LED Status Success/Fail # Shutdown the device -# Exit immediately if a command exits with a non-zero status. -set -e - timestamp() { date +"%Y-%m-%d %T" @@ -28,6 +25,7 @@ do_exit() echo "$(timestamp) $0: Exitting. ${RET_CODE}" if [ "$RET_CODE" -eq 0 ]; then echo "$0: Normal exiting." + sudo bash ${BASEDIR}/migration.sh set-status success else echo "$0: Exiting with error code [${RET_CODE}]" sudo bash ${BASEDIR}/migration.sh set-status fail orange @@ -53,20 +51,40 @@ trap do_exit EXIT echo "$(timestamp) $0: Flashing the SD-Card" sudo bash ${BASEDIR}/migration.sh set-status in-progress orange sudo bash ${BASEDIR}/migration.sh flash beamos2 sd-card +exit_code=$? +if [ "$exit_code" -ne 0 ]; then + echo "$(timestamp) $0: Flashing the SD-Card failed" + exit 100 +fi # Mount the SD-Card echo "$(timestamp) $0: Mounting the SD-Card" sudo bash ${BASEDIR}/migration.sh set-status in-progress orange -sudo bash ${BASEDIR}/migration.sh mount sd-cards +sudo bash ${BASEDIR}/migration.sh mount sd-card +exit_code=$? +if [ "$exit_code" -ne 0 ]; then + echo "$(timestamp) $0: Mounting the SD-Card failed" + exit 100 +fi # Restore Sensitive Data echo "$(timestamp) $0: Restoring Sensitive Data" sudo bash ${BASEDIR}/migration.sh set-status in-progress orange sudo bash ${BASEDIR}/migration.sh restore-data +exit_code=$? +if [ "$exit_code" -ne 0 ]; then + echo "$(timestamp) $0: Restoring Sensitive Data failed" + exit 100 +fi # Shutdown the device echo "$(timestamp) $0: Shutdown the device" sudo bash ${BASEDIR}/migration.sh set-status success sudo bash ${BASEDIR}/migration.sh shutdown +exit_code=$? +if [ "$exit_code" -ne 0 ]; then + echo "$(timestamp) $0: Shutdown the device failed" + exit 100 +fi exit 0 From 8c6b7bd3fa4bd9e29416cded3bb6d1298ed107ab Mon Sep 17 00:00:00 2001 From: Josef-MrBeam <81746291+Josef-MrBeam@users.noreply.github.com> Date: Mon, 19 Feb 2024 22:24:47 +0100 Subject: [PATCH 24/35] SW-4400 add colored progress for the leds (#125) * add mrb3-led-strip repo * update python to 3.10 * set size to 3GB --- .github/workflows/build.yml | 3 ++ src/modules/beamos/config | 8 ++-- src/modules/beamos/start_chroot_script | 4 +- src/modules/octopi/start_chroot_script | 54 +++++++++++++++++++++----- src/variants/beamos/config | 2 +- 5 files changed, 54 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e3b7ad2b..5615bec8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -142,10 +142,13 @@ jobs: echo "Placed the image in ${target_dir}/${target_name}.bz2 with bmap file" - name: Build Image (MrBeam Variant) + env: + PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} run: | sudo modprobe loop cd repository/src echo "export EXTRA_SSH_KEY='${{ secrets.SSH_BEAMOS01_RSA }}'" >> config + echo "export PERSONAL_ACCESS_TOKEN='${{ secrets.PERSONAL_ACCESS_TOKEN }}'" >> config sudo bash -x ./build_dist $VARIANT ${{ matrix.flavor }} - name: Copy output diff --git a/src/modules/beamos/config b/src/modules/beamos/config index d79d5712..2fceb148 100755 --- a/src/modules/beamos/config +++ b/src/modules/beamos/config @@ -14,7 +14,7 @@ TRUE_USER=pi ## Dependencies [ -n "$BEAMOS_IOBEAM_REPO_BRANCH" ] || BEAMOS_IOBEAM_REPO_BRANCH=v1.3.1 [ -n "$BEAMOS_MRBHWINFO_REPO_BRANCH" ] || BEAMOS_MRBHWINFO_REPO_BRANCH=v1.0.0 -[ -n "$BEAMOS_MRBEAMLED_REPO_BRANCH" ] || BEAMOS_MRBEAMLED_REPO_BRANCH=v1.0.0 +[ -n "$BEAMOS_MRBEAMLED_REPO_BRANCH" ] || BEAMOS_MRBEAMLED_REPO_BRANCH=v2.1.0a0 [ -n "$BEAMOS_NETCONNECTD_REPO_BRANCH" ] || BEAMOS_NETCONNECTD_REPO_BRANCH=v1.0.0 [ -n "$BEAMOS_MRBEAMPLUGIN_DOCS_REPO_BRANCH" ] || BEAMOS_MRBEAMPLUGIN_DOCS_REPO_BRANCH=v1.1.0 ## BeamOS-dependencies @@ -53,9 +53,9 @@ TRUE_USER=pi [ -n "$BEAMOS_MRBHWINFO_REPO_SHIP" ] || BEAMOS_MRBHWINFO_REPO_SHIP=git+ssh://git@bitbucket.org/mrbeam/mrb_hw_info.git [ -n "$BEAMOS_INCLUDE_MRBEAMLED" ] || BEAMOS_INCLUDE_MRBEAMLED=yes -[ -n "$BEAMOS_MRBEAMLED_ARCHIVE" ] || BEAMOS_MRBEAMLED_ARCHIVE=https://github.com/mrbeam/MrBeamLedStrips/archive/$BEAMOS_MRBEAMLED_REPO_BRANCH.zip -[ -n "$BEAMOS_MRBEAMLED_REPO_BUILD" ] || BEAMOS_MRBEAMLED_REPO_BUILD=https://github.com/mrbeam/MrBeamLedStrips.git -[ -n "$BEAMOS_MRBEAMLED_REPO_SHIP" ] || BEAMOS_MRBEAMLED_REPO_SHIP=https://github.com/mrbeam/MrBeamLedStrips.git +[ -n "$BEAMOS_MRBEAMLED_ARCHIVE" ] || BEAMOS_MRBEAMLED_ARCHIVE=git+https://${PERSONAL_ACCESS_TOKEN}@github.com/mrbeam/mrb3-led-strips.git@$BEAMOS_MRBEAMLED_REPO_BRANCH +[ -n "$BEAMOS_MRBEAMLED_REPO_BUILD" ] || BEAMOS_MRBEAMLED_REPO_BUILD=https://github.com/mrbeam/mrb3-led-strips.git +[ -n "$BEAMOS_MRBEAMLED_REPO_SHIP" ] || BEAMOS_MRBEAMLED_REPO_SHIP=https://github.com/mrbeam/mrb3-led-strips.git [ -n "$BEAMOS_RPI_WS281X_ARCHIVE" ] || BEAMOS_RPI_WS281X_ARCHIVE=rpi-ws281x # Netconnectd and Netconnectd plugin diff --git a/src/modules/beamos/start_chroot_script b/src/modules/beamos/start_chroot_script index e6de807f..c4a6ff2b 100755 --- a/src/modules/beamos/start_chroot_script +++ b/src/modules/beamos/start_chroot_script @@ -61,7 +61,7 @@ add_mrb3() { apt-get -y install python3 python3-venv python3-dev # create mrb virtual environments # TODO create mrb2 and mrb3 (python 2 and 3 versions) - sudo -u pi python3.7 -m venv /home/pi/mrb3 + sudo -u pi python3.10 -m venv /home/pi/mrb3 } OPRINT=/home/pi/oprint/bin @@ -460,7 +460,7 @@ pushd /home/pi # apt-install python3-pip # Install in a separate venv LED_VENV=/usr/local/mrbeam_ledstrips/venv - python3 -m virtualenv -p python3 $LED_VENV + python3.10 -m venv $LED_VENV $LED_VENV/bin/pip install $BEAMOS_RPI_WS281X_ARCHIVE $BEAMOS_MRBEAMLED_ARCHIVE # Link the executables to have mrbeam_ledstrips(_cli) in the $PATH ln -s $LED_VENV/bin/mrbeam_ledstrips /usr/bin/ diff --git a/src/modules/octopi/start_chroot_script b/src/modules/octopi/start_chroot_script index 7ca366f8..826e0ffa 100755 --- a/src/modules/octopi/start_chroot_script +++ b/src/modules/octopi/start_chroot_script @@ -34,21 +34,55 @@ else fi apt-get -y --force-yes install python3 python3-virtualenv git screen subversion cmake avahi-daemon libavahi-compat-libdnssd1 libatlas3-base +#apt-get -y install software-properties-common +#add-apt-repository ppa:deadsnakes/ppa +#apt-get update +#apt install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget +PYTHON3_VERSION=3.10.6 +file="Python-${PYTHON3_VERSION}.tar.xz" +url="https://www.python.org/ftp/python/${PYTHON3_VERSION}/${file}" +apt-get -y install python3-virtualenv git screen subversion cmake avahi-daemon libavahi-compat-libdnssd1 libatlas3-base +#wget -qO - https://raw.githubusercontent.com/tvdsluijs/sh-python-installer/main/python.sh | sudo bash -s 3.10.0 +echo "Updating & upgrading system" +apt -qq update && apt --yes --force-yes upgrade < /dev/null +echo "Installing Python essentials" +apt -qq install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev < /dev/null +echo "Downloading Python $PYTHON3_VERSION" +wget "${url}" +echo "Decompressing file" +tar -Jxf "${file}" < /dev/null +cd "Python-${PYTHON3_VERSION}" +echo "Prepare the source for the installation" +./configure --enable-optimizations +echo "(Install the new Python version $PYTHON3_VERSION)" +sudo make altinstall +#echo "Let's try to create package" +#sudo cpack +echo "Let's cleanup!" +cd .. +rm -rf "Python-${PYTHON3_VERSION}" +rm -r "${file}" + +echo "Let's install PIP" +apt -qq install -y python3-pip < /dev/null + +#echo "updating pip..." +#python"${py_main_version}" -m pip install --upgrade pip + +new_python_version=$(python -c 'import platform; print(platform.python_version())') +echo "new python version $new_python_version" + +new_python_version=$(python3 -c 'import platform; print(platform.python_version())') +echo "new python version3 $new_python_version" + +new_python_version=$(python3.10 -c 'import platform; print(platform.python_version())') +echo "new python version3.10 $new_python_version" + echo " - Reinstall iputils-ping" apt-get install --reinstall iputils-ping pushd /home/"${BASE_USER}" - # build virtualenv - sudo -u "${BASE_USER}" python3 -m virtualenv --python=$PYTHON oprint - sudo -u "${BASE_USER}" /home/"${BASE_USER}"/oprint/bin/pip install --upgrade pip - - # OctoPrint - if [ "$OCTOPI_INCLUDE_OCTOPRINT" == "yes" ] - then - echo "--- Installing OctoPrint" - PIP_DEFAULT_TIMEOUT=60 sudo -u "${BASE_USER}" /home/"${BASE_USER}"/oprint/bin/pip install $OCTOPI_OCTOPRINT_ARCHIVE - fi #mjpg-streamer if [ "$OCTOPI_INCLUDE_MJPGSTREAMER" == "yes" ] diff --git a/src/variants/beamos/config b/src/variants/beamos/config index 8c1eaed8..5d4b3e0f 100755 --- a/src/variants/beamos/config +++ b/src/variants/beamos/config @@ -3,7 +3,7 @@ export DIST_NAME=MigrationOS export DIST_VERSION=0.1.0 export BASE_OVERRIDE_HOSTNAME=MigrationOS -export BASE_IMAGE_ENLARGEROOT=2250 +export BASE_IMAGE_ENLARGEROOT=3050 export BEAMOS_DEV=no export MODULES="base(raspicam, network, disable-services(dev-libs(octopi, beamos)))" From ddd4a32fb1865b79120772eddddf4face2a77863 Mon Sep 17 00:00:00 2001 From: Josef-MrBeam <81746291+Josef-MrBeam@users.noreply.github.com> Date: Tue, 20 Feb 2024 12:51:08 +0100 Subject: [PATCH 25/35] SW-4397 Add the defined led strip lighting and their progressive loading during the two long phases (#124) * add led progress * remove old in progress * move blinking to background --- .../filesystem/migration/usr/bin/migration.sh | 19 ++-------- .../usr/bin/migrationos_to_beamos2.sh | 9 +++-- .../filesystem/migration/usr/bin/progress.sh | 38 +++++++++++++++++++ 3 files changed, 48 insertions(+), 18 deletions(-) create mode 100644 src/modules/beamos/filesystem/migration/usr/bin/progress.sh diff --git a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh index a8c43222..0f241fee 100755 --- a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh +++ b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh @@ -5,7 +5,7 @@ echo "Beam OS1 to Beam OS2 Migration Script" usage () { - echo "Beam OS1 to Beam OS2 Migration Script v1.2.0 " + echo "Beam OS1 to Beam OS2 Migration Script v1.3.0 " echo " " echo "OPTIONS: " echo " " @@ -25,8 +25,7 @@ usage () { echo " can be one of the following: " echo " - success " echo " - fail " - echo " - in-progress " - echo " - warn " + echo " - warn " echo " can be one of the following: " echo " - red,blue,green,orange,(purple,teal-only in specific error cases) " echo " config-boot-usb Configures Mr Beam to be able to boot from USB. " @@ -480,13 +479,6 @@ set_status_fail () { done } -set_status_in_progress () { - echo "$(timestamp) $0: status_in_progress" - mrbeam_ledstrips_cli flash_$1:4; - sleep 0.4 ; - mrbeam_ledstrips_cli flash_$1:5 -} - set_status_warn () { echo "$(timestamp) $0: status_warn" mrbeam_ledstrips_cli flash_$1:1; @@ -501,16 +493,13 @@ do_set_status () { set_status_success elif [ "${STATUS}" = "fail" ]; then echo "${STATUS}" - set_status_fail "$COLOR" - elif [ "${STATUS}" = "in-progress" ]; then - echo "${STATUS}" - set_status_in_progress "$COLOR" + set_status_fail "$COLOR" & elif [ "${STATUS}" = "warn" ]; then echo "${STATUS}" set_status_warn "$COLOR" else echo "$(timestamp) $0: Unknown status [${STATUS}]" - set_status_fail red + set_status_fail red & fi } diff --git a/src/modules/beamos/filesystem/migration/usr/bin/migrationos_to_beamos2.sh b/src/modules/beamos/filesystem/migration/usr/bin/migrationos_to_beamos2.sh index c2456598..99edb7cf 100755 --- a/src/modules/beamos/filesystem/migration/usr/bin/migrationos_to_beamos2.sh +++ b/src/modules/beamos/filesystem/migration/usr/bin/migrationos_to_beamos2.sh @@ -38,6 +38,8 @@ do_exit() ############################################### IMAGE_DIR="/home/pi/image" BEAMOS2_IMAGE="${IMAGE_DIR}/beamos2.wic.bz2" +MAX_TIME=900 # 15 minutes in seconds +PHASE_COLOR="ORANGE" ############################################### @@ -47,9 +49,12 @@ BEAMOS2_IMAGE="${IMAGE_DIR}/beamos2.wic.bz2" # Set trap before EXIT trap do_exit EXIT +# start progress leds +current_pid=$$ +sudo bash ${BASEDIR}/progress.sh $current_pid $MAX_TIME $PHASE_COLOR & + # Flash the SD-Card echo "$(timestamp) $0: Flashing the SD-Card" -sudo bash ${BASEDIR}/migration.sh set-status in-progress orange sudo bash ${BASEDIR}/migration.sh flash beamos2 sd-card exit_code=$? if [ "$exit_code" -ne 0 ]; then @@ -59,7 +64,6 @@ fi # Mount the SD-Card echo "$(timestamp) $0: Mounting the SD-Card" -sudo bash ${BASEDIR}/migration.sh set-status in-progress orange sudo bash ${BASEDIR}/migration.sh mount sd-card exit_code=$? if [ "$exit_code" -ne 0 ]; then @@ -69,7 +73,6 @@ fi # Restore Sensitive Data echo "$(timestamp) $0: Restoring Sensitive Data" -sudo bash ${BASEDIR}/migration.sh set-status in-progress orange sudo bash ${BASEDIR}/migration.sh restore-data exit_code=$? if [ "$exit_code" -ne 0 ]; then diff --git a/src/modules/beamos/filesystem/migration/usr/bin/progress.sh b/src/modules/beamos/filesystem/migration/usr/bin/progress.sh new file mode 100644 index 00000000..80f02126 --- /dev/null +++ b/src/modules/beamos/filesystem/migration/usr/bin/progress.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +# Check if PID and total time are provided +if [ $# -ne 2 ]; then + echo "Usage: $0 [color]" + exit 1 +fi + +pid=$1 +total_time=$2 +color=${3:-"BLUE"} + +# Check if the process exists +if ! ps -p $pid > /dev/null; then + echo "Process with PID $pid not found." + exit 1 +fi + +# Start tracking time +start_time=$(ps -o etimes= -p $pid) +last_percentage=0 +while ps -p $pid > /dev/null; do + current_time=$(ps -o etimes= -p $pid) + runtime=$((current_time - start_time)) + percentage=$((runtime * 100 / total_time)) + if [[ $percentage -ne $last_percentage && $percentage -lt 99 ]]; then + echo "Percentage of runtime: $percentage % ($runtime s)" + last_percentage=$percentage + if [ "$color" == "BLUE" ]; then + mrbeam_ledstrips_cli progress:$percentage + else + mrbeam_ledstrips_cli progress:$percentage:$color + fi + elif [[ $percentage -ge 99 ]]; then + exit 0 + fi + sleep 5 +done From ad1467c17fa18321f05cc71713cd4a8f4e86583a Mon Sep 17 00:00:00 2001 From: caglarkilimci <110826807+caglarkilimci@users.noreply.github.com> Date: Wed, 21 Feb 2024 16:53:57 +0100 Subject: [PATCH 26/35] SW-4388 Add checks for restoring users.yaml file (#127) --- .../filesystem/migration/usr/bin/migration.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh index 0f241fee..f56ef8bb 100755 --- a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh +++ b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh @@ -435,6 +435,21 @@ do_restore_data () { # Extract email addresses with a trailing colon email_list=$(grep -E -o '\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b:' "$usersyamlfile" | sed 's/:$//') + # Check if the email_list is empty + if [ -z "$email_list" ]; then + echo "$(timestamp) $0: Restore data: Warning - No email addresses found in '${usersyamlfile}'. Removing it." + sudo rm -f "$usersyamlfile" + continue + fi + + # Check if there are any active users + active_user=$(sudo yq eval '.. | select(has("active")) | .active' "$usersyamlfile" | grep true) + if [ -z "$active_user" ]; then + echo "$(timestamp) $0: Restore data: Warning - No active user found in '${usersyamlfile}'. Removing it." + sudo rm -f "$usersyamlfile" + continue + fi + for email in $email_list; do # Check if 'admin' role already exists for the email admin_exists=$(sudo yq eval ".\"$email\".roles | select(.[] == \"admin\")" "$usersyamlfile") From d2db395f2bfc8132e70b00a9448c3cfb58a94d86 Mon Sep 17 00:00:00 2001 From: Josef-MrBeam <81746291+Josef-MrBeam@users.noreply.github.com> Date: Thu, 22 Feb 2024 10:31:50 +0100 Subject: [PATCH 27/35] SW-4410 Migration without one button press (#126) * switch migration to reboot instead of shutdown * fix colored progress * fix permission --- .../filesystem/migration/usr/bin/migration.sh | 14 +++++++------- .../migration/usr/bin/migrationos_to_beamos2.sh | 10 +++++----- .../filesystem/migration/usr/bin/progress.sh | 2 +- src/modules/beamos/start_chroot_script | 5 +++++ 4 files changed, 18 insertions(+), 13 deletions(-) mode change 100644 => 100755 src/modules/beamos/filesystem/migration/usr/bin/progress.sh diff --git a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh index f56ef8bb..8846435c 100755 --- a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh +++ b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh @@ -5,7 +5,7 @@ echo "Beam OS1 to Beam OS2 Migration Script" usage () { - echo "Beam OS1 to Beam OS2 Migration Script v1.3.0 " + echo "Beam OS1 to Beam OS2 Migration Script v1.4.0 " echo " " echo "OPTIONS: " echo " " @@ -29,7 +29,7 @@ usage () { echo " can be one of the following: " echo " - red,blue,green,orange,(purple,teal-only in specific error cases) " echo " config-boot-usb Configures Mr Beam to be able to boot from USB. " - echo " shutdown Shutdown Mr Beam. " + echo " reboot Reboot Mr Beam. " } @@ -526,9 +526,9 @@ do_config_boot_usb () { exit 0 } -do_shutdown () { - echo "$(timestamp) $0: shutdown" - sudo shutdown now +do_reboot () { + echo "$(timestamp) $0: reboot" + sudo reboot now exit 0 } @@ -680,8 +680,8 @@ while true ; do shift break ;; - shutdown) - do_shutdown + reboot) + do_reboot shift break ;; diff --git a/src/modules/beamos/filesystem/migration/usr/bin/migrationos_to_beamos2.sh b/src/modules/beamos/filesystem/migration/usr/bin/migrationos_to_beamos2.sh index 99edb7cf..fb65e44e 100755 --- a/src/modules/beamos/filesystem/migration/usr/bin/migrationos_to_beamos2.sh +++ b/src/modules/beamos/filesystem/migration/usr/bin/migrationos_to_beamos2.sh @@ -12,7 +12,7 @@ BASEDIR="/usr/bin" # Mount the SD-Card # Restore Sensitive Data # Set LED Status Success/Fail -# Shutdown the device +# Reboot the device timestamp() { @@ -80,13 +80,13 @@ if [ "$exit_code" -ne 0 ]; then exit 100 fi -# Shutdown the device -echo "$(timestamp) $0: Shutdown the device" +# Reboot the device +echo "$(timestamp) $0: Reboot the device" sudo bash ${BASEDIR}/migration.sh set-status success -sudo bash ${BASEDIR}/migration.sh shutdown +sudo bash ${BASEDIR}/migration.sh reboot exit_code=$? if [ "$exit_code" -ne 0 ]; then - echo "$(timestamp) $0: Shutdown the device failed" + echo "$(timestamp) $0: Reboot the device failed" exit 100 fi diff --git a/src/modules/beamos/filesystem/migration/usr/bin/progress.sh b/src/modules/beamos/filesystem/migration/usr/bin/progress.sh old mode 100644 new mode 100755 index 80f02126..766087e0 --- a/src/modules/beamos/filesystem/migration/usr/bin/progress.sh +++ b/src/modules/beamos/filesystem/migration/usr/bin/progress.sh @@ -1,7 +1,7 @@ #!/bin/bash # Check if PID and total time are provided -if [ $# -ne 2 ]; then +if [ $# -lt 2 ]; then echo "Usage: $0 [color]" exit 1 fi diff --git a/src/modules/beamos/start_chroot_script b/src/modules/beamos/start_chroot_script index c4a6ff2b..a3675022 100755 --- a/src/modules/beamos/start_chroot_script +++ b/src/modules/beamos/start_chroot_script @@ -551,3 +551,8 @@ update-rc.d beamos_first_boot defaults # let's remove the configs for system services we don't need # rm /etc/systemd/system/netconnectd.service # fi + +# Dirty fix for reboot issue +line_to_append="gpio=14=ip,pu" +file_path="/boot/config.txt" +sed -i "1i$line_to_append" "$file_path" From 2abede8e4fe0ae6795697ae3e6ae40785cd74363 Mon Sep 17 00:00:00 2001 From: caglarkilimci <110826807+caglarkilimci@users.noreply.github.com> Date: Thu, 22 Feb 2024 13:14:46 +0100 Subject: [PATCH 28/35] SW-4388 Set config fields if the value is presented at the backed up one (#128) SW-4388 Set config fields if the value is presented at the backed up one. --- .../filesystem/migration/usr/bin/migration.sh | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh index 8846435c..0532b96f 100755 --- a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh +++ b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh @@ -378,19 +378,46 @@ do_restore_data () { migrationoperator="workshop" #accessControl needed for users.yaml echo "$(timestamp) $0: Restoring accessControl for $configfile" - sudo cat $backupfile | sudo yq ea -i 'select(fileIndex==0) * {"accessControl":select(fileIndex==1).accessControl}' $applyfile - + accessControl=$(sudo yq eval '.accessControl' $backupfile) + salt=$(sudo yq eval '.accessControl.salt' $backupfile) + # Check if the accessControl field is empty or salt is null + if [ -z "$accessControl" ] || [ "$salt" == "null" ]; then + echo "$(timestamp) $0: Warning - accessControl field is empty in $backupfile. Remove users.yaml files from to be restored file list." + DATA_TO_RESTORE=("${DATA_TO_RESTORE[@]/".octoprint/users.yaml"}") + DATA_TO_RESTORE=("${DATA_TO_RESTORE[@]/".octoprint/users-dev.yaml"}") + else + sudo cat $backupfile | sudo yq ea -i 'select(fileIndex==0) * {"accessControl":select(fileIndex==1).accessControl}' $applyfile - + fi #plugins.findmymrbeam echo "$(timestamp) $0: Restoring plugins.findmymrbeam for $configfile" - sudo cat $backupfile | sudo yq ea -i 'select(fileIndex==0) * {"plugins":{"findmymrbeam":select(fileIndex==1).plugins.findmymrbeam}}' $applyfile - + findmymrbeam=$(sudo yq eval '.plugins.findmymrbeam' $backupfile) + # Check if the findmymrbeam field is empty or null + if [ -z "$findmymrbeam" ] || [ "$findmymrbeam" == "null" ]; then + echo "$(timestamp) $0: Warning - findmymrbeam field is empty in $backupfile. Skipping." + else + sudo cat $backupfile | sudo yq ea -i 'select(fileIndex==0) * {"plugins":{"findmymrbeam":select(fileIndex==1).plugins.findmymrbeam}}' $applyfile - + fi #plugins.mrbeam.analyticsEnabled echo "$(timestamp) $0: Restoring plugins.mrbeam.analyticsEnabled for $configfile" - sudo cat $backupfile | sudo yq ea -i 'select(fileIndex==0) * {"plugins":{"mrbeam":{"analyticsEnabled":select(fileIndex==1).plugins.mrbeam.analyticsEnabled}}}' $applyfile - + analyticsEnabled=$(sudo yq eval '.plugins.mrbeam.analyticsEnabled' $backupfile) + # Check if the analyticsEnabled field is empty or null + if [ -z "$analyticsEnabled" ] || [ "$analyticsEnabled" == "null" ]; then + echo "$(timestamp) $0: Warning - analyticsEnabled field is empty in $backupfile. Skipping." + else + sudo cat $backupfile | sudo yq ea -i 'select(fileIndex==0) * {"plugins":{"mrbeam":{"analyticsEnabled":select(fileIndex==1).plugins.mrbeam.analyticsEnabled}}}' $applyfile - + fi #plugins.mrbeam.review echo "$(timestamp) $0: Restoring plugins.mrbeam.review for $configfile" - sudo cat $backupfile | sudo yq ea -i 'select(fileIndex==0) * {"plugins":{"mrbeam":{"review":select(fileIndex==1).plugins.mrbeam.review}}}' $applyfile - + review=$(sudo yq eval '.plugins.mrbeam.review' $backupfile) + # Check if the review field is empty or null + if [ -z "$review" ] || [ "$review" == "null" ]; then + echo "$(timestamp) $0: Warning - review field is empty in $backupfile. Skipping." + else + sudo cat $backupfile | sudo yq ea -i 'select(fileIndex==0) * {"plugins":{"mrbeam":{"review":select(fileIndex==1).plugins.mrbeam.review}}}' $applyfile - + fi #plugins.swupdater.attributes.migration_operator echo "$(timestamp) $0: Set plugins.swupdater.attributes.migration_operator as $migrationoperator for $configfile" From 11b5662dc5b5113b23e18640b9cbc43290344877 Mon Sep 17 00:00:00 2001 From: amrithvenkat <110397957+amrithvenkat@users.noreply.github.com> Date: Wed, 28 Feb 2024 08:06:04 +0100 Subject: [PATCH 29/35] SW-4399 define and implement a clear logging mechanism during the migration stick execution (#129) * Version bump. * Correction for bash syntax errors. * Add mount path for migrationos 3 partitions. * Add logging for Phase 2 on the USB partition. * Restore the logs on USB partition to newly flashed sd card rootfs /var/log locations. * use new parameter to mount function call. * Modify usage to reflect the new parameter. * Implement the modification on do_mount. --- .../filesystem/migration/usr/bin/migration.sh | 53 ++++++++--- .../usr/bin/migrationos_to_beamos2.sh | 88 +++++++++++++++---- 2 files changed, 113 insertions(+), 28 deletions(-) diff --git a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh index 0532b96f..f2220ec6 100755 --- a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh +++ b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh @@ -5,7 +5,7 @@ echo "Beam OS1 to Beam OS2 Migration Script" usage () { - echo "Beam OS1 to Beam OS2 Migration Script v1.4.0 " + echo "Beam OS1 to Beam OS2 Migration Script v1.5.0 " echo " " echo "OPTIONS: " echo " " @@ -17,8 +17,10 @@ usage () { echo " flash Flashes the with using . " echo " - can be \"beamos2\" or \"migrationos\". " echo " - can be \"sd-card\" or device path like \"/dev/sda\". " - echo " mount Mounts the partitions of . " + echo " mount Mounts the partitions of . " echo " - can be \"sd-card\" or device path like \"/dev/sda\". " + echo " - is the number of partitions to be mounted. " + echo " will be used in Phase 1 only. " echo " preserve-data Preserves sensitive data into USB at path \"/mnt/usb\". " echo " restore-data Restores sensitive data into SD-Card. " echo " set-status Sets the of LED in a " @@ -29,7 +31,7 @@ usage () { echo " can be one of the following: " echo " - red,blue,green,orange,(purple,teal-only in specific error cases) " echo " config-boot-usb Configures Mr Beam to be able to boot from USB. " - echo " reboot Reboot Mr Beam. " + echo " reboot Reboot Mr Beam. " } @@ -53,6 +55,7 @@ do_precondition_checks () { echo "$(timestamp) $0: SD-Card size is greater than ${MIN_SD_SIZE_IN_GB}GB. Migration can be done." else echo "$(timestamp) $0: SD-Card size must be greater than ${MIN_SD_SIZE_IN_GB}GB for Migration." + sudo cp ${LOG_FILE} ${MNT_PATH}/beamos1_to_migrationos.log exit 100 fi @@ -62,6 +65,7 @@ do_precondition_checks () { if $(dpkg --compare-versions "$mrbeam_plugin_version" "lt" $MIN_REQ_MRBEAM_PLUGIN_VERSION); then echo "$(timestamp) $0: MrBeamPlugin version - $mrbeam_plugin_version must be greater than $MIN_REQ_MRBEAM_PLUGIN_VERSION for Migration." + sudo cp ${LOG_FILE} ${MNT_PATH}/beamos1_to_migrationos.log exit 101 fi echo "$(timestamp) $0: MrBeamPlugin version is $mrbeam_plugin_version. Migration can be done." @@ -80,6 +84,7 @@ do_precondition_checks () { # Check if the file exists if [ ! -f "/etc/mrbeam" ]; then echo "$(timestamp) $0: /etc/mrbeam file not found." + sudo cp ${LOG_FILE} ${MNT_PATH}/beamos1_to_migrationos.log exit 101 fi # Read each line from the file @@ -93,6 +98,7 @@ do_precondition_checks () { # Check if the value is empty if [ -z "$value" ]; then echo "$(timestamp) $0: File /etc/mrbeam is corrupt. Empty value for key: $key" + sudo cp ${LOG_FILE} ${MNT_PATH}/beamos1_to_migrationos.log exit 101 fi fi @@ -105,6 +111,7 @@ do_precondition_checks () { # Check if there are any USB drives if [ -z "$USB_DRIVES" ]; then echo "$(timestamp) $0: No USB drives found." + sudo cp ${LOG_FILE} ${MNT_PATH}/beamos1_to_migrationos.log exit 101 fi @@ -117,6 +124,7 @@ do_precondition_checks () { echo "$(timestamp) $0: USB drive of $DEVICE_SIZE_GIGABYTES GB present." else echo "$(timestamp) $0: No USB drive of size greater than ${MIN_USB_SIZE_IN_GB}GB found." + sudo cp ${LOG_FILE} ${MNT_PATH}/beamos1_to_migrationos.log exit 101 fi @@ -131,10 +139,12 @@ do_precondition_checks () { echo "$(timestamp) $0: GPG signature verified for ${MIGRATIONOS_ENC_PATH}" else echo "$(timestamp) $0: GPG signature verification failed for ${MIGRATIONOS_ENC_PATH}" + sudo cp ${LOG_FILE} ${MNT_PATH}/beamos1_to_migrationos.log exit 101 fi else echo "$(timestamp) $0: MigrationOS encrypted file ${MIGRATIONOS_ENC_PATH} not found" + sudo cp ${LOG_FILE} ${MNT_PATH}/beamos1_to_migrationos.log exit 101 fi @@ -143,6 +153,7 @@ do_precondition_checks () { gpg --output ${MIGRATION_IMAGE_BASEDIR} --decrypt ${MIGRATIONOS_ENC_PATH} if [ $? -ne 0 ]; then echo "$(timestamp) $0: Decryption failed for ${MIGRATIONOS_ENC_PATH}" + sudo cp ${LOG_FILE} ${MNT_PATH}/beamos1_to_migrationos.log exit 102 fi echo "$(timestamp) $0: Decryption successful for ${MIGRATIONOS_ENC_PATH} to ${MIGRATION_IMAGE_BASEDIR}" @@ -199,9 +210,9 @@ do_flash () { # check status of flashing if [ $STATUS -ne 0 ]; then echo "$(timestamp) $0: Flashing Failed - $OS_TO_BE_FLASHED on $DEVICE_TO_BE_FLASHED from $CURRENT_OS_VERSION" - if [ $FLASH_COLOR_ON_FAIL_TO_FLASH="orange"]; then + if [ $FLASH_COLOR_ON_FAIL_TO_FLASH = "orange" ]; then exit 103 - elif [ $FLASH_COLOR_ON_FAIL_TO_FLASH="blue"]; then + elif [ $FLASH_COLOR_ON_FAIL_TO_FLASH = "blue" ]; then exit 104 fi fi @@ -214,6 +225,7 @@ do_flash () { do_mount () { DEVICE_TO_BE_MOUNTED="$1" + NUMPART="$2" echo "$(timestamp) $0: mount $DEVICE_TO_BE_MOUNTED" # "sd-card" or usb path like "/dev/sda" CURRENT_OS_VERSION=$(find_current_booted_os_version) @@ -233,16 +245,29 @@ do_mount () { FLASH_COLOR_ON_FAIL_TO_MOUNT="orange" elif [ "$DEVICE_TO_BE_MOUNTED" != "sd-card" ] && [ "$CURRENT_OS_VERSION" = "beamos1" ];then # Mounting the USB with migrationos - # There are 2 partitions on the USB. The first one is the boot partition and the second one is the rootfs. - DEVICE_PARTITION=${DEVICE_TO_BE_MOUNTED}2 + # There are 3 partitions on the USB. The first one is the boot partition, the second one is the rootfs, third is log partition + DEVICE_ROOTFS_PARTITION=${DEVICE_TO_BE_MOUNTED}2 + DEVICE_LOG_PARTITION=${DEVICE_TO_BE_MOUNTED}3 DEVICE_PARTITIONS=( - ${DEVICE_PARTITION} + ${DEVICE_ROOTFS_PARTITION} + ${DEVICE_LOG_PARTITION} ) MOUNT_DIRS=( ${USB_MOUNT_PATH} + ${USB_MOUNT_PATH}1 ) + + if [ ${NUMPART} -eq 1 ]; then + echo "$(timestamp) $0: Unsetting the extra partitions so that there is no severe errors." + unset DEVICE_PARTITIONS[1] + unset MOUNT_DIRS[1] + fi + # Re-index the arrays + DEVICE_PARTITIONS=("${DEVICE_PARTITIONS[@]}") + MOUNT_DIRS=("${MOUNT_DIRS[@]}") + FLASH_COLOR_ON_FAIL_TO_MOUNT="blue" else echo "$(timestamp) $0: Check inputs to the function mount" @@ -256,9 +281,9 @@ do_mount () { # Check if the mount is successful if [ $? -ne 0 ]; then echo "$(timestamp) $0: Can't mount ${DEVICE_PARTITIONS[$i]}" - if [ $FLASH_COLOR_ON_FAIL_TO_MOUNT="orange"]; then + if [ $FLASH_COLOR_ON_FAIL_TO_MOUNT = "orange" ]; then exit 103 - elif [ $FLASH_COLOR_ON_FAIL_TO_MOUNT="blue"]; then + elif [ $FLASH_COLOR_ON_FAIL_TO_MOUNT = "blue" ]; then exit 104 fi fi @@ -271,11 +296,11 @@ do_mount () { do_preserve_data () { echo "$(timestamp) $0: preserve-data $USB_MOUNT_PATH" # path like "/mnt/usb" - if [ -z "${USB_MOUNT_PATH}" ]; then + if ! grep -qs "${USB_MOUNT_PATH}" /proc/mounts; then echo "$(timestamp) $0: No suitable backup partition found. Exiting..." exit 104 fi - + echo "$(timestamp) $0: Backing up data to ${USB_MOUNT_PATH}" # Create a backup directory (if it doesn't exist) BACKUP_BASE="${USB_MOUNT_PATH}${BACKUP_PATH}" @@ -597,6 +622,7 @@ MIN_USB_SIZE_IN_GB=4 MIN_SD_SIZE_IN_GB=12 BACKUP_PATH="/mrbeam/preserve-data" SKIP_FILE_NAME="./files_to_skip_preserve_data" +LOG_FILE="/var/log/mount_manager.log" # There are 8 partitions on the SD-Card. # Root filesystems are on partition 2 and 3. @@ -680,7 +706,8 @@ while true ; do break ;; mount) - do_mount "$2" + do_mount "$2" "$3" + shift shift shift break diff --git a/src/modules/beamos/filesystem/migration/usr/bin/migrationos_to_beamos2.sh b/src/modules/beamos/filesystem/migration/usr/bin/migrationos_to_beamos2.sh index fb65e44e..1871c487 100755 --- a/src/modules/beamos/filesystem/migration/usr/bin/migrationos_to_beamos2.sh +++ b/src/modules/beamos/filesystem/migration/usr/bin/migrationos_to_beamos2.sh @@ -1,7 +1,5 @@ #!/bin/bash -BASEDIR="/usr/bin" - # This script is used to flash the Beam OS 2 to the SD-Card. # Then the Mr Beam will start to Beam OS 2. @@ -19,15 +17,27 @@ timestamp() date +"%Y-%m-%d %T" } +## functions for logging output +log() { + echo "$(date +"%Y.%m.%d %H:%M:%S") $SCRIPTNAME> $1" 2>&1 | tee -a $LOG_FILE | tee -a $2 >> /dev/null +} + +cmd() { + # tee does not complain if $2 is not set + echo "$(date +"%Y.%m.%d %H:%M:%S") $SCRIPTNAME> $1" 2>&1 | tee -a $LOG_FILE | tee -a $2 >> /dev/null + eval "$1" 2>&1 | tee -a $LOG_FILE | tee -a $2 >> /dev/null + return ${PIPESTATUS[0]} +} + do_exit() { RET_CODE="$?" - echo "$(timestamp) $0: Exitting. ${RET_CODE}" + log "$(timestamp) $0: Exitting. ${RET_CODE}" if [ "$RET_CODE" -eq 0 ]; then - echo "$0: Normal exiting." + log "$0: Normal exiting." sudo bash ${BASEDIR}/migration.sh set-status success else - echo "$0: Exiting with error code [${RET_CODE}]" + log "$0: Exiting with error code [${RET_CODE}]" sudo bash ${BASEDIR}/migration.sh set-status fail orange fi } @@ -36,6 +46,18 @@ do_exit() ############################################### # Constants ############################################### +BASEDIR="/usr/bin" +SCRIPTNAME=$(basename "$BASH_SOURCE") + +LOG_LOCATION="/mnt/usb" +LOG_FILE="${LOG_LOCATION}/migrationos_to_beamos2.log" + +SYSLOG_LOCATION="/var/log/syslog" +SYSLOG_BACKUP="${LOG_LOCATION}/migrationos_syslog.log" + +SDCARD_ROOTFS_A_PATH="/mnt/sd-card/rootfs_a" +SDCARD_ROOTFS_B_PATH="/mnt/sd-card/rootfs_b" + IMAGE_DIR="/home/pi/image" BEAMOS2_IMAGE="${IMAGE_DIR}/beamos2.wic.bz2" MAX_TIME=900 # 15 minutes in seconds @@ -49,37 +71,73 @@ PHASE_COLOR="ORANGE" # Set trap before EXIT trap do_exit EXIT +# find the right device name of partition 3 on the USB stick and mount it +echo "$(timestamp) $0: Mounting the USB stick partition 3" +USB_PART=$(lsblk -o NAME,SIZE -d -p -n | grep "/dev/sd" | awk '{print $1}') +USB_PARTITION="${USB_PART}3" +sudo mkdir -p ${LOG_LOCATION} +sudo fsck -a ${USB_PARTITION} +sudo mount ${USB_PARTITION} ${LOG_LOCATION} +exit_code=$? +if [ "$exit_code" -ne 0 ]; then + echo "$(timestamp) $0: mount ${USB_PARTITION} on ${LOG_LOCATION} failed" +fi +echo "$(timestamp) $0: Mounting the USB stick partition 3 successful" + # start progress leds current_pid=$$ -sudo bash ${BASEDIR}/progress.sh $current_pid $MAX_TIME $PHASE_COLOR & +sudo bash ${BASEDIR}/progress.sh $current_pid $MAX_TIME $PHASE_COLOR &>> $LOG_FILE & # Flash the SD-Card -echo "$(timestamp) $0: Flashing the SD-Card" -sudo bash ${BASEDIR}/migration.sh flash beamos2 sd-card +log "$(timestamp) $0: Flashing the SD-Card" +cmd 'sudo bash ${BASEDIR}/migration.sh flash beamos2 sd-card' exit_code=$? if [ "$exit_code" -ne 0 ]; then - echo "$(timestamp) $0: Flashing the SD-Card failed" + log "$(timestamp) $0: Flashing the SD-Card failed" exit 100 fi # Mount the SD-Card -echo "$(timestamp) $0: Mounting the SD-Card" -sudo bash ${BASEDIR}/migration.sh mount sd-card +log "$(timestamp) $0: Mounting the SD-Card" +cmd 'sudo bash ${BASEDIR}/migration.sh mount sd-card' exit_code=$? if [ "$exit_code" -ne 0 ]; then - echo "$(timestamp) $0: Mounting the SD-Card failed" + log "$(timestamp) $0: Mounting the SD-Card failed" exit 100 fi # Restore Sensitive Data -echo "$(timestamp) $0: Restoring Sensitive Data" -sudo bash ${BASEDIR}/migration.sh restore-data +log "$(timestamp) $0: Restoring Sensitive Data" +cmd 'sudo bash ${BASEDIR}/migration.sh restore-data' exit_code=$? if [ "$exit_code" -ne 0 ]; then - echo "$(timestamp) $0: Restoring Sensitive Data failed" + log "$(timestamp) $0: Restoring Sensitive Data failed" exit 100 fi +# Copy syslog to the USB stick +log "$(timestamp) $0: Copying syslog to the USB stick" +# Check if the file exists and rename it if it does +if [ -f ${SYSLOG_BACKUP} ]; then + cmd 'sudo mv ${SYSLOG_BACKUP} ${SYSLOG_BACKUP}.old' +fi +cmd 'sudo cp ${SYSLOG_LOCATION} ${SYSLOG_BACKUP}' +exit_code=$? +if [ "$exit_code" -ne 0 ]; then + log "$(timestamp) $0: Copy syslog to the USB stick failed" +fi +log "$(timestamp) $0: Copying syslog to the USB stick successful" + +# Copy logs on the /mnt/usb to the freshly flashed SD-Card rootfs var log partition +log "$(timestamp) $0: Copying logs to the freshly flashed SD-Card rootfs var log partition" +log "$(timestamp) $0: System will reboot after this........" +sudo cp -r ${LOG_LOCATION}/* ${SDCARD_ROOTFS_A_PATH}/var/log/ +sudo cp -r ${LOG_LOCATION}/* ${SDCARD_ROOTFS_B_PATH}/var/log/ +exit_code=$? +if [ "$exit_code" -ne 0 ]; then + echo "$(timestamp) $0: Copying logs to the freshly flashed SD-Card rootfs var log partition failed" +fi + # Reboot the device echo "$(timestamp) $0: Reboot the device" sudo bash ${BASEDIR}/migration.sh set-status success From 4bcf4daa1b8aa96c44fdc061eadc3850df4a237b Mon Sep 17 00:00:00 2001 From: amrithvenkat <110397957+amrithvenkat@users.noreply.github.com> Date: Thu, 29 Feb 2024 16:42:48 +0100 Subject: [PATCH 30/35] SW-4424 Redefine some colours on migration phase 1 (#130) * Version bump. * Change usage(). * Remove warn state for leds. * Redefine sd card error color to flash purple/red alternatively. * Introduce flash yellow/red to indicate flash to usb failure. --- .../filesystem/migration/usr/bin/migration.sh | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh index f2220ec6..0e27cd02 100755 --- a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh +++ b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh @@ -5,7 +5,7 @@ echo "Beam OS1 to Beam OS2 Migration Script" usage () { - echo "Beam OS1 to Beam OS2 Migration Script v1.5.0 " + echo "Beam OS1 to Beam OS2 Migration Script v1.5.1 " echo " " echo "OPTIONS: " echo " " @@ -27,9 +27,8 @@ usage () { echo " can be one of the following: " echo " - success " echo " - fail " - echo " - warn " echo " can be one of the following: " - echo " - red,blue,green,orange,(purple,teal-only in specific error cases) " + echo " - red,blue,green,orange,yellow,purple,teal(in specific error case) " echo " config-boot-usb Configures Mr Beam to be able to boot from USB. " echo " reboot Reboot Mr Beam. " @@ -56,7 +55,7 @@ do_precondition_checks () { else echo "$(timestamp) $0: SD-Card size must be greater than ${MIN_SD_SIZE_IN_GB}GB for Migration." sudo cp ${LOG_FILE} ${MNT_PATH}/beamos1_to_migrationos.log - exit 100 + exit 101 fi local MIN_REQ_MRBEAM_PLUGIN_VERSION="0.15.1" @@ -201,7 +200,7 @@ do_flash () { sudo umount ${DEVICE_TO_BE_FLASHED}* || true sudo dd if=${IMAGE_FILE} of=${DEVICE_TO_BE_FLASHED} bs=4M conv=fsync STATUS=$? - FLASH_COLOR_ON_FAIL_TO_FLASH="blue" + FLASH_COLOR_ON_FAIL_TO_FLASH="yellow" else echo "$(timestamp) $0: Check inputs to the function flash" exit 105 @@ -212,8 +211,8 @@ do_flash () { echo "$(timestamp) $0: Flashing Failed - $OS_TO_BE_FLASHED on $DEVICE_TO_BE_FLASHED from $CURRENT_OS_VERSION" if [ $FLASH_COLOR_ON_FAIL_TO_FLASH = "orange" ]; then exit 103 - elif [ $FLASH_COLOR_ON_FAIL_TO_FLASH = "blue" ]; then - exit 104 + elif [ $FLASH_COLOR_ON_FAIL_TO_FLASH = "yellow" ]; then + exit 106 fi fi @@ -561,9 +560,6 @@ do_set_status () { elif [ "${STATUS}" = "fail" ]; then echo "${STATUS}" set_status_fail "$COLOR" & - elif [ "${STATUS}" = "warn" ]; then - echo "${STATUS}" - set_status_warn "$COLOR" else echo "$(timestamp) $0: Unknown status [${STATUS}]" set_status_fail red & @@ -592,9 +588,7 @@ do_exit () { echo "$0: Normal exiting." else echo "$0: Exiting with error code [${RET_CODE}]" - if [ "${RET_CODE}" -eq 100 ]; then - do_set_status warn ${FLASH_PURPLE} - elif [ "${RET_CODE}" -eq 101 ]; then + if [ "${RET_CODE}" -eq 101 ]; then do_set_status fail ${FLASH_PURPLE} elif [ "${RET_CODE}" -eq 102 ]; then do_set_status fail ${FLASH_TEAL} @@ -604,6 +598,8 @@ do_exit () { do_set_status fail blue elif [ "${RET_CODE}" -eq 105 ]; then do_set_status fail red + elif [ "${RET_CODE}" -eq 106 ]; then + do_set_status fail yellow fi fi } From c9a7fedc2affb0adbd714ec794f0b74fb9bb6965 Mon Sep 17 00:00:00 2001 From: amrithvenkat <110397957+amrithvenkat@users.noreply.github.com> Date: Thu, 7 Mar 2024 13:07:34 +0100 Subject: [PATCH 31/35] SW-4450 Add precondition check for sd card free space (#131) * Precondition check for sd card free space less than 4GB * version bump --- .../filesystem/migration/usr/bin/migration.sh | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh index 0e27cd02..beee3528 100755 --- a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh +++ b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh @@ -5,7 +5,7 @@ echo "Beam OS1 to Beam OS2 Migration Script" usage () { - echo "Beam OS1 to Beam OS2 Migration Script v1.5.1 " + echo "Beam OS1 to Beam OS2 Migration Script v1.5.2 " echo " " echo "OPTIONS: " echo " " @@ -58,6 +58,19 @@ do_precondition_checks () { exit 101 fi + # Check for free available space on SD-Card 4GB + echo "$(timestamp) $0: Checking the free available space on SD-Card." + local FREE_SD_CARD_SPACE=$(df -B 1k / | awk 'NR==2 {print $4}') + SD_CARD_FREE_SPACE_GIGABYTES=$((FREE_SD_CARD_SPACE / 1024 / 1024)) + echo "$(timestamp) $0: Free space on SD-Card - ${SD_CARD_FREE_SPACE_GIGABYTES}GB found" + if [ "$FREE_SD_CARD_SPACE" -gt $((MIN_SD_FREE_SPACE_IN_GB * 1024 * 1024)) ]; then + echo "$(timestamp) $0: Free space on SD-Card is greater than ${MIN_SD_FREE_SPACE_IN_GB}GB. Migration can be done." + else + echo "$(timestamp) $0: Free space on SD-Card must be greater than ${MIN_SD_FREE_SPACE_IN_GB}GB for Migration." + sudo cp ${LOG_FILE} ${MNT_PATH}/beamos1_to_migrationos.log + exit 101 + fi + local MIN_REQ_MRBEAM_PLUGIN_VERSION="0.15.1" #Check the MrBeamPlugin version mrbeam_plugin_version=$(/home/pi/oprint/bin/pip list | grep Mr-Beam | awk '{gsub(/[()]/,""); print $2}') @@ -616,6 +629,7 @@ MIGRATION_IMAGE="${IMAGE_DIR}/migrationos.img" BEAMOS2_IMAGE="${IMAGE_DIR}/beamos2.wic.bz2" MIN_USB_SIZE_IN_GB=4 MIN_SD_SIZE_IN_GB=12 +MIN_SD_FREE_SPACE_IN_GB=4 BACKUP_PATH="/mrbeam/preserve-data" SKIP_FILE_NAME="./files_to_skip_preserve_data" LOG_FILE="/var/log/mount_manager.log" From 5aa95409ff0c99cac10eefbabd13ae958c6a40b9 Mon Sep 17 00:00:00 2001 From: amrithvenkat <110397957+amrithvenkat@users.noreply.github.com> Date: Tue, 12 Mar 2024 14:58:13 +0100 Subject: [PATCH 32/35] SW-4458 Modify state success LED colours (#132) * Version bump * add colour to success LEDs state * success state blinks alternative between stage colour and green for three times --- .../filesystem/migration/usr/bin/migration.sh | 16 ++++++++++------ .../migration/usr/bin/migrationos_to_beamos2.sh | 4 ++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh index beee3528..96bf778d 100755 --- a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh +++ b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh @@ -5,7 +5,7 @@ echo "Beam OS1 to Beam OS2 Migration Script" usage () { - echo "Beam OS1 to Beam OS2 Migration Script v1.5.2 " + echo "Beam OS1 to Beam OS2 Migration Script v1.5.3 " echo " " echo "OPTIONS: " echo " " @@ -541,10 +541,14 @@ FLASH_PURPLE="color:128:0:128" FLASH_TEAL="color:10:100:100" set_status_success() { - echo "$(timestamp) $0: status_success" - mrbeam_ledstrips_cli flash_green - sleep 1 - mrbeam_ledstrips_cli green + echo "$(timestamp) $0: status_success $1" + STAGE_COLOR="$1" + for ((i=0; i<3; i++)); do + mrbeam_ledstrips_cli flash_$STAGE_COLOR + sleep 0.5 + mrbeam_ledstrips_cli flash_green + sleep 0.5 + done } set_status_fail () { @@ -569,7 +573,7 @@ do_set_status () { echo "$(timestamp) $0: set-status ${STATUS}" if [ "${STATUS}" = "success" ]; then echo "${STATUS}" - set_status_success + set_status_success "$COLOR" elif [ "${STATUS}" = "fail" ]; then echo "${STATUS}" set_status_fail "$COLOR" & diff --git a/src/modules/beamos/filesystem/migration/usr/bin/migrationos_to_beamos2.sh b/src/modules/beamos/filesystem/migration/usr/bin/migrationos_to_beamos2.sh index 1871c487..fd0cac31 100755 --- a/src/modules/beamos/filesystem/migration/usr/bin/migrationos_to_beamos2.sh +++ b/src/modules/beamos/filesystem/migration/usr/bin/migrationos_to_beamos2.sh @@ -35,7 +35,7 @@ do_exit() log "$(timestamp) $0: Exitting. ${RET_CODE}" if [ "$RET_CODE" -eq 0 ]; then log "$0: Normal exiting." - sudo bash ${BASEDIR}/migration.sh set-status success + sudo bash ${BASEDIR}/migration.sh set-status success orange else log "$0: Exiting with error code [${RET_CODE}]" sudo bash ${BASEDIR}/migration.sh set-status fail orange @@ -140,7 +140,7 @@ fi # Reboot the device echo "$(timestamp) $0: Reboot the device" -sudo bash ${BASEDIR}/migration.sh set-status success +sudo bash ${BASEDIR}/migration.sh set-status success orange sudo bash ${BASEDIR}/migration.sh reboot exit_code=$? if [ "$exit_code" -ne 0 ]; then From 88bbf3d9914ad35ff76d9ae12f87cbbdd774f575 Mon Sep 17 00:00:00 2001 From: amrithvenkat <110397957+amrithvenkat@users.noreply.github.com> Date: Tue, 19 Mar 2024 13:18:28 +0100 Subject: [PATCH 33/35] SW-4494 create migration operator on the fly (#133) * Bump version * Use migration operator from file. --- src/modules/beamos/filesystem/migration/usr/bin/migration.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh index 96bf778d..e098c449 100755 --- a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh +++ b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh @@ -5,7 +5,7 @@ echo "Beam OS1 to Beam OS2 Migration Script" usage () { - echo "Beam OS1 to Beam OS2 Migration Script v1.5.3 " + echo "Beam OS1 to Beam OS2 Migration Script v1.5.4 " echo " " echo "OPTIONS: " echo " " @@ -412,7 +412,7 @@ do_restore_data () { configfile="/home/pi/.octoprint/config.yaml" backupfile="${backupfolder}${configfile}" applyfile="${applyfolder}${configfile}" - migrationoperator="workshop" + migrationoperator=$(sudo cat ${MIGRATION_OPERATOR_FILE}) #accessControl needed for users.yaml echo "$(timestamp) $0: Restoring accessControl for $configfile" accessControl=$(sudo yq eval '.accessControl' $backupfile) @@ -631,6 +631,7 @@ MIGRATION_IMAGE_BASEDIR=${BASEDIR}/migrationos.img IMAGE_DIR="/home/pi/image" MIGRATION_IMAGE="${IMAGE_DIR}/migrationos.img" BEAMOS2_IMAGE="${IMAGE_DIR}/beamos2.wic.bz2" +MIGRATION_OPERATOR_FILE="${IMAGE_DIR}/migrationoperator" MIN_USB_SIZE_IN_GB=4 MIN_SD_SIZE_IN_GB=12 MIN_SD_FREE_SPACE_IN_GB=4 From 44c81aa8fa892972d5c8b49769609df55689e596 Mon Sep 17 00:00:00 2001 From: amrithvenkat <110397957+amrithvenkat@users.noreply.github.com> Date: Wed, 20 Mar 2024 16:29:25 +0100 Subject: [PATCH 34/35] SW-4494 Ensure the migrationoperator file is copied (#134) * Bump version * ensure the migrationoperator file is copied --- src/modules/beamos/filesystem/migration/usr/bin/migration.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh index e098c449..dd5c1736 100755 --- a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh +++ b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh @@ -5,7 +5,7 @@ echo "Beam OS1 to Beam OS2 Migration Script" usage () { - echo "Beam OS1 to Beam OS2 Migration Script v1.5.4 " + echo "Beam OS1 to Beam OS2 Migration Script v1.5.5 " echo " " echo "OPTIONS: " echo " " @@ -356,6 +356,9 @@ do_preserve_data () { fi done + echo "$(timestamp) $0:Copying ${MIGRATION_OPERATOR_FILE} to ${USB_MOUNT_PATH}/${MIGRATION_OPERATOR_FILE}" + sudo cp ${MIGRATION_OPERATOR_FILE} ${USB_MOUNT_PATH}/${MIGRATION_OPERATOR_FILE} + echo "$(timestamp) $0: Backup process completed. Backup copies are stored in '$BACKUP_BASE'." if [ "${SKIPPED}" -gt 0 ]; then echo "$(timestamp) $0: Warning - ${SKIPPED} files were skipped - Please check syslog." From 45d5a1735d5ea5d99e68ea398c20ee0ea66ee72d Mon Sep 17 00:00:00 2001 From: amrithvenkat <110397957+amrithvenkat@users.noreply.github.com> Date: Thu, 18 Apr 2024 12:47:00 +0200 Subject: [PATCH 35/35] SW-4540 use correct command to check sd card size (#135) * grep the correct disk on the sd card --- src/modules/beamos/filesystem/migration/usr/bin/migration.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh index dd5c1736..d5601bc8 100755 --- a/src/modules/beamos/filesystem/migration/usr/bin/migration.sh +++ b/src/modules/beamos/filesystem/migration/usr/bin/migration.sh @@ -47,7 +47,7 @@ do_precondition_checks () { # Check the size of SD-Card echo "$(timestamp) $0: Checking the size of SD-Card." - local SD_CARD_SIZE=$(lsblk -b -o SIZE /dev/mmcblk0 | tail -n 1) + local SD_CARD_SIZE=$(lsblk -b -o SIZE,TYPE /dev/mmcblk0 | grep "disk" | awk '{print $1}') SD_CARD_SIZE_GIGABYTES=$((SD_CARD_SIZE / 1024 / 1024 / 1024)) echo "$(timestamp) $0: SD-Card size - ${SD_CARD_SIZE_GIGABYTES}GB found" if [ "$SD_CARD_SIZE" -gt $((MIN_SD_SIZE_IN_GB * 1024 * 1024 * 1024)) ]; then