forked from butterproject/butter-desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_butter.sh
executable file
·195 lines (181 loc) · 5.45 KB
/
make_butter.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/bin/sh
## Version 0.1.1
##
## Usage
## ./make_butter.sh [url]
##
## The script make_butter.sh allows you to clone, setup, and build a version of Butter
## The [url] handle is optional and allows you to pick what repository you wish to clone
## If you use 'ssh' in the place of the optional [url] parameter, it will clone via ssh instead of http
##
## Optionally, you can also pass in a specific branch to build or clone, by making url contain a branch specifier
## ./make_butter.sh '-b release/0.3.4 https://github.com/butterproject/butter-desktop'
##
clone_repo="True"
if [ -z "$1" ]; then
clone_url="https://github.com/butterproject/butter-desktop.git"
elif [ "$1" = "ssh" ]; then
clone_url="ssh://git@github.com:butterproject/butter-desktop.git"
else
clone_url="$1"
fi
execsudo() {
case $OSTYPE in msys*)
echo $OSTYPE
$1
;;
*)
sudo $1
;;
esac
}
clone_command() {
if git clone $clone_url $dir; then
echo "Cloned Butter successfully"
else
echo "Butter encountered an error and could not be cloned"
exit 2
fi
}
if [ -e ".git/config" ]; then
dat=$(grep url .git/config)
case $dat in *butter*)
echo "You appear to be inside of a Butter repository already, not cloning"
clone_repo="False"
;;
*)
try="True"
tries=0
while [ "$try" = "True" ]; do
read -p "Looks like we are inside a git repository, do you wish to clone inside it? (yes/no) [no] " rd_cln
if [ -z "$rd_cln" ]; then
rd_cln='no'
fi
tries=$((tries+1))
if [ "$rd_cln" = "yes" ] || [ "$rd_cln" = "no" ]; then
try="False"
elif [ "$tries" -ge "3" ]; then
echo "No valid input, exiting"
exit 1
else
echo "Not a valid answer, please try again"
fi
done
if [ "$rd_cln" = "no" ]; then
echo "You appear to be inside of a Butter repository already, not cloning"
clone_repo="False"
else
echo "You've chosen to clone inside the current directory"
fi
;;
esac
fi
if [ "$clone_repo" = "True" ]; then
echo "Cloning Butter"
read -p "Where do you wish to clone butter to? [butter] " dir
if [ -z "$dir" ]; then
dir='butter'
elif [ "$dir" = "/" ]; then
dir='butter'
fi
if [ ! -d "$dir" ]; then
clone_command
else
try="True"
tries=0
while [ "$try" = "True" ]; do
read -p "Directory $dir already exists, do you wish to delete it and redownload? (yes/no) [no] " rd_ans
if [ -z "$rd_ans" ]; then
rd_ans='no'
fi
tries=$((tries+1))
if [ "$rd_ans" = "yes" ] || [ "$rd_ans" = "no" ]; then
try="False"
elif [ "$tries" -ge "3" ]; then
echo "No valid input, exiting"
exit 3
else
echo "Not a valid answer, please try again"
fi
done
if [ "$rd_ans" = "yes" ]; then
echo "Removing old directory"
if [ "$dir" != "." ] || [ "$dir" != "$PWD" ]; then
echo "Cleaning up from inside the destination directory"
sudo rm -rf $dir/*
else
echo "Cleaning up from outside the destination directory"
sudo rm -rf $dir
fi
clone_command
else
echo "Directory already exists and you've chosen not to clone again"
fi
fi
fi
try="True"
tries=0
while [ "$try" = "True" ]; do
read -p "Do you wish to install the required dependencies for Butter and setup for building? (yes/no) [yes] " rd_dep
if [ -z "$rd_dep" ]; then
rd_dep="yes"
fi
tries=$((tries+1))
if [ "$rd_dep" = "yes" ] || [ "$rd_dep" = "no" ]; then
try="False"
elif [ "$tries" -ge "3" ]; then
echo "No valid input, exiting"
exit 3
else
echo "Not a valid answer, please try again"
fi
done
if [ -z "$dir" ]; then
dir="."
fi
cd $dir
echo "Switched to $PWD"
if [ "$rd_dep" = "yes" ]; then
echo "Installing global dependencies"
if execsudo "npm install -g bower grunt-cli"; then
echo "Global dependencies installed successfully!"
else
echo "Global dependencies encountered an error while installing"
exit 4
fi
echo "Installing local dependencies"
if execsudo "npm install"; then
echo "Local dependencies installed successfully!"
else
echo "Local dependencies encountered an error while installing"
exit 4
fi
curh=$HOME
case $OSTYPE in msys*)
;;
*)
if execsudo "chown -R $USER ." && execsudo "chown -R $USER $curh/.cache"; then
echo "Local permissions corrected successfully!"
else
echo "Local permissions encountered an error while correcting"
exit 4
fi
;;
esac
echo "Setting up Bower"
if bower install; then
echo "Bower successfully installed"
else
echo "Encountered an error while installing bower"
exit 4
fi
echo "Successfully setup for Butter"
fi
if grunt build; then
echo "Butter built successfully!"
echo "Run 'grunt start' from inside the repository to launch the app"
echo "Enjoy!"
else
echo "Butter encountered an error and couldn't be built"
exit 5
fi