From f2d34284881a27021f43af0cda7ce715f867fe76 Mon Sep 17 00:00:00 2001 From: paukstelis Date: Sun, 23 Oct 2022 09:15:02 -0400 Subject: [PATCH] sync user function --- README.md | 7 +++-- octoprint_deploy.sh | 64 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 59 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 29aeb1b..a5c9448 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -Updated October 21, 2022. +Updated October 23, 2022. Want to support this work? Buy Me a Coffee. https://www.buymeacoffee.com/ppaukstelis. Need help with octoprint_deploy? Ask on Discord: https://discord.gg/6vgSjgvR6u # octoprint_deploy @@ -58,15 +58,14 @@ These files provide a bash script for quickly deploying multiple octoprint insta * Change udev rules for an instance with `sudo octoprint_deploy/octoprint_deploy.sh replace` * Always a good idea to update octoprint_deploy from time-to-time with `git -C octoprint_deploy pull` # Recent Changes +* Added `Sync Users` option. It will copy users.yaml file from selected instances to all other instances (including template) +* Starting with 0.1.4, added `Update` in the menu which will update octoprint_deploy via git (then exit) * Rename printers_udev.sh to udev_rules.sh. Allows writing udev rules for both printers and cameras without full deployment. * 0.1.3, printer and camera detection now done with dmesg instead of journalctl. This allows faster timeouts when a device is detected by the USB port but it does not have a serial number. * Fail if sudouser is root. * Add MIT license * Write /etc/octoprint_deploy if missing (older version system preparation) * Add option for plugin installation during system preparation. -* Enable ssh. -* Added webcam restart to system commands during camera addition. -* Admin user and first run wizards during Prepare System. # TODO * Multiple cameras for an instance (see multi-camera branch) diff --git a/octoprint_deploy.sh b/octoprint_deploy.sh index 55552bd..7ca8b01 100755 --- a/octoprint_deploy.sh +++ b/octoprint_deploy.sh @@ -468,7 +468,7 @@ detect_printer() { dmesg -C echo "Plug your printer in via USB now (detection time-out in 1 min)" counter=0 - while [[ -z "$UDEV" ]] && [[ $counter -lt 60 ]]; do + while [[ -z "$UDEV" ]] && [[ $counter -lt 60 ]]; do TEMPUSB=$(dmesg | sed -n -e 's/^.*\(cdc_acm\|ftdi_sio\|ch341\|cp210x\) \([0-9].*[0-9]\): \(tty.*\|FTD.*\|ch341-uart.*\|cp210x\).*/\2/p') UDEV=$(dmesg | sed -n -e 's/^.*SerialNumber: //p') counter=$(( $counter + 1 )) @@ -675,7 +675,7 @@ prepare () { echo 'Disabling unneeded services....' systemctl disable octoprint.service systemctl disable webcamd.service - systemctl stop webcamd.service + systemctl stop webcamd.service systemctl disable streamer_select.service systemctl stop streamer_select.service echo 'Installing needed packages' @@ -1014,6 +1014,41 @@ restart_all() { exit 0 } +sync_users() { + PS3='Select instance that contains current user list: ' + readarray -t options < <(cat /etc/octoprint_instances | sed -n -e 's/^instance:\([[:graph:]]*\) .*/\1/p') + options+=("Quit") + select opt in "${options[@]}" + do + if [ "$opt" == Quit ]; then + main_menu + fi + + if prompt_confirm "Copy users from instance $opt to all other instances?"; then + if [ "$opt" == generic ]; then + userfile=/home/$user/.octoprint/users.yaml + else + userfile=/home/$user/.$opt/users.yaml + fi + #re-read to avoid the Quit + readarray -t instances < <(cat /etc/octoprint_instances | sed -n -e 's/^instance:\([[:graph:]]*\) .*/\1/p') + for instance in "${instances[@]}"; do + if [ "$instance" == generic ]; then + sudo -u $user cp $userfile /home/$user/.octoprint/ + else + sudo -u $user cp $userfile /home/$user/.$instance/ + fi + done + + if prompt_confirm "Restart all instances now for changes to take effect?"; then + restart_all + fi + fi + + main_menu + done +} + back_up() { INSTANCE=$1 echo "Creating backup of $INSTANCE...." @@ -1091,8 +1126,13 @@ replace_id() { done } +octo_deploy_update() { + sudo -u $user git -C octoprint_deploy pull + exit +} + main_menu() { - VERSION=0.1.3 + VERSION=0.1.5 #reset UDEV='' TEMPUSB='' @@ -1108,9 +1148,9 @@ main_menu() { echo PS3='Select operation: ' if [ -f "/etc/octoprint_instances" ]; then - options=("New instance" "Delete instance" "Add Camera" "USB port testing" "Create Backup" "Restore Backup" "Quit") + options=("New instance" "Delete instance" "Add Camera" "USB port testing" "Sync Users" "Create Backup" "Restore Backup" "Update" "Quit") else - options=("Prepare system" "USB port testing" "Quit") + options=("Prepare system" "USB port testing" "Update" "Quit") fi select opt in "${options[@]}" @@ -1135,6 +1175,10 @@ main_menu() { usb_testing break ;; + "Sync Users") + sync_users + break + ;; "Create Backup") create_menu break @@ -1143,6 +1187,10 @@ main_menu() { restore_menu break ;; + "Update") + octo_deploy_update + break + ;; "Quit") exit 1 ;; @@ -1157,7 +1205,7 @@ source $SCRIPTDIR/plugins.sh # gather info and write /etc/octoprint_deploy if missing if [ ! -f /etc/octoprint_deploy ] && [ -f /etc/octoprint_instances ]; then echo "/etc/octoprint_deploy is missing. You may have prepared the system with an older vesion." - echo "The file will be created now." + echo "The file will be created now." streamer_type=("mjpg-streamer" "ustreamer") haproxy_bool=("true" "false") if [ -f /etc/octopi_version ]; then @@ -1176,8 +1224,8 @@ if [ ! -f /etc/octoprint_deploy ] && [ -f /etc/octoprint_instances ]; then echo "haproxy: $prox" >> /etc/octoprint_deploy break done - -fi + +fi #command line arguments if [ "$1" == remove ]; then