-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit-printer.sh
More file actions
47 lines (35 loc) · 1.65 KB
/
init-printer.sh
File metadata and controls
47 lines (35 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
# Set up given clerk printer
# Usage: ./init_printer.sh [printer_ip]
USERNAME="root"
REMOTE_IP="$1"
SERIAL="$2"
if [ -z "$REMOTE_IP" ]; then
echo "Usage: $0 [printer_ip]"
exit 1
fi
echo "Setting up clerk printer at $REMOTE_IP..."
# Ping the printer to check if it's reachable
ping -c 1 "$REMOTE_IP" > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Error: Printer at $REMOTE_IP is not reachable."
exit 1
fi
# Get the directory where the script is located
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# # Mount the root filesystem as read-write
ssh "$USERNAME@$REMOTE_IP" "mount -o remount, rw /"
ssh "$USERNAME@$REMOTE_IP" "mount -o remount, rw /calibration"
ssh "$USERNAME@$REMOTE_IP" "touch /data/.firstboot"
# Copy the clerk files to the printer
BACKUP_SUFFIX=".bak$(date +%Y%m%d_%H%M%S)"
# Sync share data
rsync -azvP --update --backup "--suffix=$BACKUP_SUFFIX" "$SCRIPT_DIR/share/data" root@"$REMOTE_IP:/"
rsync -azvP --update --backup "--suffix=$BACKUP_SUFFIX" "$SCRIPT_DIR/share/usr" root@"$REMOTE_IP:/"
# Sync unique data
rsync -azvP --update --backup "--suffix=$BACKUP_SUFFIX" "$SCRIPT_DIR/${SERIAL}/data" root@"$REMOTE_IP:/"
# rsync -azvP --update --backup "--suffix=$BACKUP_SUFFIX" "$SCRIPT_DIR/etc" root@"$REMOTE_IP:/"
rsync -azvP --update --backup "--suffix=$BACKUP_SUFFIX" "$SCRIPT_DIR/${SERIAL}/calibration" root@"$REMOTE_IP:/"
# rsync -azvP --update --backup "--suffix=$BACKUP_SUFFIX" "$SCRIPT_DIR/usr" root@"$REMOTE_IP:/"
# rsync -azvP --update --backup "--suffix=$BACKUP_SUFFIX" "$SCRIPT_DIR/lib" root@"$REMOTE_IP:/"
ssh "$USERNAME@$REMOTE_IP" "sudo reboot"