Publish authenticated workstation bootstrap
This commit is contained in:
25
bootstrap.sh
25
bootstrap.sh
@@ -15,10 +15,6 @@ if ! command -v git >/dev/null || ! command -v python3 >/dev/null; then
|
|||||||
*) echo "Bootstrap package adapter unavailable for $ID." >&2; exit 1 ;;
|
*) echo "Bootstrap package adapter unavailable for $ID." >&2; exit 1 ;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
read -r -p 'Gitea username: ' CARR_GITEA_USER </dev/tty
|
|
||||||
read -r -s -p 'Gitea access token (read access to workstation repository): ' CARR_GITEA_TOKEN </dev/tty
|
|
||||||
printf '\n'
|
|
||||||
export CARR_GITEA_USER CARR_GITEA_TOKEN
|
|
||||||
carr_auth_dir=$(mktemp -d)
|
carr_auth_dir=$(mktemp -d)
|
||||||
carr_stage_dir=''
|
carr_stage_dir=''
|
||||||
trap 'unset CARR_GITEA_TOKEN CARR_GITEA_USER; rm -rf -- "$carr_auth_dir"; if [[ -n "$carr_stage_dir" ]]; then rm -rf -- "$carr_stage_dir"; fi' EXIT
|
trap 'unset CARR_GITEA_TOKEN CARR_GITEA_USER; rm -rf -- "$carr_auth_dir"; if [[ -n "$carr_stage_dir" ]]; then rm -rf -- "$carr_stage_dir"; fi' EXIT
|
||||||
@@ -39,7 +35,26 @@ if [[ -e "$carr_checkout" ]]; then
|
|||||||
fi
|
fi
|
||||||
mkdir -p -- "$(dirname -- "$carr_checkout")"
|
mkdir -p -- "$(dirname -- "$carr_checkout")"
|
||||||
carr_stage_dir=$(mktemp -d "$(dirname -- "$carr_checkout")/.carr-clone-XXXXXX")
|
carr_stage_dir=$(mktemp -d "$(dirname -- "$carr_checkout")/.carr-clone-XXXXXX")
|
||||||
git -c credential.helper= clone --no-checkout -- "https://git.carr.pub/$CARR_GITEA_USER/workstation.git" "$carr_stage_dir"
|
while true; do
|
||||||
|
read -r -p 'Gitea username [adamcarr]: ' CARR_GITEA_USER </dev/tty
|
||||||
|
CARR_GITEA_USER=${CARR_GITEA_USER:-adamcarr}
|
||||||
|
echo 'Paste your token, then press Enter. Token characters are hidden.' >/dev/tty
|
||||||
|
read -r -s -p 'Gitea access token (read:repository, private access): ' CARR_GITEA_TOKEN </dev/tty
|
||||||
|
printf '\n' >/dev/tty
|
||||||
|
if [[ -z "$CARR_GITEA_TOKEN" ]]; then
|
||||||
|
echo 'No token received. Please try again.' >/dev/tty
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
export CARR_GITEA_USER CARR_GITEA_TOKEN
|
||||||
|
if git -c credential.helper= clone --no-checkout -- "https://git.carr.pub/$CARR_GITEA_USER/workstation.git" "$carr_stage_dir"; then
|
||||||
|
echo 'Authenticated repository download succeeded.' >/dev/tty
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
unset CARR_GITEA_TOKEN
|
||||||
|
echo 'Download failed. Check the account, private repository permission, and network; retry or press Ctrl+C.' >/dev/tty
|
||||||
|
rm -rf -- "$carr_stage_dir"
|
||||||
|
carr_stage_dir=$(mktemp -d "$(dirname -- "$carr_checkout")/.carr-clone-XXXXXX")
|
||||||
|
done
|
||||||
git -C "$carr_stage_dir" checkout --detach "$ref"
|
git -C "$carr_stage_dir" checkout --detach "$ref"
|
||||||
mv -- "$carr_stage_dir" "$carr_checkout"
|
mv -- "$carr_stage_dir" "$carr_checkout"
|
||||||
carr_stage_dir=''
|
carr_stage_dir=''
|
||||||
|
|||||||
Reference in New Issue
Block a user