Add initial version of bootstrap script (#48)
This commit is contained in:
parent
a612a98136
commit
08427328f9
1 changed files with 104 additions and 0 deletions
104
bootstrap
Executable file
104
bootstrap
Executable file
|
@ -0,0 +1,104 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# envoke with:
|
||||||
|
# curl -fsSL 'https://tinyurl.com/yadm-bootstrap' | bash [-s -- REPO_URL [YADM_RELEASE]]
|
||||||
|
|
||||||
|
# or
|
||||||
|
|
||||||
|
# curl -fsSL 'https://github.com/TheLocehiliosan/yadm/raw/master/bootstrap' | bash [-s -- REPO_URL [YADM_RELEASE]]
|
||||||
|
|
||||||
|
YADM_REPO="https://github.com/TheLocehiliosan/yadm"
|
||||||
|
YADM_RELEASE="master"
|
||||||
|
REPO_URL=""
|
||||||
|
|
||||||
|
function yadm() {
|
||||||
|
if command -v which >/dev/null 2>&1 && which yadm >/dev/null 2>&1; then
|
||||||
|
echo "Found yadm installed locally, removing remote yadm() function"
|
||||||
|
unset -f yadm
|
||||||
|
command yadm "$@"
|
||||||
|
else
|
||||||
|
echo WARNING: Using yadm remotely. You should install yadm locally.
|
||||||
|
curl -fsSL "$YADM_REPO/raw/$YADM_RELEASE/yadm" | bash -s -- "$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
export -f yadm
|
||||||
|
|
||||||
|
# if being sourced, return here, otherwise continue processing
|
||||||
|
return 2>/dev/null
|
||||||
|
unset -f yadm
|
||||||
|
|
||||||
|
function remote_yadm() {
|
||||||
|
curl -fsSL "$YADM_REPO/raw/$YADM_RELEASE/yadm" | bash -s -- "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
function ask_about_source() {
|
||||||
|
if ! command -v yadm >/dev/null 2>&1; then
|
||||||
|
echo
|
||||||
|
echo "***************************************************"
|
||||||
|
echo "yadm is NOT currently installed."
|
||||||
|
echo "You should install it locally, this link may help:"
|
||||||
|
echo "https://thelocehiliosan.github.io/yadm/docs/install"
|
||||||
|
echo "***************************************************"
|
||||||
|
echo
|
||||||
|
echo "If installation is not possible right now, you can temporarily \"source\""
|
||||||
|
echo "in a yadm() function which fetches yadm remotely each time it is called."
|
||||||
|
echo
|
||||||
|
echo " source <<< curl -fsSL '$YADM_REPO/raw/$YADM_RELEASE/bootstrap'"
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function build_url() {
|
||||||
|
echo "No repo URL provided."
|
||||||
|
echo
|
||||||
|
echo "Where is your repo?"
|
||||||
|
echo
|
||||||
|
echo " 1. GitHub"
|
||||||
|
echo " 2. Bitbucket"
|
||||||
|
echo " 3. Other"
|
||||||
|
echo
|
||||||
|
read -r -p "Where is your repo? (1/2/3) ->" choice < /dev/tty
|
||||||
|
case $choice in
|
||||||
|
1)
|
||||||
|
REPO_URL="https://github.com/"
|
||||||
|
;;
|
||||||
|
2)
|
||||||
|
REPO_URL="https://bitbucket.org/"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo
|
||||||
|
echo Please specify the full URL of your dotfiles repo
|
||||||
|
read -r -p "URL ->" choice < /dev/tty
|
||||||
|
REPO_URL="$choice"
|
||||||
|
return
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo "Provide your user and repo separated by '/'"
|
||||||
|
echo "For example: TheLocehiliosan/dotfiles"
|
||||||
|
echo
|
||||||
|
read -r -p "User/Repo ->" choice < /dev/tty
|
||||||
|
[[ "$choice" =~ ^[^[:space:]]+/[^[:space:]]+$ ]] || {
|
||||||
|
echo "Not formatted as USER/REPO"
|
||||||
|
REPO_URL=
|
||||||
|
return
|
||||||
|
}
|
||||||
|
REPO_URL="${REPO_URL}${choice}.git"
|
||||||
|
}
|
||||||
|
|
||||||
|
function main() {
|
||||||
|
|
||||||
|
[ -n "$1" ] && REPO_URL="$1"
|
||||||
|
[ -n "$2" ] && YADM_RELEASE="$2"
|
||||||
|
[ -z "$REPO_URL" ] && build_url
|
||||||
|
[ -z "$REPO_URL" ] && echo "Unable to determine the repo URL" && exit 1
|
||||||
|
|
||||||
|
echo "Using URL: $REPO_URL"
|
||||||
|
remote_yadm clone "$REPO_URL"
|
||||||
|
|
||||||
|
ask_about_source
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
main "$@"
|
Loading…
Reference in a new issue