From d1f6a29b59f2f4e50256954432c69b438e85a9bb Mon Sep 17 00:00:00 2001 From: David Barbion Date: Tue, 1 Feb 2022 09:08:30 +0100 Subject: [PATCH] feat: add 2 new linux scripts * mountOverlay.sh allows mounting a SD card or usb key with overlay * diffConfig.sh show changes in defconfig even if order of items changed --- scripts/linux/diffConfig.sh | 62 +++++++++++++++++++++++++++++++++++ scripts/linux/mountOverlay.sh | 26 +++++++++++++++ 2 files changed, 88 insertions(+) create mode 100755 scripts/linux/diffConfig.sh create mode 100755 scripts/linux/mountOverlay.sh diff --git a/scripts/linux/diffConfig.sh b/scripts/linux/diffConfig.sh new file mode 100755 index 0000000000..48ff4388db --- /dev/null +++ b/scripts/linux/diffConfig.sh @@ -0,0 +1,62 @@ +#!/bin/bash + +SHOW_FULL=false +if [ "$2" = "-f" ]; then + SHOW_FULL=true +fi + +mapfile -t ADDED < <(git diff "$1" |grep -E '^(\+)[^+]' | sed 's/^.//') +mapfile -t REMOVED < <(git diff "$1" |grep -E '^(\-)[^-]' | sed 's/^.//') + +is_removed() { + local to_check="$1" + for x in "${REMOVED[@]}"; do + [ "$to_check" = "$x" ] && return 0 + done + return 1 +} + +is_added() { + local to_check="$1" + for x in "${ADDED[@]}"; do + [ "$to_check" = "$x" ] && return 0 + done + return 1 +} + +total_added=() +total_removed=() +total_changed=() + +for i in "${ADDED[@]}"; do + if is_added "$i" && ! is_removed "$i" ; then + total_added+=("$i") + fi +done +for i in "${REMOVED[@]}"; do + if ! is_added "$i" && is_removed "$i"; then + total_removed+=("$i") + fi +done +for i in "${ADDED[@]}"; do + if is_added "$i" && is_removed "$i"; then + total_changed+=("$i") + fi +done + +if [ ${#total_added[*]} -gt 0 ]; then + echo "+++ added:" + printf '\e[32m%s\e[0m\n' "${total_added[@]}" +fi + +if [ ${#total_removed[*]} -gt 0 ]; then + echo "--- removed:" + printf '\e[31m%s\e[0m\n' "${total_removed[@]}" +fi + +if [ $SHOW_FULL = true ] && [ ${#total_changed[*]} -gt 0 ]; then + echo "ยงยงยง Postition changed:" + printf '\e[33m%s\e[0m\n' "${total_changed[@]}" +fi + + diff --git a/scripts/linux/mountOverlay.sh b/scripts/linux/mountOverlay.sh new file mode 100755 index 0000000000..3083a91bd3 --- /dev/null +++ b/scripts/linux/mountOverlay.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +if [ -z "$1" ]; then + echo "missing device" >&2 + echo "please specify sdcard (/dev/mmcblk0) of usb key (/dev/sdb)" >&2 + exit 1 +fi + +DEVICE="$1" +if [[ "$DEVICE" =~ mmcblk ]]; then + BOOTDEVICE="${DEVICE}p1" +else + BOOTDEVICE="${DEVICE}1" +fi + + +mkdir -p /tmp/recalbox/lower /tmp/recalbox/upper /tmp/recalbox/work /tmp/recalbox/boot /tmp/recalbox/root +sudo mount "$BOOTDEVICE" /tmp/recalbox/boot || exit 1 +sudo mount /tmp/recalbox/boot/boot/recalbox /tmp/recalbox/lower || exit 1 +sudo mount -t overlay overlay -o rw,lowerdir=/tmp/recalbox/lower,upperdir=/tmp/recalbox/upper,workdir=/tmp/recalbox/work /tmp/recalbox/root || exit 1 + +echo "root file system is accessible from /tmp/recalbox/root" +echo "once finished:" +echo "umount /tmp/recalbox/root" +echo "umount /tmp/recalbox/lower" +echo "umount /tmp/recalbox/boot" -- GitLab