]> mop.ddnsfree.com - git repositories - brisk.git/commitdiff
sql/builder.sh: sudo instead of su
authorMatteo Nastasi <nastasi@alternativeoutput.it>
Sun, 13 Sep 2026 10:37:07 +0000 (12:37 +0200)
committerMatteo Nastasi <nastasi@alternativeoutput.it>
Sun, 13 Sep 2026 10:37:07 +0000 (12:37 +0200)
"su root -c" asks for the root password, which on a freshly installed debian
does not even exist: the first user administers with sudo. The two commands
were also nested (su root calling su postgres) with three levels of quoting
to get through, and the variables ended up in the string unprotected.

Now it goes straight to "sudo -u postgres" and the arguments are quoted.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014M1jiEq9cHdE5SE5j6vFuE

sql/builder.sh

index db1dcd182e8e8483a362be13a2788a897f079086..55df9779ba036eacc96611b9966312307e780497 100755 (executable)
@@ -145,16 +145,18 @@ test "$DBUSER" != "" && pg_args="$pg_args -U $DBUSER"
 test "$DBPORT" != "" && pg_args="$pg_args -p $DBPORT"
 test "$DBBASE" != "" && pg_args="$pg_args $DBBASE"
 
-
 case $CMD in
     "create")
-        echo "su root"
-        su root -c "su postgres -c \"echo \\\"DBUser passwd: $DBPASS\\\" ; createuser -S -D -R -P $DBUSER && createdb -E utf8 -O $DBUSER $DBBASE\""
+        echo "sudo -u postgres"
+        echo "DBUser passwd: $DBPASS"
+        sudo -u postgres createuser -S -D -R -P "$DBUSER" \
+            && sudo -u postgres createdb -E utf8 -O "$DBUSER" "$DBBASE"
         ;;
 
     "destroy")
-        echo "su root"
-        su root -c "su postgres -c \"dropdb $DBBASE && dropuser $DBUSER\""
+        echo "sudo -u postgres"
+        sudo -u postgres dropdb "$DBBASE" \
+            && sudo -u postgres dropuser "$DBUSER"
         ;;
     "clean")
         ( echo "-- MESG: clean start" ; one_or_all $2 | egrep "$MATCH_DROP|^-- MESG|^-- FILE " | tac ; echo "-- MESG: clean end" ;   ) | sqlexe