#---------------------------------------------------------------------------- # /var/install/bin/phppgadmin-tools-helper # # Creation: 2017-11-02 hbfl # Last Update: $Id$ # # Copyright (c) 2017-2022 Holger Bruenjes, holgerbruenjes(at)gmx(dot)net # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------- ASK='/var/install/bin/ask' MKTEMP='/usr/bin/mktemp' RM='/usr/bin/rm' CAT='/usr/bin/cat' SED='/usr/bin/sed' GREP='/usr/bin/grep' XZ='/usr/bin/xz' AWK='/usr/bin/gawk' # --------------------------------------------------------------------------- # check status and access of PostgreSQL Database # --------------------------------------------------------------------------- check_status() { pg_server=$(find /etc/config.d -maxdepth 1 \ -name 'postgresql' -printf '%f\n' -o \ -name 'postgresql[0-9]*' -printf '%f\n') if [ -n "${pg_server}" ] then for SERVER in ${pg_server} do # get package-name and extract numeric value pg_path=$(echo "${SERVER}" | cut -d'_' -f1 | sed 's|[^[:digit:]]||g') if [ -z "${pg_path}" ] then database_exec=/usr/local/pgsql/bin/psql else database_exec=/usr/lib/pgsql/${pg_path}/bin/psql fi break done else database_exec=/usr/bin/psql if [ ! -f ${database_exec} ] then # install the postgresql-client package eisman install --auto postgresql-client inst_ret=${?} if [ ${inst_ret} -ne 0 ] then echo mecho --error 'No psql executable found' mecho --info 'Please install the postgresql-client package' echo anykey exit 1 fi fi # # the executable is contained # ${XZ} --decompress --quiet /srv/phppgadmin/psql.xz # # database_exec=/srv/phppgadmin/psql fi # output in tmpfile is require to catch all output from psql too :-( tmpfile=$(${MKTEMP} -t .XXXXXXXXXXXXX) # use LANG=C to get always the same output to can grep them correctly LANG=C ${database_exec} -A \ -h${host} \ -p${port} \ -dpostgres \ -t \ -w \ -c 'select version()' > ${tmpfile} 2>&1 read status < ${tmpfile} ${RM} -f ${tmpfile} if echo ${status} | ${GREP} -q 'Connection refused' then echo mecho -n --warn "PostgreSQL Server on '" mecho -n --std "${host} ${port}" mecho --warn "' is not running" echo anykey select_server fi } # --------------------------------------------------------------------------- # get_passwd # --------------------------------------------------------------------------- get_admin_and_passwd() { local count clrhome mecho -n --info "Please enter Admin and Password for 'PostgreSQL' " mecho "'${host}' '${name}' '${port}'" echo _ask_tmpfile=$(${MKTEMP} -t .XXXXXXXXXXXXX) ${ASK} "Please enter the 'PostgreSQL' Admin user:" "" "+" > ${_ask_tmpfile} rc=${?} read admin_user < ${_ask_tmpfile} ${RM} -f ${_ask_tmpfile} # if ask break, ask returned 255 if [ ${rc} = 255 ] then exit 127 fi count=1 while [ ${count} -le 3 ] do _ask_tmpfile=$(${MKTEMP} -t .XXXXXXXXXXXXX) ${ASK} "Please enter the 'PostgreSQL' Admin Passwd:" "" "+hidden+" > ${_ask_tmpfile} rc=${?} read password < ${_ask_tmpfile} ${RM} -f ${_ask_tmpfile} # if ask break, ask returned 255 if [ ${rc} = 255 ] then exit 127 fi if [ -n "${password}" ] then ${CAT} >/root/.pgpass < ${tmpfile} 2>&1 pw_check_ret=${?} ${RM} -f ${tmpfile} if [ ${pw_check_ret} -eq 0 ] then break else echo mecho --error 'Password input error' ${SED} -i "/${host}:${port}:\*:${admin_user}:${password}/d" /root/.pgpass echo if [ ${count} -eq 3 ] then anykey select_server fi fi # count=$((${count} + 1)) fi count=$((${count} + 1)) done } # --------------------------------------------------------------------------- # list configured servers # --------------------------------------------------------------------------- list_configured_servers() { local idx mecho mecho 'Configured activ servers:' mecho techo --begin '3 5r 20 17 13' techo --row '' --info "No" --info "Host" --info 'Description' idx=1 while [ ${idx} -le ${PHPPGADMIN_SERVER_N} ] do eval active='${PHPPGADMIN_SERVER_'${idx}'_ACTIVE}' eval host='${PHPPGADMIN_SERVER_'${idx}'_HOST}' eval name='${PHPPGADMIN_SERVER_'${idx}'_NAME}' if [ "${active}" = "yes" ] then techo --row '' ${idx}. ${host} ${name} --info "active" else techo --row '' ${idx}. ${host} ${name} --warn "not active" fi idx=$((${idx} + 1)) done echo; echo eval advanced_settings='${PHPPGADMIN_ADVANCED_SETTINGS}' if [ "${advanced_settings}" = "yes" ] then techo --row '' '' 'ADVANCED_SETTINGS' --info 'active' else techo --row '' '' 'ADVANCED_SETTINGS' --warn 'not active' fi techo --end echo _ask_tmpfile=$(${MKTEMP} -t .XXXXXXXXXXXXX) ${ASK} "Select" "" "1-$((${idx} - 1))" "^$=Return" "0=Exit" >${_ask_tmpfile} rc=${?} read server < ${_ask_tmpfile} ${RM} -f ${_ask_tmpfile} # if ask break, ask returned 255 if [ ${rc} = 255 ] then exit 127 fi } # --------------------------------------------------------------------------- # check executable binary # --------------------------------------------------------------------------- check_executable() { if [ -f /srv/phppgadmin/psql ] then ${XZ} --compress --quiet /srv/phppgadmin/psql fi } # --------------------------------------------------------------------------- # print result # --------------------------------------------------------------------------- print_result() { if [ ${1} -eq 0 ] then mecho --ok else mecho --fail fi } # --------------------------------------------------------------------------- # end # ---------------------------------------------------------------------------