-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·100 lines (87 loc) · 2.65 KB
/
install.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
#!/bin/bash
cd `dirname $0`
RUBY_VERSION="`cat ./.ruby-version`"
#install rbenv
sudo apt-get install -y \
openssh-server \
git \
zlib1g-dev \
libssl-dev \
g++ \
autoconf \
make \
gcc
if [ ! -d ~/.rbenv ]; then
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
else
sh -c "cd ~/.rbenv; git fetch; git rebase origin/master;"
sh -c "cd ~/.rbenv/plugins/ruby-build; git fetch; git rebase origin/master;"
fi
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
#install ruby and bundle
if [ "`rbenv versions | grep ${RUBY_VERSION}`" = "" ]; then
rbenv install "${RUBY_VERSION}"
else
echo "ruby ${RUBY_VERSION} is installed"
fi
#set ruby
rbenv local "${RUBY_VERSION}"
rbenv rehash
rbenv exec gem i bundler --no-ri --no-rdoc
rbenv rehash
# install pakagees of bundle and beaks
rbenv exec bundle install --path=.bundle
rbenv exec bundle update
rbenv exec bundle exec berks vendor ./cookbooks
rbenv exec bundle exec berks update
#Set up Hostname
if [ "$1" = "" ]; then
HostName="localhost"
#put tmp ssh keys
if [ ! -d ~/.ssh ]; then
echo ~/.ssh is not found. put tmp ssh keys
mkdir ~/.ssh && chmod 700 ~/.ssh
cp ./.tmpsshkeys/id_rsa ~/.ssh/id_rsa && chmod 600 ~/.ssh/id_rsa
cp ./.tmpsshkeys/id_rsa.pub ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys
cp ./.tmpsshkeys/id_rsa.pub ~/.ssh/id_rsa.pub && chmod 644 ~/.ssh/id_rsa.pub
ssh-keyscan localhost >> ~/.ssh/known_hosts
echo "Host localhost\nStrictHostKeyChecking no" > ~/.ssh/config
touch ./.tmpsshkeys/put
fi
# install chef-client
if ! builtin command -v chef-client >> /dev/null ; then
echo chef-client is not installed on this PC
echo chef-client install
sudo apt-get install curl bash
curl -L https://www.opscode.com/chef/install.sh | sudo bash
fi
else
HostName=$1
fi
#install chef
if [ "$2" = "init" ]; then
echo "install chef ${HostName}"
rbenv exec bundle exec knife solo prepare ${HostName}
fi
## if submodule is not init
if [ ! -d ./private-cookbooks/nodes ]; then
mkdir tmpnodes
for node in `ls -1 ./nodes/*`; do
if [ -L $node ]; then
mv $node ./tmpnodes/
fi
done
trap "mv ./tmpnodes/* ./nodes; rm -r ./tmpnodes" EXIT
fi
##cook
rbenv exec bundle exec knife solo cook ${HostName}
if [ -f ./.tmpsshkeys/put ]; then
echo rm tmp ssh keys
rm ~/.ssh/id_rsa
rm ~/.ssh/id_rsa.pub
rm ~/.ssh/known_hosts
rm ~/.ssh/config
rm ./.tmpsshkeys/put
fi