This commit is contained in:
MangoPig 2025-12-03 14:40:48 +00:00
parent 044ffd46a1
commit 367b92b596
3 changed files with 50 additions and 34 deletions

View File

@ -12,7 +12,7 @@ setup:
# Just stow the dotfiles # Just stow the dotfiles
stow: stow:
stow . --target=$$HOME --ignore="setup.sh" --ignore=".git" --ignore=".gitignore" --ignore="README.md" --ignore=".zsh_secrets" --ignore=".zsh_secrets.example" --ignore="LICENSE" --ignore="Makefile" --ignore="provision.sh" --ignore="rclone.sh" stow . --target=$$HOME --ignore="setup.sh" --ignore=".git" --ignore=".gitignore" --ignore="README.md" --ignore=".zsh_secrets" --ignore=".zsh_secrets.example" --ignore="LICENSE" --ignore="Makefile" --ignore="provision.sh" --ignore="storagebox.sh"
@echo "Dotfiles linked." @echo "Dotfiles linked."
# Clean old files and links # Clean old files and links
@ -25,8 +25,8 @@ update:
git pull origin main git pull origin main
make setup make setup
# rclone setup # Setup StorageBox
rclone-setup: storagebox:
bash rclone.sh bash rclone.sh
# Docker Tests # Docker Tests

View File

@ -220,7 +220,7 @@ touch "$HOME/.zsh_secrets"
# Stow Dotfiles # Stow Dotfiles
echo -e "${BLUE} LOG:${YELLOW} Stowing dotfiles...${NC}" echo -e "${BLUE} LOG:${YELLOW} Stowing dotfiles...${NC}"
cd "$DOTFILES_DIR" cd "$DOTFILES_DIR"
stow . --target="$HOME" --ignore="setup.sh" --ignore=".git" --ignore=".gitignore" --ignore="README.md" --ignore=".zsh_secrets" --ignore=".zsh_secrets.example" --ignore="LICENSE" --ignore="Makefile" --ignore="provision.sh" --ignore="rclone.sh" stow . --target="$HOME" --ignore="setup.sh" --ignore=".git" --ignore=".gitignore" --ignore="README.md" --ignore=".zsh_secrets" --ignore=".zsh_secrets.example" --ignore="LICENSE" --ignore="Makefile" --ignore="provision.sh" --ignore="storagebox.sh"
# Language Setup # Language Setup
echo -e "${BLUE} LOG:${YELLOW} Finalizing Language Setup...${NC}" echo -e "${BLUE} LOG:${YELLOW} Finalizing Language Setup...${NC}"

View File

@ -11,39 +11,40 @@ NC='\033[0m'
SECRETS_FILE="$HOME/.zsh_secrets" SECRETS_FILE="$HOME/.zsh_secrets"
REMOTE_NAME="hetzner-box" REMOTE_NAME="hetzner-box"
# 1. Dependency Check # Dependency Check
if ! command -v rclone &> /dev/null; then if ! command -v rclone &> /dev/null; then
echo -e "${RED}Error: rclone is not installed.${NC}" echo -e "${RED}Error: rclone is not installed.${NC}"
echo "Run: sudo pacman -S rclone (Arch) or sudo apt install rclone (Ubuntu)"
exit 1 exit 1
fi fi
# 2. Load Secrets # Load Secrets
if [ -f "$SECRETS_FILE" ]; then if [ -f "$SECRETS_FILE" ]; then
source "$SECRETS_FILE" source "$SECRETS_FILE"
fi fi
# 3. Configure Remote (If missing) # Configure Remote (If missing)
if ! rclone listremotes | grep -q "^${REMOTE_NAME}:$"; then if ! rclone listremotes | grep -q "^${REMOTE_NAME}:$"; then
echo -e "${BLUE}Configuration missing. Starting setup...${NC}" echo -e "${BLUE}Configuration missing. Starting setup...${NC}"
# Prompt if variables are missing
if [ -z "$HETZNER_USER" ]; then if [ -z "$HETZNER_USER" ]; then
HETZNER_USER="u513875" DEFAULT_USER="u513875"
read -p "Enter Storage Box Username (u123456): " HETZNER_USER read -p "Enter Username [$DEFAULT_USER]: " INPUT_USER
HETZNER_USER="${INPUT_USER:-$DEFAULT_USER}"
fi fi
if [ -z "$HETZNER_HOST" ]; then if [ -z "$HETZNER_HOST" ]; then
HETZNER_HOST="u513875.your-storagebox.de" DEFAULT_HOST="${HETZNER_USER}.your-storagebox.de"
read -p "Enter Storage Box Host (u513875.your-storagebox.de): " HETZNER_HOST read -p "Enter Host [$DEFAULT_HOST]: " INPUT_HOST
HETZNER_HOST="${INPUT_HOST:-$DEFAULT_HOST}"
fi fi
if [ -z "$HETZNER_PASS" ]; then if [ -z "$HETZNER_PASS" ]; then
HETZNER_PASS=""
echo -e "${YELLOW}Note: Passwords are obscured in config, but saving to secrets file uses plain text.${NC}" echo -e "${YELLOW}Note: Passwords are obscured in config, but saving to secrets file uses plain text.${NC}"
read -s -p "Enter Storage Box Password: " HETZNER_PASS read -s -p "Enter Password: " HETZNER_PASS
echo "" echo ""
fi fi
# Save to secrets for future use # Save to secrets
if ! grep -q "HETZNER_USER" "$SECRETS_FILE" 2>/dev/null; then if ! grep -q "HETZNER_USER" "$SECRETS_FILE" 2>/dev/null; then
echo -e "${BLUE}Saving credentials to $SECRETS_FILE...${NC}" echo -e "${BLUE}Saving credentials to $SECRETS_FILE...${NC}"
{ {
@ -55,7 +56,6 @@ if ! rclone listremotes | grep -q "^${REMOTE_NAME}:$"; then
} >> "$SECRETS_FILE" } >> "$SECRETS_FILE"
fi fi
# Create Rclone Config (Obscure password first)
OBSCURED_PASS=$(rclone obscure "$HETZNER_PASS") OBSCURED_PASS=$(rclone obscure "$HETZNER_PASS")
rclone config create "$REMOTE_NAME" sftp \ rclone config create "$REMOTE_NAME" sftp \
host "$HETZNER_HOST" \ host "$HETZNER_HOST" \
@ -67,47 +67,63 @@ if ! rclone listremotes | grep -q "^${REMOTE_NAME}:$"; then
echo -e "${GREEN}Configuration created!${NC}" echo -e "${GREEN}Configuration created!${NC}"
fi fi
# 4. Interactive Menu # Interactive Menu
echo -e "${BLUE}--- Hetzner Storage Box Manager ---${NC}" echo -e "${BLUE}--- Hetzner Storage Box Manager ---${NC}"
echo "1) List files (ls)" echo "1) List files (ls)"
echo "2) Upload (Copy LOCAL -> REMOTE)" echo "2) Upload (Copy LOCAL -> REMOTE)"
echo "3) Download (Copy REMOTE -> LOCAL)" echo "3) Download (Copy REMOTE -> LOCAL)"
echo "4) Mount (Browse files)" echo "4) Mount (Fast NVMe Cache)"
echo "q) Quit" echo "q) Quit"
read -p "Select option: " OPTION read -p "Select option: " OPTION
case $OPTION in case $OPTION in
1) 1)
DEFAULT_DEPTH=2 read -p "Enter depth [2]: " INPUT_DEPTH
echo -e "${YELLOW}Listing files...${NC}" DEPTH="${INPUT_DEPTH:-2}"
read -p "Enter depth (default $DEFAULT_DEPTH): " DEFAULT_DEPTH rclone ls "${REMOTE_NAME}:" --max-depth "$DEPTH"
rclone ls "${REMOTE_NAME}:" --max-depth "$DEFAULT_DEPTH"
;; ;;
2) 2)
read -p "Enter local folder to upload from (e.g., $HOME/Documents): " LOCAL_FOLDER read -p "Enter local folder to upload: " LOCAL_FOLDER
LOCAL_FOLDER=${LOCAL_FOLDER%/} LOCAL_FOLDER=${LOCAL_FOLDER%/}
read -p "Enter remote folder name (e.g. Backup): " REMOTE_FOLDER
read -p "Enter remote folder name on Hetzner (e.g. Backup): " REMOTE_FOLDER
echo -e "${YELLOW}Uploading (Copying)...${NC}" echo -e "${YELLOW}Uploading (Copying)...${NC}"
rclone copy "$LOCAL_FOLDER" "${REMOTE_NAME}:/${REMOTE_FOLDER}" -P rclone copy "$LOCAL_FOLDER" "${REMOTE_NAME}:/${REMOTE_FOLDER}" -P
;; ;;
3) 3)
read -p "Enter remote folder on Hetzner to download (e.g. Backup): " REMOTE_FOLDER read -p "Enter remote folder to download: " REMOTE_FOLDER
read -p "Enter local destination folder: " LOCAL_FOLDER read -p "Enter local destination: " LOCAL_FOLDER
echo -e "${YELLOW}Downloading (Copying)...${NC}" echo -e "${YELLOW}Downloading (Copying)...${NC}"
rclone copy "${REMOTE_NAME}:/${REMOTE_FOLDER}" "$LOCAL_FOLDER" -P rclone copy "${REMOTE_NAME}:/${REMOTE_FOLDER}" "$LOCAL_FOLDER" -P
;; ;;
4) 4)
MOUNT_POINT="/mnt/resources/storagebox" if [ -d "/mnt/resource" ]; then
BASE_DIR="/mnt/resource"
else
BASE_DIR="/mnt"
fi
MOUNT_POINT="$BASE_DIR/storagebox"
CACHE_DIR="$BASE_DIR/rclone_cache"
mkdir -p "$MOUNT_POINT" echo -e "${BLUE}Target: $MOUNT_POINT${NC}"
echo -e "${YELLOW}Mounting to $MOUNT_POINT... (Ctrl+C to stop)${NC}" echo -e "${BLUE}Cache: $CACHE_DIR${NC}"
rclone mount "${REMOTE_NAME}:" "$MOUNT_POINT" --vfs-cache-mode writes
if [ ! -d "$MOUNT_POINT" ] || [ ! -w "$MOUNT_POINT" ]; then
echo -e "${YELLOW}Setting up permissions for $BASE_DIR... (sudo required)${NC}"
sudo mkdir -p "$MOUNT_POINT" "$CACHE_DIR"
sudo chown $(whoami):$(id -gn) "$MOUNT_POINT" "$CACHE_DIR"
fi
echo -e "${YELLOW}Mounting... (Ctrl+C to stop)${NC}"
rclone mount "${REMOTE_NAME}:" "$MOUNT_POINT" \
--vfs-cache-mode full \
--cache-dir "$CACHE_DIR" \
--vfs-cache-max-size 10G \
--vfs-cache-max-age 24h
;; ;;
q) q)
exit 0 exit 0