Files
pxe_boot_alma/work/KickStart/cfg/probe-config/L150-setDisk1pw.sh.no
T
andersenandClaude Fable 5 6d398b826a refactor: move tree under homelab/, add alma10 hardening and kickstart docs
- restructure boot/kickstarts/scripts/docs into homelab/
- docs: alma9->10 breaking changes, CIS hardening, kickstart changes
- add find_cron_entries.sh helper and codex running memory notes

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-07-06 22:35:07 -04:00

118 lines
3.6 KiB
Plaintext

#
# Set /opt/iglass passphrase in 1password
#
OPDOMAIN="iglassnetworks"
#OPVAULT="Private"
OPVAULT="NOC"
#OPUSER="[email protected]"
if [ -z "$PROBE" ]; then
Warn "Probe name required for setting 1password."
else
echo "Setting /opt/iglass password in 1password for $PROBE\[$ST\]"
OP=$($SSH "PGSERVICE=iglass2 psql -Aqt -U noc -c \"select optpass from probes_auth where service_tag = '$ST' LIMIT 1\"")
if [ -z "$OP" ]; then
Warn "No optpass found for '$ST' in DB"
else
Debug "Found optpass for '$ST'"
echo
echo "Please enter 1password credentials."
echo
#read -p " Email address [$OPUSER]: " TMPU
#[ -n "$TMPU" ] && OPUSER="$TMPU"
while [ -z "$OPUSER" ]; do
read -p " User/Email address: " OPUSER
done
if echo "$OPUSER" | grep -qv \@; then
SH="$OPUSER"
#OPUSER="$OPUSER@$OPDOMAIN";
OPUSER="[email protected]";
else
SH=${OPUSER/%@*/}
fi
SH=$(echo $SH | tr '.' '_')
while [ -z "$OPMPW" ]; do
read -s -p " Master password for $OPUSER: " OPMPW
echo
#read -s -p "Re-enter Master password: " OPMPW2
#echo
#if [ "$OPMPW" != "$OPMPW2" ]; then
# OPMPW=""
# echo
# echo "Passwords do not match!"
#fi
#echo
done
OPTITLE="$PROBE"
[ -n "$ST" ] && OPTITLE="$OPTITLE [$ST]"
[ -n "$CUST" ] && OPTITLE="$OPTITLE $CUST"
Debug "SSH=\"$SSH\""
SIGNEDIN="$($SSH grep -E shorthand.*$SH .op/config 2>/dev/null)"
if [ -z "$SIGNEDIN" ]; then
SKEY=
while [ -z "$SKEY" ]; do
read -s -p " First time for $OPUSER enter secret key: " SKEY
echo
done
SESSION=$($SSH op signin $OPDOMAIN.1password.com $OPUSER $SKEY $OPMPW --output=raw --shorthand=$SH)
else
Debug "User $OPUSER has signed into 1password previously"
#SESSION=$($SSH op signin $OPDOMAIN $OPMPW --output=raw)
SESSION=$($SSH op signin $SH $OPMPW --output=raw)
fi
echo
echo "Creating 1password entry for $OPTITLE: "
if [ -z "$SESSION" ]; then
Warn "Could not establish OP session"
else
Debug "OP session established"
#QUERY="PGSERVICE=iglass2 psql -U noc -c \"SELECT optpass FROM probes_auth WHERE service_tag = '$ST'\""
#JSON=$(jq -n --arg np "$QUERY" --arg op "$OP" '{notesPlain: $np, sections:[], passwordHistory:[], password: $op}')
JSON=$(jq -n --arg op "$OP" '{sections:[], passwordHistory:[], password: $op}')
Debug "Encoding: $JSON"
#ENCODED=$($SSH "echo '$JSON' | op encode")
ENCODED=$(echo $JSON | base64 -w0)
if [ -z "$ENCODED" ]; then
Warn "Could not encode json entry"
else
Debug "ENCODED=$ENCODED"
UUID=$($SSH "OP_SESSION_$SH='$SESSION' op create item Password $ENCODED --title=\"$OPTITLE\" --vault=$OPVAULT --tags=\"probe passphrases\"")
if [ -z "$UUID" ]; then
Warn "Entry not added to 1password"
else
echo "Entry added to 1password: $UUID"
echo "Deleting entry from iglass2 DB"
echo "PGSERVICE=iglass2 psql -U noc -c \"DELETE FROM probes_auth WHERE service_tag = '$ST'\""
fi
$SSH "OP_SESSION_$SH='$SESSION' op signout OP_SESSION_$SH"
# It will created duplicates with different uuids
#if op get item \"$OPTITLE\" --vault=Private &> /dev/null; then echo 1password entry created; else echo Could not create 1password entry; fi \""
fi
fi
fi
fi
Continue