forked from ramezsaeed/developer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsinit.sh
executable file
·262 lines (224 loc) · 7.17 KB
/
jsinit.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
set -e
clear
if ! type "curl" > /dev/null; then
echo "curl is not installed, please install"
exit 1
fi
function valid() {
EXITCODE=$?
if [ ${EXITCODE} -ne 0 ]; then
cat /tmp/lastcommandoutput.txt
if [ -z $1 ]; then
echo "Error in last step"
else
echo $1
fi
exit ${EXITCODE}
fi
}
function osx_install {
if ! type "brew" > /dev/null; then
sudo echo "* Install Brew"
yes '' | /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
set +e
sudo echo "* Unlink curl/python/git"
brew unlink curl > /tmp/lastcommandoutput.txt 2>&1
brew unlink python3 > /tmp/lastcommandoutput.txt 2>&1
brew unlink git > /tmp/lastcommandoutput.txt 2>&1
set -e
sudo echo "* Install Python"
brew install --overwrite python3 > /tmp/lastcommandoutput.txt 2>&1
valid
brew link --overwrite python3 > /tmp/lastcommandoutput.txt 2>&1
valid
sudo echo "* Install Git"
brew install git > /tmp/lastcommandoutput.txt 2>&1
valid
brew link --overwrite git > /tmp/lastcommandoutput.txt 2>&1
valid
sudo echo "* Install Curl"
brew install curl > /tmp/lastcommandoutput.txt 2>&1
valid
brew link --overwrite curl > /tmp/lastcommandoutput.txt 2>&1
valid
# brew install snappy
# sudo mkdir -p /optvar
# sudo chown -R $USER /optvar
# sudo mkdir -p /opt
# sudo chown -R $USER /opt
}
function alpine_install {
apk add git > /tmp/lastcommandoutput.txt 2>&1
apk add curl > /tmp/lastcommandoutput.txt 2>&1
apk add python3 > /tmp/lastcommandoutput.txt 2>&1
apk add tmux > /tmp/lastcommandoutput.txt 2>&1
# apk add wget
# apk add python3-dev
# apk add gcc
# apk add make
# apk add alpine-sdk
# apk add snappy-dev
# apk add py3-cffi
# apk add libffi
# apk add libffi-dev
# apk add openssl-dev
# apk add libexecinfo-dev
# apk add linux-headers
# apk add redis
}
function ubuntu_install {
locale-gen en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
apt-get install git
apt-get install curl git ssh python3 -y
# apt-get install python3-pip -y
# apt-get install libssl-dev -y
# apt-get install python3-dev -y
# apt-get install build-essential -y
# apt-get install libffi-dev -y
# apt-get install libsnappy-dev libsnappy1v5 -y
# rm -f /usr/bin/python
# rm -f /usr/bin/python3
# ln -s /usr/bin/python3.5 /usr/bin/python
# ln -s /usr/bin/python3.5 /usr/bin/python3
}
function archlinux_install {
sudo pacman -S --needed git curl openssh python3 --noconfirm
}
function fedora_install {
dnf install -y git curl openssh python3
export PATH=$PATH:/usr/local/bin
}
function cygwin_install {
# Do something under Windows NT platform
export LANG=C; export LC_ALL=C
lynx -source rawgit.com/transcode-open/apt-cyg/master/apt-cyg > apt-cyg
install apt-cyg /bin
apt-cyg install curl
# apt-cyg install python3-dev
# apt-cyg install build-essential
# apt-cyg install openssl-devel
# apt-cyg install libffi-dev
apt-cyg install python3
# apt-cyg install make
# apt-cyg install unzip
apt-cyg install git
ln -sf /usr/bin/python3 /usr/bin/python
}
function getcode {
echo "get code"
cd $CODEDIR/github/jumpscale
if [ ! -e $CODEDIR/github/jumpscale/developer ]; then
set +e
git clone [email protected]:Jumpscale/developer.git
if [ ! $? -eq 0 ]; then
set -ex
git clone https://github.com/Jumpscale/developer.git
fi
set +e
else
cd $CODEDIR/github/jumpscale/developer
git pull
fi
cd $CODEDIR/github/jumpscale
if [ ! -e $CODEDIR/github/jumpscale/core9 ]; then
set +e
git clone [email protected]:Jumpscale/core9.git
if [ ! $? -eq 0 ]; then
set -ex
git clone https://github.com/Jumpscale/core9.git
fi
set +e
else
cd $CODEDIR/github/jumpscale/core9
git pull
fi
}
########MAIN BLOCK#############
echo "* get mascot"
curl https://raw.githubusercontent.com/Jumpscale/developer/master/mascot?$RANDOM > ~/.mascot.txt
valid
clear
cat ~/.mascot.txt
echo
if [ "$(uname)" == "Darwin" ]; then
# Do something under Mac OS X platform
echo "* INSTALL homebrew, curl, python, git"
export LANG=C; export LC_ALL=C
osx_install
elif [ -e /etc/alpine-release ]; then
echo "* INSTALL curl, python, git"
alpine_install
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
echo "* INSTALL curl, python, git"
dist=`grep DISTRIB_ID /etc/*-release | awk -F '=' '{print $2}'`
if [ "$dist" == "Ubuntu" ]; then
ubuntu_install
elif type "pacman" > /dev/null 2>&1; then
archlinux_install
elif type "dnf" > /dev/null 2>&1; then
fedora_install
else
echo "ONLY ARCHLINUX & UBUNTU LINUX SUPPORTED"
exit 1
fi
elif [ "$(expr substr $(uname -s) 1 9)" == "CYGWIN_NT" ]; then
cygwin_install
fi
echo "* get gig environment script"
curl https://raw.githubusercontent.com/Jumpscale/developer/master/jsenv.sh?$RANDOM > ~/.jsenv.sh
valid
echo "* include the gig environment script"
source ~/.jsenv.sh
#THIS GIVES GIG & CODEDIR
#check profile file exists, if yes modify
if [ ! -e $HOMEDIR/.bash_profile ] ; then
touch $HOMEDIR/.bash_profile
else
#make a 1time backup
if [ ! -e "$HOMEDIR/.bash_profile.bak" ]; then
cp $HOMEDIR/.bash_profile $HOMEDIR/.bash_profile.bak
fi
fi
set -e
sed '/export SSHKEYNAME/d' $HOMEDIR/.bash_profile > $HOMEDIR/.bash_profile2
mv $HOMEDIR/.bash_profile2 $HOMEDIR/.bash_profile
sed '/jsenv.sh/d' $HOMEDIR/.bash_profile > $HOMEDIR/.bash_profile2
mv $HOMEDIR/.bash_profile2 $HOMEDIR/.bash_profile
echo export SSHKEYNAME=$SSHKEYNAME >> $HOMEDIR/.bash_profile
echo source ~/.jsenv.sh >> $HOMEDIR/.bash_profile
echo "* create dir's"
export CODEDIR="$GIGDIR/code"
mkdir -p $CODEDIR/github/jumpscale > /tmp/lastcommandoutput.txt 2>&1
valid
echo "* get core code for development scripts & jumpscale core"
getcode > /tmp/lastcommandoutput.txt 2>&1
valid
function linkcode {
echo "* link commands to local environment"
#link all our command lines relevant to jumpscale development env
rm -f /usr/local/bin/js9*
rm -rf /usr/local/bin/cmds*
find $CODEDIR/github/jumpscale/developer/cmds_host -exec chmod 770 {} \;
sudo find $CODEDIR/github/jumpscale/developer/cmds_host -exec ln -s {} "/usr/local/bin/" \;
rm -rf /usr/local/bin/cmds_host
}
linkcode > /tmp/lastcommandoutput.txt 2>&1
valid
#create private dir
mkdir -p $GIGDIR/private
if [ ! -e "$GIGDIR/private/me.toml" ]; then
echo "* copy templates private files."
cp $CODEDIR/github/jumpscale/developer/templates/private/me.toml $GIGDIR/private/ > /tmp/lastcommandoutput.txt 2>&1
valid
fi
echo "* copy chosen sshpub key"
mkdir -p $GIGDIR/private/pubsshkeys
cp ~/.ssh/$SSHKEYNAME.pub $GIGDIR/private/pubsshkeys/ > /tmp/lastcommandoutput.txt 2>&1
valid
trap valid ERR
valid
echo "* please edit templates in $GIGDIR/private/, if you don't then installer will ask for it."
echo "* to get started with jumpscale do 'js9_start', docker needs to be installed locally."