formatting update; sent errors to std:err
This commit is contained in:
parent
128756d056
commit
aea4e9dbae
53
bin/rd-db.sh
53
bin/rd-db.sh
@ -34,15 +34,15 @@ DB_PASSWORD_WARNING='WARNING : No password available for selected connection.';
|
||||
ERROR_CODE=0;
|
||||
|
||||
command -v op >/dev/null 2>&1\
|
||||
|| { ERROR_CODE="$REQUIREMENT_ERROR_CODE"; printf "$REQUIREMENT_ERROR" 'op' "$LINK_OP" >&2; }
|
||||
|| { ERROR_CODE="$REQUIREMENT_ERROR_CODE"; printf "$REQUIREMENT_ERROR" 'op' "$LINK_OP" >&2; };
|
||||
command -v jq >/dev/null 2>&1\
|
||||
|| { ERROR_CODE="$REQUIREMENT_ERROR_CODE"; printf "$REQUIREMENT_ERROR" 'jq' "$LINK_JQ" >&2; }
|
||||
|| { ERROR_CODE="$REQUIREMENT_ERROR_CODE"; printf "$REQUIREMENT_ERROR" 'jq' "$LINK_JQ" >&2; };
|
||||
command -v fzf >/dev/null 2>&1\
|
||||
|| { ERROR_CODE="$REQUIREMENT_ERROR_CODE"; printf "$REQUIREMENT_ERROR" 'fzf' "$LINK_FZF" >&2; }
|
||||
|| { ERROR_CODE="$REQUIREMENT_ERROR_CODE"; printf "$REQUIREMENT_ERROR" 'fzf' "$LINK_FZF" >&2; };
|
||||
command -v mssql-cli >/dev/null 2>&1\
|
||||
|| { ERROR_CODE="$REQUIREMENT_ERROR_CODE"; printf "$REQUIREMENT_ERROR" 'mssql-cli' "$LINK_MSSQLCLI" >&2; }
|
||||
|| { ERROR_CODE="$REQUIREMENT_ERROR_CODE"; printf "$REQUIREMENT_ERROR" 'mssql-cli' "$LINK_MSSQLCLI" >&2; };
|
||||
command -v pgcli >/dev/null 2>&1\
|
||||
|| { ERROR_CODE="$REQUIREMENT_ERROR_CODE"; printf "$REQUIREMENT_ERROR" 'pgcli' "$LINK_PGCLI" >&2; }
|
||||
|| { ERROR_CODE="$REQUIREMENT_ERROR_CODE"; printf "$REQUIREMENT_ERROR" 'pgcli' "$LINK_PGCLI" >&2; };
|
||||
|
||||
[[ "$ERROR_CODE" -ne 0 ]] && exit "$ERROR_CODE";
|
||||
|
||||
@ -51,10 +51,11 @@ op list templates >/dev/null 2>&1 || {
|
||||
unset OP_SESSION_rent_dynamics;
|
||||
eval $(op signin rent_dynamics 2>/dev/null);
|
||||
|
||||
op list templates >/dev/null 2>&1 || { printf "$OP_ERROR"; exit "$OP_ERROR_CODE"; };
|
||||
op list templates >/dev/null 2>&1 || { printf "$OP_ERROR" >&2; exit "$OP_ERROR_CODE"; };
|
||||
}
|
||||
|
||||
printf "\n\nSelect database connection:"
|
||||
|
||||
printf "\n\nSelect database connection:";
|
||||
connection=$(\
|
||||
op list items 2>/dev/null \
|
||||
| jq '.[] | select(.templateUuid == "102") | .overview.title' \
|
||||
@ -69,20 +70,20 @@ credentials=$(\
|
||||
| jq -s 'add | (.type, if .url then .url else .server end, .username, .password, .database)' \
|
||||
);
|
||||
|
||||
database_type=$(echo "$credentials" | awk '{print $1;}' | xargs)
|
||||
server=$(echo "$credentials" | awk '{print $2;}' | xargs)
|
||||
user=$(echo "$credentials" | awk '{print $3;}' | xargs)
|
||||
pass=$(echo "$credentials" | awk '{print $4;}' | xargs)
|
||||
dbname=$(echo "$credentials" | awk '{print $5;}' | xargs)
|
||||
database_type=$(echo "$credentials" | awk '{print $1;}' | xargs);
|
||||
server=$(echo "$credentials" | awk '{print $2;}' | xargs);
|
||||
user=$(echo "$credentials" | awk '{print $3;}' | xargs);
|
||||
pass=$(echo "$credentials" | awk '{print $4;}' | xargs);
|
||||
dbname=$(echo "$credentials" | awk '{print $5;}' | xargs);
|
||||
|
||||
[ "$server" == 'null' ] && { printf "$DB_SELECT_ERROR"; exit "$DB_SELECT_ERROR_CODE"; };
|
||||
[ "$server" == 'null' ] && { printf "$DB_SELECT_ERROR" >&2; exit "$DB_SELECT_ERROR_CODE"; };
|
||||
|
||||
[ "$user" == 'null' ] && {
|
||||
printf "$DB_USER_WARNING" "$connection";
|
||||
printf "Enter username:";
|
||||
read user;
|
||||
|
||||
[ ! "$user" ] && { echo "$DB_USER_ERROR"; exit "$DB_USER_ERROR_CODE";}
|
||||
[ ! "$user" ] && { echo "$DB_USER_ERROR" >&2; exit "$DB_USER_ERROR_CODE"; };
|
||||
};
|
||||
|
||||
[ "$pass" == 'null' ] && {
|
||||
@ -92,18 +93,18 @@ dbname=$(echo "$credentials" | awk '{print $5;}' | xargs)
|
||||
};
|
||||
|
||||
if [ "$database_type" == "mssql" ]; then
|
||||
echo "Microsoft SQL database detected! Connecting..."
|
||||
mssql-cli -S "$server" -U "$user" -P "$pass"
|
||||
echo "Microsoft SQL database detected! Connecting...";
|
||||
mssql-cli -S "$server" -U "$user" -P "$pass";
|
||||
elif [ "$database_type" == "postgresql" ]; then
|
||||
echo "Postgres database detected! Connecting..."
|
||||
PGPASSWORD="$pass" pgcli -h "$server" -U "$user" -d "$dbname"
|
||||
echo "Postgres database detected! Connecting...";
|
||||
PGPASSWORD="$pass" pgcli -h "$server" -U "$user" -d "$dbname";
|
||||
else
|
||||
database_type=$(echo -e "mssql\npostgresql" | fzf --height=20% --layout=reverse)
|
||||
if [ "$database_type" == "mssql" ]; then
|
||||
echo "Connection type selected: Microsoft SQL. Connecting...";
|
||||
mssql-cli -S "$server" -U "$user" -P "$pass"
|
||||
elif [ "$database_type" == "postgresql" ]; then
|
||||
echo "Connection type selected: Postgres. Connecting...";
|
||||
PGPASSWORD="$pass" pgcli -h "$server" -U "$user" -d "$dbname"
|
||||
fi
|
||||
database_type=$(echo -e "mssql\npostgresql" | fzf --height=20% --layout=reverse);
|
||||
if [ "$database_type" == "mssql" ]; then
|
||||
echo "Connection type selected: Microsoft SQL. Connecting...";
|
||||
mssql-cli -S "$server" -U "$user" -P "$pass";
|
||||
elif [ "$database_type" == "postgresql" ]; then
|
||||
echo "Connection type selected: Postgres. Connecting...";
|
||||
PGPASSWORD="$pass" pgcli -h "$server" -U "$user" -d "$dbname";
|
||||
fi
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user