Files
nextcloud-integration/build.sh
T
WLTBAgent 801d5cf0aa Complete rewrite of build.sh credential prompts
Removed confusing headers and simplified logic:
- IMAP credentials are now REQUIRED (no defaults)
- SMTP credentials use IMAP defaults if not specified separately
- IMAP validation applies to both sets
- Clearer prompts without confusing default messages

This should fix empty credential issues by requiring IMAP
credentials to be explicitly entered.
2026-02-23 23:59:10 +00:00

133 lines
3.8 KiB
Bash
Executable File

#!/bin/bash
# Build Nextcloud CLI tools with compile-time credentials
# Usage: ./build.sh <server-url> <username> <token>
set -e
# Check arguments
if [ $# -ne 3 ]; then
echo "Usage: $0 <server-url> <username> <token>"
exit 1
fi
SERVER_URL="$1"
USERNAME="$2"
TOKEN="$3"
echo ""
echo "Building Nextcloud CLI tools with credentials..."
echo " Server: $SERVER_URL"
echo " Username: $USERNAME"
echo " Token: ${TOKEN:0:10}..."
echo ""
# Prompt for email credentials
read -p "IMAP Server hostname: " IMAP_SERVER
if [ -z "$IMAP_SERVER" ]; then
echo "❌ Error: IMAP server cannot be empty"
exit 1
fi
read -p "IMAP Port (default: 993): " IMAP_PORT
IMAP_PORT=${IMAP_PORT:-993}
read -p "IMAP Username: " IMAP_USER
if [ -z "$IMAP_USER" ]; then
echo "❌ Error: IMAP username cannot be empty"
exit 1
fi
read -sp "IMAP Password: " IMAP_PASS
if [ -z "$IMAP_PASS" ]; then
echo "❌ Error: IMAP password cannot be empty"
exit 1
fi
read -p "SMTP Server hostname: " SMTP_SERVER
SMTP_SERVER=${SMTP_SERVER:-teamworkapps.com}
read -p "SMTP Port (default: 465): " SMTP_PORT
SMTP_PORT=${SMTP_PORT:-465}
read -p "SMTP Username: " SMTP_USER
if [ -z "$SMTP_USER" ]; then
SMTP_USER="$IMAP_USER"
fi
read -sp "SMTP Password: " SMTP_PASS
if [ -z "$SMTP_PASS" ]; then
SMTP_PASS="$IMAP_PASS"
fi
read -p "Use SSL/TLS? (Y/n, default: Y): " USE_SSL
USE_SSL=${USE_SSL:-Y}
if [ "$USE_SSL" = "Y" ] || [ "$USE_SSL" = "y" ]; then
USE_SSL="true"
else
USE_SSL="false"
fi
read -p "Ignore certificate validity errors? (y/N, default: N): " IGNORE_CERTS
IGNORE_CERTS=${IGNORE_CERTS:-N}
if [ "$IGNORE_CERTS" = "Y" ] || [ "$IGNORE_CERTS" = "y" ]; then
IGNORE_CERTS="true"
else
IGNORE_CERTS="false"
fi
# Build nextcloud-client
echo "Building nextcloud-client..."
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$SCRIPT_DIR/tools/go/nextcloud-client"
go build -ldflags="-X main.BuildServerURL=$SERVER_URL -X main.BuildUsername=$USERNAME -X main.BuildToken=$TOKEN" -o ~/bin/nextcloud-client .
echo "✓ nextcloud-client built successfully"
# Build nextcloud-contacts
echo "Building nextcloud-contacts..."
cd "$SCRIPT_DIR/tools/go/nextcloud-contacts"
go build -ldflags="-X main.BuildServerURL=$SERVER_URL -X main.BuildUsername=$USERNAME -X main.BuildToken=$TOKEN" -o ~/bin/nextcloud-contacts .
echo "✓ nextcloud-contacts built successfully"
# Build nextcloud-calendar
echo "Building nextcloud-calendar..."
cd "$SCRIPT_DIR/tools/go/nextcloud-calendar"
go build -ldflags="-X main.BuildServerURL=$SERVER_URL -X main.BuildUsername=$USERNAME -X main.BuildToken=$TOKEN" -o ~/bin/nextcloud-calendar .
echo "✓ nextcloud-calendar built successfully"
# Build nextcloud-mail
echo "Building nextcloud-mail..."
cd "$SCRIPT_DIR/tools/go/nextcloud-mail"
# Build with compile-time credentials using multiple -ldflags arguments
go build \
-ldflags="-X main.BuildIMAPServer=$IMAP_SERVER" \
-ldflags="-X main.BuildIMAPPort=$IMAP_PORT" \
-ldflags="-X main.BuildIMAPUser=$IMAP_USER" \
-ldflags="-X main.BuildIMAPPassword=$IMAP_PASS" \
-ldflags="-X main.BuildSMTPServer=$SMTP_SERVER" \
-ldflags="-X main.BuildSMTPPort=$SMTP_PORT" \
-ldflags="-X main.BuildSMTPUser=$SMTP_USER" \
-ldflags="-X main.BuildSMTPPassword=$SMTP_PASS" \
-ldflags="-X main.BuildUseSSL=$USE_SSL" \
-ldflags="-X main.BuildIgnoreCerts=$IGNORE_CERTS" \
-o ~/bin/nextcloud-mail
if [ $? -eq 0 ]; then
echo "✓ nextcloud-mail built successfully"
else
echo "❌ Build failed"
exit 1
fi
echo ""
echo "All tools built successfully!"
echo ""
echo "Binaries installed at:"
echo " ~/bin/nextcloud-client (WebDAV file operations)"
echo " ~/bin/nextcloud-contacts (CardDAV address books)"
echo " ~/bin/nextcloud-calendar (CalDAV events)"
echo " ~/bin/nextcloud-mail (IMAP/SMTP email)"
echo ""
echo "Security Note: These binaries contain credentials in clear text."
echo "Do not distribute them outside your trusted environment."