feat: add Ubuntu server setup script

- Creates /data/jingtian/BenjaminTeam directory structure
- Creates dedicated rclone-sync user for SFTP access
- Generates ed25519 SSH key pair for Windows clients
- Installs rclone on the server
- Outputs private key for embedding in Windows setup
This commit is contained in:
2026-02-13 09:44:34 +00:00
parent 83c45e1e97
commit 7c671569b4

140
ubuntu/setup.sh Normal file
View File

@@ -0,0 +1,140 @@
#!/bin/bash
#
# JingTian rclone Server Setup Script
# Run this on the Ubuntu VM that will receive synced files
#
# Usage: sudo bash setup.sh
#
set -e
# Configuration
DATA_DIR="/data/jingtian/BenjaminTeam"
RCLONE_USER="rclone-sync"
SSH_KEY_NAME="jingtian_rclone"
SSH_KEY_DIR="/home/$RCLONE_USER/.ssh"
echo "=========================================="
echo "JingTian rclone Server Setup"
echo "=========================================="
# Check if running as root
if [ "$EUID" -ne 0 ]; then
echo "Please run as root (sudo bash setup.sh)"
exit 1
fi
# Step 1: Create data directory
echo ""
echo "[1/5] Creating data directory..."
mkdir -p "$DATA_DIR"
mkdir -p "$DATA_DIR/_LLM_Sync"
# Create the same folder structure as client
mkdir -p "$DATA_DIR/Admin/E-Signature"
mkdir -p "$DATA_DIR/Admin/General Matter"
mkdir -p "$DATA_DIR/Admin/IPD e-filing"
mkdir -p "$DATA_DIR/Admin/JT Logo"
mkdir -p "$DATA_DIR/Admin/Letterhead"
mkdir -p "$DATA_DIR/Admin/Matter Open"
mkdir -p "$DATA_DIR/Admin/Template"
mkdir -p "$DATA_DIR/BD&M/2025 GCP"
mkdir -p "$DATA_DIR/BD&M/HKPC"
mkdir -p "$DATA_DIR/BD&M/WKCDA WKProcure"
mkdir -p "$DATA_DIR/Billing/Draft Bills"
mkdir -p "$DATA_DIR/Billing/Invoice Templates"
mkdir -p "$DATA_DIR/Billing/Issued Bills"
mkdir -p "$DATA_DIR/Client"
mkdir -p "$DATA_DIR/Free Schedules/Price List"
mkdir -p "$DATA_DIR/Free Schedules/Emails"
mkdir -p "$DATA_DIR/IP"
mkdir -p "$DATA_DIR/Precedent"
echo " Created: $DATA_DIR"
# Step 2: Create dedicated user for rclone sync
echo ""
echo "[2/5] Creating dedicated sync user: $RCLONE_USER..."
if id "$RCLONE_USER" &>/dev/null; then
echo " User $RCLONE_USER already exists, skipping..."
else
useradd -m -s /bin/bash "$RCLONE_USER"
echo " Created user: $RCLONE_USER"
fi
# Set ownership of data directory
chown -R "$RCLONE_USER:$RCLONE_USER" "$DATA_DIR"
chmod -R 755 "$DATA_DIR"
echo " Set ownership of $DATA_DIR to $RCLONE_USER"
# Step 3: Generate SSH key pair for rclone
echo ""
echo "[3/5] Generating SSH key pair..."
mkdir -p "$SSH_KEY_DIR"
chown "$RCLONE_USER:$RCLONE_USER" "$SSH_KEY_DIR"
chmod 700 "$SSH_KEY_DIR"
SSH_KEY_PATH="$SSH_KEY_DIR/$SSH_KEY_NAME"
if [ -f "$SSH_KEY_PATH" ]; then
echo " SSH key already exists at $SSH_KEY_PATH"
echo " To regenerate, delete the key and run this script again"
else
ssh-keygen -t ed25519 -f "$SSH_KEY_PATH" -N "" -C "jingtian-rclone-sync"
chown "$RCLONE_USER:$RCLONE_USER" "$SSH_KEY_PATH" "$SSH_KEY_PATH.pub"
chmod 600 "$SSH_KEY_PATH"
chmod 644 "$SSH_KEY_PATH.pub"
echo " Generated: $SSH_KEY_PATH"
fi
# Step 4: Add public key to authorized_keys
echo ""
echo "[4/5] Configuring SSH authorized_keys..."
AUTHORIZED_KEYS="$SSH_KEY_DIR/authorized_keys"
PUBLIC_KEY=$(cat "$SSH_KEY_PATH.pub")
if [ -f "$AUTHORIZED_KEYS" ] && grep -q "jingtian-rclone-sync" "$AUTHORIZED_KEYS"; then
echo " Public key already in authorized_keys"
else
echo "$PUBLIC_KEY" >> "$AUTHORIZED_KEYS"
chown "$RCLONE_USER:$RCLONE_USER" "$AUTHORIZED_KEYS"
chmod 600 "$AUTHORIZED_KEYS"
echo " Added public key to authorized_keys"
fi
# Step 5: Install rclone (optional on server, but useful for debugging)
echo ""
echo "[5/5] Installing rclone..."
if command -v rclone &> /dev/null; then
echo " rclone already installed: $(rclone version | head -1)"
else
curl -s https://rclone.org/install.sh | bash
echo " Installed: $(rclone version | head -1)"
fi
# Print summary
echo ""
echo "=========================================="
echo "Setup Complete!"
echo "=========================================="
echo ""
echo "Data directory: $DATA_DIR"
echo "Sync user: $RCLONE_USER"
echo "SSH key location: $SSH_KEY_PATH"
echo ""
echo "=========================================="
echo "IMPORTANT: Copy the private key below"
echo "=========================================="
echo ""
echo "--- BEGIN PRIVATE KEY ---"
cat "$SSH_KEY_PATH"
echo ""
echo "--- END PRIVATE KEY ---"
echo ""
echo "Save this key to: windows/rclone-key"
echo "It will be used by Windows clients to connect."
echo ""
echo "Connection details for Windows rclone config:"
echo " Host: $(hostname -I | awk '{print $1}')"
echo " User: $RCLONE_USER"
echo " Path: $DATA_DIR"
echo ""