#!/bin/bash : ' @vendor Chorke Academia, Inc. @web https://cdn.chorke.org/docs/academia @version 1.0.00 @since 1.0.00 ' :< "$HOME/Downloads/$LDB_TMP_TABLE.sql" if [[ "$OSTYPE" == "darwin"* ]];then printf -v LDB_SED_ADAPT 's|public.%s|%s|g' "$LDB_TMP_TABLE" "$LDB_SRC_TABLE" sed -i '' -e "$LDB_SED_ADAPT" "$HOME/Downloads/$LDB_TMP_TABLE.sql" printf -v LDB_SED_ADAPT 's|%s|%s|g' "$LDB_TMP_TABLE" "$LDB_SRC_TABLE" sed -i '' -e "$LDB_SED_ADAPT" "$HOME/Downloads/$LDB_TMP_TABLE.sql" else printf -v LDB_SED_ADAPT 's|public.%s|%s|g' "$LDB_TMP_TABLE" "$LDB_SRC_TABLE" sed -i -e "$LDB_SED_ADAPT" "$HOME/Downloads/$LDB_TMP_TABLE.sql" printf -v LDB_SED_ADAPT 's|%s|%s|g' "$LDB_TMP_TABLE" "$LDB_SRC_TABLE" sed -i -e "$LDB_SED_ADAPT" "$HOME/Downloads/$LDB_TMP_TABLE.sql" fi } function remove_temp_table(){ echo '' cat << EOF | psql \c $LDB_SRC_DBASE; DROP TABLE IF EXISTS $LDB_TMP_TABLE; EOF } function export_init_check(){ if [ -z "$LDB_SRC_DBASE" ];then printf 'Enter \033[0;32mdatabase\033[0m: '; read LDB_SRC_DBASE;fi if [ -z "$LDB_SRC_TABLE" ];then printf 'Enter \033[0;32mtable \033[0m: '; read LDB_SRC_TABLE;fi if [ -z "$LDB_SRC_WHERE" ];then printf 'Enter \033[0;32mwhere \033[0m: '; read LDB_SRC_WHERE;fi if [ ! -z "$LDB_SRC_DBASE" ]&&[ ! -z "$LDB_SRC_TABLE" ]&&[ ! -z "$LDB_SRC_WHERE" ];then create_temp_table; export_temp_table; remove_temp_table else printf '\033[0;31mdatabase, table, where clause\033[0m is missing!\n';fi } function init(){ if [ -z "$PGPASSWORD" ];then printf 'PSQL \033[0;32mPassword\033[0m: ';read -s PGPASSWORD;if [ ! -z "$PGPASSWORD" ];then export PGPASSWORD;fi;fi if [ -x "$(command -v psql)" ];then if [ -x "$(command -v pg_dump)" ];then export_init_check else printf '\npg_dump \033[0;32mcommand not found! \033[0m:(\n';fi else printf '\npsql \033[0;31mcommand not found! \033[0m:(\n';fi if [ ! -z "$PGPASSWORD" ];then unset PGPASSWORD;fi } init