forked from larstobi/bootstrap-puppet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.functions.sh
96 lines (83 loc) · 1.54 KB
/
bootstrap.functions.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
function package_installed {
name=$1
if `rpm -q $name 1>/dev/null`; then
return 0
else
return 1
fi
}
function install_package {
`yum install --quiet -y $1 1>/dev/null`
RET=$?
if [ $RET == 0 ]; then
return 0
else
echo "ERROR: Could not install package $1"
exit 1
fi
}
function ensure_package_installed {
if ! package_installed $1 ; then
echo "Installing ${1}"
install_package $1
fi
}
function ensure_packages_installed {
for package in $1; do
ensure_package_installed $package
done
}
function user_present {
if `grep -q "^$1:" /etc/passwd`; then
return 0
else
return 1
fi
}
function ensure_user_present {
if ! user_present $1; then
echo "Adding user $1"
DIR=/var/empty/$1
useradd -d $DIR $1
chown root:root $DIR
chmod 711 $DIR
fi
}
function ensure_directory_absent {
if [ "${1}" == "/" ]; then
echo "ERROR: Trying to delete root filesystem."
exit 1
else
echo "rm -rf ${1}"
rm -rf "${1}"
fi
}
function ensure_directory {
if ! [ -d "${1}" ]; then
mkdir "${1}"
fi
}
function download_file {
cd $BOOTSTRAP_DIR
wget --quiet --no-check-certificate ${URL}${1}
}
function ensure_file_absent {
rm -f "${1}"
}
function ensure_file {
path=$1
source=$2
if ! [ -f $source ]; then
download_file $source
fi
if ! [ -f $path ]; then
cp $BOOTSTRAP_DIR/$source $path && \
return 0
elif ! diff -q $BOOTSTRAP_DIR/$source $path; then
return 0
fi
}
function exec_puppet_apply {
manifest=$1
puppet apply $manifest
}