-
Notifications
You must be signed in to change notification settings - Fork 177
/
bootstrap
executable file
·133 lines (119 loc) · 3.64 KB
/
bootstrap
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
#
# This script can be "curl-piped" into bash to bootstrap a dotfiles repo when
# yadm is not locally installed. Read below for instructions.
#
# This script is hosted at bootstrap.yadm.io to make it easy to remember/type.
#
# 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).
#
# Invoke bootstrap with:
#
# curl -L bootstrap.yadm.io | bash
#
# OR
#
# curl -L bootstrap.yadm.io | bash [-s -- REPO_URL [YADM_RELEASE]]
#
# Alternatively, source in this file to export a yadm() function which uses
# yadm remotely until it is locally installed.
#
# source <(curl -L bootstrap.yadm.io)
#
YADM_REPO="https://github.com/yadm-dev/yadm"
YADM_RELEASE=${release:-master}
REPO_URL=""
function _private_yadm() {
unset -f yadm
if command -v yadm &> /dev/null; then
echo "Found yadm installed locally, removing remote yadm() function"
unset -f _private_yadm
command yadm "$@"
else
function yadm() { _private_yadm "$@"; }; export -f yadm
echo WARNING: Using yadm remotely. You should install yadm locally.
curl -fsSL "$YADM_REPO/raw/$YADM_RELEASE/yadm" | bash -s -- "$@"
fi
}
export -f _private_yadm
function yadm() { _private_yadm "$@"; }; 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; then
echo
echo "***************************************************"
echo "yadm is NOT currently installed."
echo "You should install it locally, this link may help:"
echo "https://yadm.io/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 -L bootstrap.yadm.io)"
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. GitLab"
echo " 4. Other"
echo
read -r -p "Where is your repo? (1/2/3/4) ->" choice < /dev/tty
case $choice in
1)
REPO_URL="https://github.com/"
;;
2)
REPO_URL="https://bitbucket.org/"
;;
3)
REPO_URL="https://gitlab.com/"
;;
*)
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: UserName/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 "$@"