Bryan Roessler 8 mesiacov pred
rodič
commit
7d304d743f
3 zmenil súbory, kde vykonal 113 pridanie a 0 odobranie
  1. 26 0
      shell/btrbkwrap
  2. 38 0
      shell/chroot-rescue
  3. 49 0
      shell/tmux-management

+ 26 - 0
shell/btrbkwrap

@@ -0,0 +1,26 @@
+#!/usr/bin/env bash
+# Copyright 2023 Bryan C. Roessler
+#
+# btrbk wrapper to return latest target subvolume
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+#     http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+(( EUID > 0 )) && echo "Please run as root." && exit 1
+
+target="$1" # router.lan:/mnt/backup/media/music
+
+shift
+
+btrbk --dry-run "$@" &&
+btrbk list latest --format=col:h:TARGET_HOST,TARGET_SUBVOLUME "$target"

+ 38 - 0
shell/chroot-rescue

@@ -0,0 +1,38 @@
+#!/usr/bin/env bash
+# This script will mount and chroot a linux system
+# Copyright 2024 Bryan C. Roessler
+
+lsblk
+
+# Set defaults
+RP=${ROOT_PART:-/dev/nvme0n0p3}
+BP=${BOOT_PART:-/dev/nvme0n0p1}
+
+echo "Press enter to accept default value"
+read -r -p "Root partition [$RP]: " RP
+read -r -p "Boot partition [$BP]: " BP
+MD="${MOUNT_DIR:-/mnt/${RP##*/}}"
+[[ -d $MD ]] && MD=$MD-$RANDOM
+read -r -p "Mount directory [$MD]: " MD
+
+[[ -e $RP && -e $BP ]] || exit 1
+
+# Mount and entire the chroot
+echo "Mounting and entering chroot"
+sudo mkdir -p "$MD" &&
+sudo mount "$RP" "$MD" &&
+for i in proc sys dev; do
+  sudo mount --bind /$i "$MD/$i"
+done &&
+sudo mount "$BP" "$MD/boot/efi" &&
+sudo chroot "$MD";
+
+# After chroot
+echo "Exiting and unmounting chroot"
+sudo umount "$MD/boot/efi"
+for i in proc sys dev; do
+  sudo umount "$MD/$i"
+done 
+sudo umount "$MD"
+
+exit $?

+ 49 - 0
shell/tmux-management

@@ -0,0 +1,49 @@
+#!/usr/bin/env bash
+# This script launches a multi-pane tmux session for multiple remotes
+# TODO make remote sessions run in tmux too
+# Copyright 2024 Bryan C. Roessler
+
+# Use DEBUG=1 ./tmux-management to enable debugging
+DEBUG=${DEBUG:-0}
+
+debug() { (( DEBUG )) && echo "Debug: $*"; }
+
+HOSTS=(
+  workstation
+  laptop
+  #hartmanlab
+)
+
+debug "Hosts list: ${HOSTS[*]}"
+
+# Remove localhost from HOSTS list
+TARGETS=()
+for HOST in "${HOSTS[@]}"; do
+    if [[ "$HOST" != "$HOSTNAME" ]]; then
+        TARGETS+=("$HOST")
+    fi
+done
+unset HOST
+
+# Create a unique session name from the remaining hosts
+SESSION=$(IFS=- ; echo "${TARGETS[*]}")
+
+debug "Targets: ${TARGETS[*]}"
+debug "Session: $SESSION"
+
+# Connect to existing session
+if tmux has-session -t "$SESSION" &> /dev/null; then
+  tmux attach -t "$SESSION";
+else # create new tmux session
+  tmux new-session -d -s "$SESSION" -n "$SESSION";
+  # Create a new pane for each TARGET
+  for TARGET in "${TARGETS[@]}"; do
+    tmux split-window -h;
+    tmux send "ssh $TARGET" enter;
+  done
+  tmux set-window-option synchronize-panes on;
+  tmux select-pane -t "$SESSION:0.0"
+  tmux send 'clear' enter;
+  tmux attach-session -t "$SESSION"
+fi
+unset TARGET