somratpro commited on
Commit
c979202
·
1 Parent(s): 32ab05a

chore: update environment configuration in start.sh

Browse files
Files changed (1) hide show
  1. start.sh +5 -3
start.sh CHANGED
@@ -109,7 +109,7 @@ done
109
  # Generate random DB password on first run (don't hardcode 'paperclip')
110
  DB_PASSWORD_FILE="${PAPERCLIP_HOME}/.db-password"
111
  if [ ! -f "${DB_PASSWORD_FILE}" ]; then
112
- DB_PASSWORD=$(openssl rand -base64 24)
113
  echo "$DB_PASSWORD" > "${DB_PASSWORD_FILE}"
114
  chmod 600 "${DB_PASSWORD_FILE}"
115
  else
@@ -121,8 +121,10 @@ su - postgres -c "psql -c \"ALTER USER postgres WITH PASSWORD '${DB_PASSWORD}';\
121
  su - postgres -c "psql -tc \"SELECT 1 FROM pg_database WHERE datname = 'paperclip'\" | grep -q 1 || psql -c \"CREATE DATABASE paperclip OWNER postgres;\"" >/dev/null 2>&1 || true
122
 
123
  # Update DATABASE_URL with generated password (if not explicitly set)
 
124
  if [[ "$DATABASE_URL" == *"postgres:paperclip"* ]]; then
125
- export DATABASE_URL="postgres://postgres:${DB_PASSWORD}@localhost:5432/paperclip"
 
126
  fi
127
 
128
  echo "PostgreSQL ready (v${PG_VERSION})"
@@ -135,7 +137,7 @@ if [ -n "${HF_TOKEN:-}" ]; then
135
 
136
  # Check if last sync failed
137
  if [ -f "${SYNC_STATUS_FILE}" ]; then
138
- LAST_ERROR=$(python3 -c "import json; f=open('${SYNC_STATUS_FILE}'); d=json.load(f); print(d.get('last_error', ''))" 2>/dev/null || true)
139
  if [ -n "$LAST_ERROR" ]; then
140
  echo "⚠️ WARNING: Last backup sync failed: $LAST_ERROR"
141
  echo " Data may not be persisted to HF Dataset"
 
109
  # Generate random DB password on first run (don't hardcode 'paperclip')
110
  DB_PASSWORD_FILE="${PAPERCLIP_HOME}/.db-password"
111
  if [ ! -f "${DB_PASSWORD_FILE}" ]; then
112
+ DB_PASSWORD=$(openssl rand -hex 24)
113
  echo "$DB_PASSWORD" > "${DB_PASSWORD_FILE}"
114
  chmod 600 "${DB_PASSWORD_FILE}"
115
  else
 
121
  su - postgres -c "psql -tc \"SELECT 1 FROM pg_database WHERE datname = 'paperclip'\" | grep -q 1 || psql -c \"CREATE DATABASE paperclip OWNER postgres;\"" >/dev/null 2>&1 || true
122
 
123
  # Update DATABASE_URL with generated password (if not explicitly set)
124
+ # URL-encode the password to handle special chars (e.g. / + = from old base64 passwords)
125
  if [[ "$DATABASE_URL" == *"postgres:paperclip"* ]]; then
126
+ DB_PASSWORD_ENCODED=$(python3 -c "import urllib.parse,sys; print(urllib.parse.quote(sys.argv[1], safe=''))" "${DB_PASSWORD}")
127
+ export DATABASE_URL="postgres://postgres:${DB_PASSWORD_ENCODED}@localhost:5432/paperclip"
128
  fi
129
 
130
  echo "PostgreSQL ready (v${PG_VERSION})"
 
137
 
138
  # Check if last sync failed
139
  if [ -f "${SYNC_STATUS_FILE}" ]; then
140
+ LAST_ERROR=$(python3 -c "import json; f=open('${SYNC_STATUS_FILE}'); d=json.load(f); print(d.get('last_error') or '')" 2>/dev/null || true)
141
  if [ -n "$LAST_ERROR" ]; then
142
  echo "⚠️ WARNING: Last backup sync failed: $LAST_ERROR"
143
  echo " Data may not be persisted to HF Dataset"