2017-01-27 18:09:48 -05:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-02-08 23:38:51 -05:00
|
|
|
#
|
|
|
|
# This script can be "curl-piped" into bash to bootstrap a dotfiles repo when
|
|
|
|
# yadm is not locally installed. Read below for instructions.
|
|
|
|
#
|
2019-11-07 21:36:53 -05:00
|
|
|
# This script is hosted at bootstrap.yadm.io to make it easy to remember/type.
|
|
|
|
#
|
2017-02-08 23:38:51 -05:00
|
|
|
# DISCLAIMER: In general, I would advise against piping someone's code directly
|
|
|
|
# from the Internet into an interpreter (like Bash). You should
|
|
|
|
# probably review any code like this prior to executing it. I leave
|
|
|
|
# it to you to decide if this is risky behavior or not. The main
|
|
|
|
# reason this script exists is because I find it to be a pragmatic
|
|
|
|
# way to bootstrap my dotfiles, and install yadm in one step
|
|
|
|
# (allowing the yadm project to be a submodule of my dotfiles
|
|
|
|
# repo).
|
|
|
|
#
|
2019-11-07 21:36:53 -05:00
|
|
|
# Invoke bootstrap with:
|
|
|
|
#
|
|
|
|
# curl -L bootstrap.yadm.io | bash
|
|
|
|
#
|
|
|
|
# OR
|
|
|
|
#
|
|
|
|
# curl -L bootstrap.yadm.io | bash [-s -- REPO_URL [YADM_RELEASE]]
|
2017-02-08 23:38:51 -05:00
|
|
|
#
|
2019-11-07 21:36:53 -05:00
|
|
|
# Alternatively, source in this file to export a yadm() function which uses
|
|
|
|
# yadm remotely until it is locally installed.
|
2017-02-08 23:38:51 -05:00
|
|
|
#
|
2019-11-07 21:36:53 -05:00
|
|
|
# source <(curl -L bootstrap.yadm.io)
|
2017-02-08 23:38:51 -05:00
|
|
|
#
|
2017-01-27 18:09:48 -05:00
|
|
|
|
2024-10-30 18:18:49 -04:00
|
|
|
YADM_REPO="https://github.com/yadm-dev/yadm"
|
2019-11-07 21:36:53 -05:00
|
|
|
YADM_RELEASE=${release:-master}
|
2017-01-27 18:09:48 -05:00
|
|
|
REPO_URL=""
|
|
|
|
|
2019-11-07 21:36:53 -05:00
|
|
|
function _private_yadm() {
|
|
|
|
unset -f yadm
|
2024-12-11 14:05:16 -05:00
|
|
|
if command -v yadm &>/dev/null; then
|
2017-01-27 18:09:48 -05:00
|
|
|
echo "Found yadm installed locally, removing remote yadm() function"
|
2019-11-07 21:36:53 -05:00
|
|
|
unset -f _private_yadm
|
2017-01-27 18:09:48 -05:00
|
|
|
command yadm "$@"
|
|
|
|
else
|
2024-12-11 14:05:16 -05:00
|
|
|
function yadm() { _private_yadm "$@"; }
|
|
|
|
export -f yadm
|
2017-01-27 18:09:48 -05:00
|
|
|
echo WARNING: Using yadm remotely. You should install yadm locally.
|
|
|
|
curl -fsSL "$YADM_REPO/raw/$YADM_RELEASE/yadm" | bash -s -- "$@"
|
|
|
|
fi
|
|
|
|
}
|
2019-11-07 21:36:53 -05:00
|
|
|
export -f _private_yadm
|
2024-12-11 14:05:16 -05:00
|
|
|
function yadm() { _private_yadm "$@"; }
|
|
|
|
export -f yadm
|
2017-01-27 18:09:48 -05:00
|
|
|
|
|
|
|
# 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() {
|
2024-12-11 14:05:16 -05:00
|
|
|
if ! command -v yadm &>/dev/null; then
|
2017-01-27 18:09:48 -05:00
|
|
|
echo
|
|
|
|
echo "***************************************************"
|
|
|
|
echo "yadm is NOT currently installed."
|
|
|
|
echo "You should install it locally, this link may help:"
|
2019-11-07 21:36:53 -05:00
|
|
|
echo "https://yadm.io/docs/install"
|
2017-01-27 18:09:48 -05:00
|
|
|
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
|
2019-11-07 21:36:53 -05:00
|
|
|
echo " source <(curl -L bootstrap.yadm.io)"
|
2017-01-27 18:09:48 -05:00
|
|
|
echo
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function build_url() {
|
|
|
|
echo "No repo URL provided."
|
|
|
|
echo
|
|
|
|
echo "Where is your repo?"
|
|
|
|
echo
|
|
|
|
echo " 1. GitHub"
|
|
|
|
echo " 2. Bitbucket"
|
2017-02-03 08:38:57 -05:00
|
|
|
echo " 3. GitLab"
|
|
|
|
echo " 4. Other"
|
2017-01-27 18:09:48 -05:00
|
|
|
echo
|
2024-12-11 14:05:16 -05:00
|
|
|
read -r -p "Where is your repo? (1/2/3/4) ->" choice </dev/tty
|
2017-01-27 18:09:48 -05:00
|
|
|
case $choice in
|
|
|
|
1)
|
|
|
|
REPO_URL="https://github.com/"
|
|
|
|
;;
|
|
|
|
2)
|
|
|
|
REPO_URL="https://bitbucket.org/"
|
|
|
|
;;
|
2017-02-03 08:38:57 -05:00
|
|
|
3)
|
|
|
|
REPO_URL="https://gitlab.com/"
|
|
|
|
;;
|
2017-01-27 18:09:48 -05:00
|
|
|
*)
|
|
|
|
echo
|
|
|
|
echo Please specify the full URL of your dotfiles repo
|
2024-12-11 14:05:16 -05:00
|
|
|
read -r -p "URL ->" choice </dev/tty
|
2017-01-27 18:09:48 -05:00
|
|
|
REPO_URL="$choice"
|
|
|
|
return
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Provide your user and repo separated by '/'"
|
2017-02-09 00:06:00 -05:00
|
|
|
echo "For example: UserName/dotfiles"
|
2017-01-27 18:09:48 -05:00
|
|
|
echo
|
2024-12-11 14:05:16 -05:00
|
|
|
read -r -p "User/Repo ->" choice </dev/tty
|
2017-01-27 18:09:48 -05:00
|
|
|
[[ "$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 "$@"
|