Remember Forgejo URL and key label across runs
Persist the last-entered values to ~/.config/travel-bootstrap/config and offer them as the prompt default, so a re-run only needs Enter instead of retyping the same values every time. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
d52d1060ce
commit
079c3e4f10
1 changed files with 24 additions and 3 deletions
25
bootstrap.sh
25
bootstrap.sh
|
|
@ -50,17 +50,38 @@ preflight_env() {
|
||||||
|
|
||||||
gather_config() {
|
gather_config() {
|
||||||
section "config"
|
section "config"
|
||||||
|
local config_file="$HOME/.config/travel-bootstrap/config"
|
||||||
|
mkdir -p "$(dirname "$config_file")"
|
||||||
|
|
||||||
|
local DEFAULT_FORGEJO_URL="" DEFAULT_KEY_NAME=""
|
||||||
|
if [ -f "$config_file" ]; then
|
||||||
|
# shellcheck disable=SC1090
|
||||||
|
source "$config_file"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -z "${FORGEJO_URL:-}" ]; then
|
if [ -z "${FORGEJO_URL:-}" ]; then
|
||||||
|
if [ -n "$DEFAULT_FORGEJO_URL" ]; then
|
||||||
|
read -rp "Forgejo instance URL [$DEFAULT_FORGEJO_URL]: " FORGEJO_URL
|
||||||
|
FORGEJO_URL="${FORGEJO_URL:-$DEFAULT_FORGEJO_URL}"
|
||||||
|
else
|
||||||
read -rp "Forgejo instance URL (e.g. https://git.example.com): " FORGEJO_URL
|
read -rp "Forgejo instance URL (e.g. https://git.example.com): " FORGEJO_URL
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
FORGEJO_URL="${FORGEJO_URL%/}"
|
FORGEJO_URL="${FORGEJO_URL%/}"
|
||||||
|
|
||||||
if [ -z "${KEY_NAME:-}" ]; then
|
if [ -z "${KEY_NAME:-}" ]; then
|
||||||
read -rp "Label for this device's SSH key [travel-laptop]: " KEY_NAME
|
local key_default="${DEFAULT_KEY_NAME:-travel-laptop}"
|
||||||
|
read -rp "Label for this device's SSH key [$key_default]: " KEY_NAME
|
||||||
|
KEY_NAME="${KEY_NAME:-$key_default}"
|
||||||
fi
|
fi
|
||||||
KEY_NAME="${KEY_NAME:-travel-laptop}"
|
|
||||||
KEYFILE="$HOME/.ssh/id_ed25519_${KEY_NAME}"
|
KEYFILE="$HOME/.ssh/id_ed25519_${KEY_NAME}"
|
||||||
|
|
||||||
|
cat > "$config_file" <<EOF
|
||||||
|
DEFAULT_FORGEJO_URL="$FORGEJO_URL"
|
||||||
|
DEFAULT_KEY_NAME="$KEY_NAME"
|
||||||
|
EOF
|
||||||
|
chmod 600 "$config_file"
|
||||||
|
|
||||||
step_ok "config gathered" "FORGEJO_URL=$FORGEJO_URL KEY_NAME=$KEY_NAME"
|
step_ok "config gathered" "FORGEJO_URL=$FORGEJO_URL KEY_NAME=$KEY_NAME"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue