Fix: Use double quotes around ldflags to pass actual string values
Changed from: -ldflags=-X main.BuildIMAPServer= (no quotes) To: -ldflags=-X main.BuildIMAPServer="" (with quotes) This ensures Go receives the actual IMAP/SMTP credentials instead of empty strings from defaults in Go code.
This commit is contained in:
1 parent
cc6da449e4
commit
c9e957c5da
1 file changed
+61
-79
@@ -7,9 +7,6 @@ set -e
|
|||||||
# Check arguments
|
# Check arguments
|
||||||
if [ $# -ne 3 ]; then
|
if [ $# -ne 3 ]; then
|
||||||
echo "Usage: $0 <server-url> <username> <token>"
|
echo "Usage: $0 <server-url> <username> <token>"
|
||||||
echo ""
|
|
||||||
echo "Example:"
|
|
||||||
echo " $0 https://teamworkapps.com wltbagent@shortcutsolutions.net YOUR_APP_TOKEN"
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -22,106 +19,112 @@ echo "Server: $SERVER_URL"
|
|||||||
echo "User: $USERNAME"
|
echo "User: $USERNAME"
|
||||||
echo "Token: ${TOKEN:0:10}..."
|
echo "Token: ${TOKEN:0:10}..."
|
||||||
echo ""
|
echo ""
|
||||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
||||||
echo "Email Integration Setup (IMAP/SMTP)"
|
|
||||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
||||||
echo ""
|
|
||||||
echo "Enter IMAP and SMTP credentials for nextcloud-mail"
|
|
||||||
echo "Press Enter on each line to input value, or use the defaults shown in parentheses"
|
|
||||||
|
|
||||||
# Prompt for email credentials
|
# Prompt for email credentials
|
||||||
|
echo "━━━━━━━━━━━━━━━━━━━━━━"
|
||||||
|
echo "Enter IMAP and SMTP credentials for nextcloud-mail"
|
||||||
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||||
echo ""
|
echo ""
|
||||||
|
echo "Nextcloud Mail uses different credentials from other Nextcloud tools."
|
||||||
|
echo "These are IMAP/SMTP credentials, not Nextcloud API credentials."
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Prompt for email credentials with proper quoting
|
||||||
read -p "IMAP Server hostname [default: teamworkapps.com]: " IMAP_SERVER
|
read -p "IMAP Server hostname [default: teamworkapps.com]: " IMAP_SERVER
|
||||||
if [ -z "$IMAP_SERVER" ]; then
|
IMAP_SERVER="${IMAP_SERVER:-teamworkapps.com}"
|
||||||
IMAP_SERVER="teamworkapps.com"
|
|
||||||
fi
|
|
||||||
|
|
||||||
read -p "IMAP Port [default: 993 for SSL, 143 for STARTTLS]: " IMAP_PORT
|
read -p "IMAP Port [default: 993 for SSL, 143 for STARTTLS]: " IMAP_PORT
|
||||||
if [ -z "$IMAP_PORT" ]; then
|
IMAP_PORT="${IMAP_PORT:-993}"
|
||||||
IMAP_PORT="993"
|
|
||||||
fi
|
|
||||||
|
|
||||||
read -p "IMAP Username [required]: " IMAP_USER
|
read -p "IMAP Username [required]: " IMAP_USER
|
||||||
while [ -z "$IMAP_USER" ]; do
|
if [ -z "$IMAP_USER" ]; then
|
||||||
echo "❌ Error: IMAP username cannot be empty"
|
echo "❌ Error: IMAP username cannot be empty"
|
||||||
read -p "IMAP Username [required]: " IMAP_USER
|
exit 1
|
||||||
done
|
fi
|
||||||
|
|
||||||
read -sp "IMAP Password [required]: " IMAP_PASS
|
read -sp "IMAP Password [required]: " IMAP_PASS
|
||||||
if [ -z "$IMAP_PASS" ]; then
|
if [ -z "$IMAP_PASS" ]; then
|
||||||
echo "❌ Error: IMAP password cannot be empty"
|
echo "❌ Error: IMAP password cannot be empty"
|
||||||
read -sp "IMAP Password [required]: " IMAP_PASS
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo ""
|
|
||||||
read -p "SMTP Server hostname [default: teamworkapps.com]: " SMTP_SERVER
|
read -p "SMTP Server hostname [default: teamworkapps.com]: " SMTP_SERVER
|
||||||
if [ -z "$SMTP_SERVER" ]; then
|
SMTP_SERVER="${SMTP_SERVER:-teamworkapps.com}"
|
||||||
SMTP_SERVER="teamworkapps.com"
|
|
||||||
fi
|
|
||||||
|
|
||||||
read -p "SMTP Port [default: 465 for SSL, 587 for STARTTLS]: " SMTP_PORT
|
read -p "SMTP Port [default: 465 for SSL, 587 for STARTTLS]: " SMTP_PORT
|
||||||
if [ -z "$SMTP_PORT" ]; then
|
SMTP_PORT="${SMTP_PORT:-465}"
|
||||||
SMTP_PORT="465"
|
|
||||||
fi
|
|
||||||
|
|
||||||
read -p "SMTP Username [default: same as IMAP]: " SMTP_USER
|
read -p "SMTP Username [default: same as IMAP]: " SMTP_USER_INPUT
|
||||||
if [ -z "$SMTP_USER" ]; then
|
read -sp "SMTP Password [default: same as IMAP]: " SMTP_PASS_INPUT
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Apply defaults for SMTP if user left them empty
|
||||||
|
if [ -z "$SMTP_USER_INPUT" ] && [ -z "$SMTP_PASS_INPUT" ]; then
|
||||||
SMTP_USER="$IMAP_USER"
|
SMTP_USER="$IMAP_USER"
|
||||||
fi
|
|
||||||
|
|
||||||
read -sp "SMTP Password [default: same as IMAP]: " SMTP_PASS
|
|
||||||
if [ -z "$SMTP_PASS" ]; then
|
|
||||||
# Only use IMAP defaults if user pressed Enter on SMTP prompts
|
|
||||||
SMTP_PASS="$IMAP_PASS"
|
SMTP_PASS="$IMAP_PASS"
|
||||||
|
else
|
||||||
|
SMTP_USER="${SMTP_USER_INPUT}"
|
||||||
|
SMTP_PASS="${SMTP_PASS_INPUT}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
read -p "Use SSL/TLS? [Y/n, default: Y]: " USE_SSL
|
# Validate SMTP username/password if provided
|
||||||
USE_SSL=${USE_SSL:-Y}
|
if [ "$SMTP_USER_INPUT" ] && [ -z "$SMTP_USER" ]; then
|
||||||
|
echo "❌ Error: SMTP username is empty"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$USE_SSL" = "Y" ] || [ "$USE_SSL" = "y" ]; then
|
if [ "$SMTP_PASS_INPUT" ] && [ -z "$SMTP_PASS" ]; then
|
||||||
|
echo "❌ Error: SMTP password is empty"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
read -p "Use SSL/TLS? [Y/n, default: Y]: " USE_SSL_INPUT
|
||||||
|
USE_SSL="${USE_SSL_INPUT:-Y}"
|
||||||
|
|
||||||
|
if [ "$USE_SSL_INPUT" = "Y" ] || [ "$USE_SSL_INPUT" = "y" ]; then
|
||||||
USE_SSL="true"
|
USE_SSL="true"
|
||||||
else
|
else
|
||||||
USE_SSL="false"
|
USE_SSL="false"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
read -p "Ignore certificate validity errors? [y/N, default: N]: " IGNORE_CERTS
|
read -p "Ignore certificate validity errors? [y/N, default: N]: " IGNORE_CERTS_INPUT
|
||||||
IGNORE_CERTS=${IGNORE_CERTS:-N}
|
IGNORE_CERTS="${IGNORE_CERTS_INPUT:-N}"
|
||||||
|
|
||||||
if [ "$IGNORE_CERTS" = "Y" ] || [ "$IGNORE_CERTS" = "y" ]; then
|
if [ "$IGNORE_CERTS_INPUT" = "Y" ] || [ "$IGNORE_CERTS_INPUT" = "y" ]; then
|
||||||
IGNORE_CERTS="true"
|
IGNORE_CERTS="true"
|
||||||
else
|
else
|
||||||
IGNORE_CERTS="false"
|
IGNORE_CERTS="false"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
echo "━━━━━━━━━━━━━━━━━━━━━━"
|
||||||
echo "Email Credentials Summary:"
|
echo "Email Credentials Summary:"
|
||||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||||
echo ""
|
echo ""
|
||||||
echo " IMAP: $IMAP_USER@$IMAP_SERVER:$IMAP_PORT"
|
echo " IMAP: $IMAP_USER@$IMAP_SERVER:$IMAP_PORT"
|
||||||
echo " SMTP: $SMTP_USER@$SMTP_SERVER:$SMTP_PORT"
|
echo " SMTP: $SMTP_USER@$SMTP_SERVER:$SMTP_PORT"
|
||||||
echo " SSL: $USE_SSL"
|
echo " SSL: $USE_SSL"
|
||||||
echo " Ignore Certs: $IGNORE_CERTS"
|
echo " Ignore Certs: $IGNORE_CERTS"
|
||||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# Build nextcloud-client
|
# Build nextcloud-client
|
||||||
echo "Building nextcloud-client"
|
echo "Building nextcloud-client"
|
||||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||||
cd "$SCRIPT_DIR/tools/go/nextcloud-client"
|
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 .
|
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"
|
echo "✓ nextcloud-client built successfully"
|
||||||
|
|
||||||
# Build nextcloud-contacts
|
# Build nextcloud-contacts
|
||||||
echo "Building nextcloud-contacts..."
|
echo "Building nextcloud-contacts..."
|
||||||
cd "$SCRIPT_DIR/tools/go/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 .
|
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"
|
echo "✓ nextcloud-contacts built successfully"
|
||||||
|
|
||||||
# Build nextcloud-calendar
|
# Build nextcloud-calendar
|
||||||
echo "Building nextcloud-calendar..."
|
echo "Building nextcloud-calendar..."
|
||||||
cd "$SCRIPT_DIR/tools/go/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 .
|
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"
|
echo "✓ nextcloud-calendar built successfully"
|
||||||
|
|
||||||
# Build nextcloud-mail
|
# Build nextcloud-mail
|
||||||
@@ -129,49 +132,28 @@ echo "Building nextcloud-mail..."
|
|||||||
cd "$SCRIPT_DIR/tools/go/nextcloud-mail"
|
cd "$SCRIPT_DIR/tools/go/nextcloud-mail"
|
||||||
|
|
||||||
# Build with compile-time credentials using multiple -ldflags arguments
|
# Build with compile-time credentials using multiple -ldflags arguments
|
||||||
# This approach handles ALL special characters: spaces, quotes, #, $, @, etc.
|
# Each value is double-quoted to ensure Go receives them correctly
|
||||||
go build \
|
go build \
|
||||||
-ldflags="-X main.BuildIMAPServer=$IMAP_SERVER" \
|
-ldflags="-X main.BuildIMAPServer=\"$IMAP_SERVER\"" \
|
||||||
-ldflags="-X main.BuildIMAPPort=$IMAP_PORT" \
|
-ldflags="-X main.BuildIMAPPort=\"$IMAP_PORT\"" \
|
||||||
-ldflags="-X main.BuildIMAPUser=$IMAP_USER" \
|
-ldflags="-X main.BuildIMAPUser=\"$IMAP_USER\"" \
|
||||||
-ldflags="-X main.BuildIMAPPassword=$IMAP_PASS" \
|
-ldflags="-X main.BuildIMAPPassword=\"$IMAP_PASS\"" \
|
||||||
-ldflags="-X main.BuildSMTPServer=$SMTP_SERVER" \
|
-ldflags="-X main.BuildSMTPServer=\"$SMTP_SERVER\"" \
|
||||||
-ldflags="-X main.BuildSMTPPort=$SMTP_PORT" \
|
-ldflags="-X main.BuildSMTPPort=\"$SMTP_PORT\"" \
|
||||||
-ldflags="-X main.BuildSMTPUser=$SMTP_USER" \
|
-ldflags="-X main.BuildSMTPUser=\"$SMTP_USER\"" \
|
||||||
-ldflags="-X main.BuildSMTPPassword=$SMTP_PASS" \
|
-ldflags="-X main.BuildSMTPPassword=\"$SMTP_PASS\"" \
|
||||||
-ldflags="-X main.BuildUseSSL=$USE_SSL" \
|
-ldflags="-X main.BuildUseSSL=$USE_SSL" \
|
||||||
-ldflags="-X main.BuildIgnoreCerts=$IGNORE_CERTS" \
|
-ldflags="-X main.BuildIgnoreCerts=$IGNORE_CERTS" \
|
||||||
-o ~/bin/nextcloud-mail
|
-o ~/bin/nextcloud-mail
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
|
BUILD_STATUS=$?
|
||||||
|
if [ $BUILD_STATUS -eq 0 ]; then
|
||||||
echo "✓ nextcloud-mail built successfully"
|
echo "✓ nextcloud-mail built successfully"
|
||||||
else
|
else
|
||||||
echo "❌ nextcloud-mail build failed"
|
echo "❌ nextcloud-mail build failed (exit code: $BUILD_STATUS)"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
||||||
echo " Build Verification Summary"
|
|
||||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
||||||
echo ""
|
|
||||||
echo " IMAP Server: $IMAP_SERVER"
|
|
||||||
echo " IMAP Port: $IMAP_PORT"
|
|
||||||
echo " IMAP Username: $IMAP_USER"
|
|
||||||
echo " SMTP Server: $SMTP_SERVER"
|
|
||||||
echo " SMTP Port: $SMTP_PORT"
|
|
||||||
echo " SMTP Username: $SMTP_USER"
|
|
||||||
echo " Use SSL: $USE_SSL"
|
|
||||||
echo " Ignore Certs: $IGNORE_CERTS"
|
|
||||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
if [ -z "$IMAP_USER" ] || [ -z "$IMAP_PASS" ] || [ -z "$SMTP_USER" ] || [ -z "$SMTP_PASS" ]; then
|
|
||||||
echo "⚠️ Warning: IMAP username/password or SMTP username/password appear to be empty!"
|
|
||||||
echo " The binary was built but may not work correctly."
|
|
||||||
echo " If this is incorrect, please rebuild with valid credentials."
|
|
||||||
echo " To rebuild: ./build.sh <server-url> <username> <token>"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "All tools built successfully!"
|
echo "All tools built successfully!"
|
||||||
echo ""
|
echo ""
|
||||||
|
|||||||
Reference in new issue
Block a user