forked from devstructure/ubuntu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
125 lines (111 loc) · 3.02 KB
/
setup.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
# Setup DevStructure.
# Gather credentials.
TMPNAME=$(mktemp devstructure-XXXXXXXXXX)
echo
echo -e "\033[1mGET STARTED WITH DEVSTRUCTURE\033[0m"
echo
while true
do
read -p "Do you have an account? (yes/no/skip) " YESNO
[ -z "$YESNO" ] && YESNO="n"
case "$YESNO" in
# Sign in.
yes|y|Y)
read -p "Email or login: " VALUE
stty -echo
read -p "Password: " PASSWORD
echo
stty echo
case "$VALUE" in
*@*) KEY="email";;
*) KEY="login";;
esac
CODE="$(curl -s -w '%{http_code}\n' -o "$TMPNAME" \
-d "$KEY"="$VALUE" \
-d password="$PASSWORD" \
"https://api.devstructure.com/sign_in" || echo -)";;
# Sign up.
no|n|N)
read -p "Email: " EMAIL
read -p "Login: " LOGIN
stty -echo
read -p "Password: " PASSWORD
echo
read -p "Confirm password: " CONFIRM_PASSWORD
echo
stty echo
[ "$PASSWORD" = "$CONFIRM_PASSWORD" ] || {
echo "Please confirm your password." >&2
continue
}
CODE="$(curl -s -w '%{http_code}\n' -o "$TMPNAME" \
-d email="$EMAIL" \
-d login="$LOGIN" \
-d password="$PASSWORD" \
"https://api.devstructure.com/sign_up" || echo -)";;
# Skip setup for now.
skip|s|S)
echo "Skipping DevStructure setup for now."
break;;
# Ask again.
*) continue;;
esac
# Successful sign in or sign up breaks out of the loop. Everyone
# else gets a message and heads back to the top.
case "$CODE" in
200) ;;
400)
echo "Invalid account credentials, please try again." >&2
continue;;
401)
echo "Password doesn't match, please try again.">&2
continue;;
409)
echo "That email or login is already registered." >&2
continue;;
-)
echo "Please try again when you're connected to the Internet." >&2
echo " sh /etc/profile.d/setup.sh" >&2
break;;
*)
echo "DevStructure is having problems." >&2
continue;;
esac
# Parse out the DevStructure API token.
TMP=$(tr , \\n <"$TMPNAME" | tr -d \"\{\})
LOGIN=$(echo "$TMP" | grep ^login | cut -c7-)
TOKEN=$(echo "$TMP" | grep ^token | cut -c7-)
[ -z "$TOKEN" ] && {
echo "No DevStructure API token found." >&2
echo -e \
"Please contact us at \033[[email protected]\033[0m." >&2
break
}
# Store the DevStructure API token for later.
echo "$LOGIN" >~/.login
echo "$TOKEN" >~/.token
# Install the DevStructure software.
echo
echo "One moment while we upgrade the DevStructure packages..."
echo
sudo apt-get update
sudo apt-get -y install sandbox blueprint
# Now the complete welcome message.
echo
echo -e "\033[1mWELCOME TO DEVSTRUCTURE\033[0m"
echo
echo -e "Get started by creating a sandbox: " \
"\033[4msandbox create my-first-sandbox\033[0m"
echo
echo -e "Work there to keep your server clean: " \
"\033[4msandbox use my-first-sandbox\033[0m"
echo
echo -e "And when you're ready to deploy: " \
"\033[4mblueprint create my-first-blueprint\033[0m"
echo
echo -e "Learn more at \033[4mhttp://docs.devstructure.com/start\033[0m"
# This run was successful so setup.sh is no longer necessary.
sudo rm /etc/profile.d/setup.sh
break
done
rm -f "$TMPNAME"