forked from Nordstrom/chefdk_bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap
executable file
·128 lines (106 loc) · 3.92 KB
/
bootstrap
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
#!/usr/bin/env bash
# Copyright 2015 Nordstrom, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
set -o nounset -o pipefail
CHEFDK_TARGET_VERSION=0.10.0
function prompt_continue () {
echo ""
echo "chefdk_bootstrap encountered an error in the previous step."
read -p "Ignore the error and contine with installation? [yN] " </dev/tty
case "$REPLY" in
[yY]*) return
;;
*) echo "Not cleaning up $tempInstallDir; exiting."
exit 2
;;
esac
}
# If the user has not passed in a cookbook name use 'chefdk_bootstrap' for the cookbook
bootstrapCookbook=${1:-chefdk_bootstrap}
# If the user has passed in a private supermarket url then add it to the Berksfile
private_source=${2:+source \'$2\'}
# make temp installation directory variable
tempInstallDir="/tmp/chefdk_bootstrap_$$"
[[ ! -d "$tempInstallDir" ]] && mkdir "$tempInstallDir"
clear
# introduction
cat <<EOF;
This script will:
1. Install the latest ChefDK package
2. Create some chef directories in your user profile (home) directory
~/.chef
~/chef
~/chef/cookbooks
3. Download the 'chefdk_bootstrap' cookbook via Berkshelf
4. Run 'chef-client' to install the rest of the tools you will need
EOF
#NOTE: this should be moved into the mac_os_x recipe, issue #43
[[ ! -d ~/.chef ]] && mkdir ~/.chef
[[ ! -d ~/chef ]] && mkdir ~/chef
[[ ! -d ~/chef/cookbooks ]] && mkdir ~/chef/cookbooks
# create Berksfile so that we can install the correct cookbook dependencies
cat > "${tempInstallDir}/Berksfile" <<EOF;
source 'https://supermarket.chef.io'
$private_source
cookbook '$bootstrapCookbook'
EOF
# create client.rb file so that Chef client can find its dependant cookbooks
cat > "${tempInstallDir}/client.rb" <<EOF;
cookbook_path File.join(Dir.pwd, 'berks-cookbooks')
Ohai::Config[:disabled_plugins] = [:Passwd]
EOF
cat <<EOF;
** Installing ChefDK
EOF
chefdk_installed_version=$(chef --version 2>/dev/null |awk '/Chef Development Kit Version:/ {print $NF}')
case "$chefdk_installed_version" in
"$CHEFDK_TARGET_VERSION")
echo "ChefDK ${CHEFDK_TARGET_VERSION} is already installed, skipping"
INSTALL_CHEFDK=0;;
"")
# ChefDK is not installed
INSTALL_CHEFDK=1;;
*)
echo "Replacing ChefDK ${chefdk_installed_version} with ${CHEFDK_TARGET_VERSION}"
echo "Uninstalling ChefDK ${chefdk_installed_version}..."
sudo rm -rf /opt/chefdk
sudo find /usr/bin /usr/local/bin -lname '/opt/chefdk/*' -delete
rm -rf ~/.chefdk
INSTALL_CHEFDK=1;;
esac
if [[ "$INSTALL_CHEFDK" -eq 1 ]]
then
echo "Installing ChefDK ${CHEFDK_TARGET_VERSION}"
curl https://omnitruck.chef.io/install.sh | \
sudo -E bash -s -- -c stable -P chefdk -v ${CHEFDK_TARGET_VERSION} || prompt_continue
fi
echo "Downloading cookbook dependencies with Berkshelf"
cd "$tempInstallDir"
chef exec berks vendor || prompt_continue
echo "Running chef-client (installed by ChefDK) to bootstrap this machine"
sudo -E chef-client -z -l error -c "${tempInstallDir}/client.rb" -o "$bootstrapCookbook" || prompt_continue
# cleanup
cd -
rm -f "$tempInstallDir/Berksfile"
rm -f "$tempInstallDir/Berksfile.lock"
rm -f "$tempInstallDir/client.rb"
rm -rf "$tempInstallDir/berks-cookbooks"
rmdir "$tempInstallDir"
#End message to direct Mac users to last step in set up
cat <<EOF;
You're almost done!!! You just need to edit your shell startup script to set up
chefdk environment variables for each login. See this page:
https://github.com/chef/chef-dk#using-chefdk-as-your-primary-development-environment
EOF