-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbootstrap.sh
executable file
·130 lines (104 loc) · 3.76 KB
/
bootstrap.sh
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
#! /usr/bin/env bash
# ----------------------------------------------------------------------------
# bootstrap *this* repository from an url
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# setup
# ----------------------------------------------------------------------------
appl="handsOn"
download_url="https://github.com/return42/${appl}/raw/master/bootstrap.sh"
git_clone_url="https://github.com/return42/${appl}.git"
BASE_PACKAGES="git"
INSTALL_CMD="sudo -H ./scripts/ubuntu_install_pkgs.sh bootstrap"
# ----------------------------------------------------------------------------
main(){
# ----------------------------------------------------------------------------
case $1 in
usage)
usage
;;
*)
bootstrap
;;
esac
}
# ----------------------------------------------------------------------------
usage() {
# ----------------------------------------------------------------------------
cat <<EOF
usage:
cd /folder/where/to/place/repository/clone/in
wget --no-check -O /tmp/bs.sh "$download_url" ; bash /tmp/bs.sh
EOF
}
# ----------------------------------------------------------------------------
bootstrap() {
# ----------------------------------------------------------------------------
rstHeading "Bootstraping $appl" part
rstHeading "Install bootstrap requirements" chapter
rstPkgList ${BASE_PACKAGES}
waitKEY
sudo -H apt-get install -y ${BASE_PACKAGES}
rstHeading "cloning $appl --> $PWD/$appl" chapter
waitKEY
if [[ ! -z ${SUDO_USER} ]]; then
sudo -u ${SUDO_USER} git clone "$git_clone_url" "$PWD/$appl"
else
git clone "$git_clone_url" "$PWD/$appl"
fi
cd "$PWD/$appl"
$INSTALL_CMD
}
# ----------------------------------------------------------------------------
err_msg() {
# ----------------------------------------------------------------------------
printf "ERROR: $*\n" >&2
}
# ----------------------------------------------------------------------------
rstHeading() {
# ----------------------------------------------------------------------------
# usage:rstHeading <header-text> [part|chapter|section]
case ${2-chapter} in
part) printf "\n${1//?/=}\n$1\n${1//?/=}\n";;
chapter) printf "\n${1}\n${1//?/=}\n";;
section) printf "\n${1}\n${1//?/-}\n";;
*)
err_msg "invalid argument '${2}' in line $(caller)"
return 42
;;
esac
}
# ----------------------------------------------------------------------------
rstBlock() {
# ----------------------------------------------------------------------------
echo -en "\n$*\n" | fmt
}
# ----------------------------------------------------------------------------
rstPkgList() {
# ----------------------------------------------------------------------------
echo -en "\npackage::\n\n $*\n" | fmt
}
# ----------------------------------------------------------------------------
cleanStdIn() {
# ----------------------------------------------------------------------------
if [[ $(uname -s) != 'Darwin' ]]; then
while $(read -n1 -t 0.1); do : ; done
fi
}
# ----------------------------------------------------------------------------
waitKEY(){
# ----------------------------------------------------------------------------
# usage: waitKEY [<timeout in sec>]
local _t=$1
[[ ! -z $FORCE_TIMEOUT ]] && _t=$FORCE_TIMEOUT
[[ ! -z $_t ]] && _t="-t $_t"
shift
cleanStdIn
echo
read -n1 $_t -p "** press any [KEY] to continue **"
printf "\n"
cleanStdIn
}
# ----------------------------------------------------------------------------
main "$@"
# ----------------------------------------------------------------------------