Files
nextcloud-integration/build.sh
T
WLTBAgent 154a93a148 Fix build.sh: add proper escaping for nextcloud-mail ldflags
The build was failing with Go linker errors because special characters in
user-provided credentials (especially passwords) were not being properly escaped.

Added escape_ldflag() function to handle:
- Backslashes
- Double quotes
- Spaces

This ensures that any user input (including passwords with special characters)
is safely passed to Go's linker without breaking the build command.
2026-02-23 21:55:51 +00:00

143 lines
5.2 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>"
echo ""
echo "Example:"
echo " $0 https://teamworkapps.com wltbagent@shortcutsolutions.net YOUR_APP_TOKEN"
exit 1
fi
SERVER_URL="$1"
USERNAME="$2"
TOKEN="$3"
echo "Building Nextcloud CLI tools with credentials..."
echo "Server: $SERVER_URL"
echo "User: $USERNAME"
echo "Token: ${TOKEN:0:10}..."
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "Email Integration Setup (IMAP/SMTP)"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "Nextcloud Mail uses different credentials from the other Nextcloud tools."
echo "These are IMAP/SMTP credentials, not Nextcloud API credentials."
echo ""
# Prompt for email credentials
read -p "IMAP Server hostname (default: teamworkapps.com): " IMAP_SERVER
IMAP_SERVER=${IMAP_SERVER:-teamworkapps.com}
read -p "IMAP Port (default: 993 for SSL, 143 for STARTTLS): " IMAP_PORT
IMAP_PORT=${IMAP_PORT:-993}
read -p "IMAP Username: " IMAP_USER
read -sp "IMAP Password: " IMAP_PASS
echo ""
read -p "SMTP Server hostname (default: teamworkapps.com): " SMTP_SERVER
SMTP_SERVER=${SMTP_SERVER:-teamworkapps.com}
read -p "SMTP Port (default: 465 for SSL, 587 for STARTTLS): " SMTP_PORT
SMTP_PORT=${SMTP_PORT:-465}
read -p "SMTP Username (default: same as IMAP): " SMTP_USER
SMTP_USER=${SMTP_USER:-$IMAP_USER}
read -sp "SMTP Password (default: same as IMAP): " SMTP_PASS
echo ""
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
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "Email Credentials Summary:"
echo " IMAP: $IMAP_USER@$IMAP_SERVER:$IMAP_PORT (SSL: $USE_SSL)"
echo " SMTP: $SMTP_USER@$SMTP_SERVER:$SMTP_PORT (SSL: $USE_SSL)"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
# 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 ldflags - escape special characters in values
escape_ldflag() {
local value="$1"
# Escape backslashes, double quotes, and spaces
value="${value//\\/\\\\}"
value="${value//\"/\\\"}"
echo "$value"
}
LDFLAGS="-X main.BuildIMAPServer=\"$(escape_ldflag "$IMAP_SERVER")\""
LDFLAGS="$LDFLAGS -X main.BuildIMAPPort=\"$(escape_ldflag "$IMAP_PORT")\""
LDFLAGS="$LDFLAGS -X main.BuildIMAPUser=\"$(escape_ldflag "$IMAP_USER")\""
LDFLAGS="$LDFLAGS -X main.BuildIMAPPassword=\"$(escape_ldflag "$IMAP_PASS")\""
LDFLAGS="$LDFLAGS -X main.BuildSMTPServer=\"$(escape_ldflag "$SMTP_SERVER")\""
LDFLAGS="$LDFLAGS -X main.BuildSMTPPort=\"$(escape_ldflag "$SMTP_PORT")\""
LDFLAGS="$LDFLAGS -X main.BuildSMTPUser=\"$(escape_ldflag "$SMTP_USER")\""
LDFLAGS="$LDFLAGS -X main.BuildSMTPPassword=\"$(escape_ldflag "$SMTP_PASS")\""
LDFLAGS="$LDFLAGS -X main.BuildUseSSL=\"$(escape_ldflag "$USE_SSL")\""
LDFLAGS="$LDFLAGS -X main.BuildIgnoreCerts=\"$(escape_ldflag "$IGNORE_CERTS")\""
go build -ldflags="$LDFLAGS" -o ~/bin/nextcloud-mail .
echo "✓ nextcloud-mail built successfully"
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."