-
Notifications
You must be signed in to change notification settings - Fork 2
/
install_server.sh
executable file
·158 lines (141 loc) · 4.94 KB
/
install_server.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
#!/bin/bash
## Setting neccessary variables
HERE="$(dirname "$(readlink -f "${0}")")";
## Set this according to your puppet modules directory
## shipped with your puppet installation
PUPPET_MODULE_PATH="/usr/share/puppet/modules/";
centos_requirements(){
if ! rpm -qa | grep -q "puppet-agent\|puppetlabs-stdlib";
then
if ! rpm -qa | grep -q "epel-release-latest\|puppet8-release";
then
yum install -y "https://dl.fedoraproject.org/pub/epel/epel-release-latest-${DISTRO_VERSION}.noarch.rpm" "https://yum.puppetlabs.com/puppet8/el/${DISTRO_VERSION}/x86_64/puppet8-release-1.0.0-3.el${DISTRO_VERSION}.noarch.rpm" git;
fi
yum install -y "puppet-agent";
rpm --import https://download.opensuse.org/repositories/home:/seilerphilipp:/opentracker/AlmaLinux_9/repodata/repomd.xml.key
fi;
if [ -f /etc/profile.d/puppet.sh ];
then
if ! which puppet > /dev/null;
then
source /etc/profile.d/puppet.sh;
fi;
else
# Creating search path for puppet binary for bash
echo "#!/bin/bash" > /etc/profile.d/puppet.sh;
echo "PATH=\"\${PATH}:/opt/puppetlabs/puppet/bin\"" >> /etc/profile.d/puppet.sh;
fi;
}
suse_requirements(){
local PUPPET5_REPO="https://yum.puppetlabs.com/puppet8/sles/15/x86_64/"
local PUPPETLABS_REPO="https://download.opensuse.org/repositories/home:/seilerphilipp:/puppet/openSUSE_Leap_15.1/"
local OPENTRACKER_REPO="https://download.opensuse.org/repositories/home:/seilerphilipp:/opentracker/openSUSE_Leap_15.1/"
if ! rpm -qa | grep -q "puppet-agent";
then
if ! zypper repos --uri | grep -qi "${PUPPET5_REPO}";
then
zypper addrepo -f "${PUPPET5_REPO}" "puppet8";
fi;
zypper install -y "puppet-agent";
fi;
if ! rpm -qa | grep -q "puppetlabs-stdlib";
then
if ! zypper repos --uri | grep -qi "${PUPPETLABS_REPO}";
then
zypper addrepo -f "${PUPPETLABS_REPO}" "puppetlabs";
fi
zypper --gpg-auto-import-keys refresh
zypper install -y "puppetlabs-stdlib";
fi;
if ! rpm -qa | grep -q "opentracker";
then
if ! zypper repos --uri | grep -qi "${OPENTRACKER_REPO}";
then
zypper addrepo -f "${OPENTRACKER_REPO}" "opentracker";
fi
zypper --gpg-auto-import-keys refresh
fi;
if [ -f /etc/profile.d/puppet.sh ];
then
if ! which puppet &> /dev/null;
then
source /etc/profile.d/puppet.sh;
fi;
else
# Creating search path for puppet binary for bash
echo "#!/bin/bash" > /etc/profile.d/puppet.sh;
echo "PATH=\"\${PATH}:/opt/puppetlabs/puppet/bin\"" >> /etc/profile.d/puppet.sh;
fi;
}
if [ $UID -ne 0 ];
then
echo "run the script as root";
exit 1;
fi;
# get distribution
if [ -e "/etc/os-release" ];
then
DISTRO=$(grep "^ID=" "/etc/os-release" | cut -d"=" -f2| sed 's/"//g');
if grep "^VERSION_ID=" "/etc/os-release" | tr -d '"' | cut -d"=" -f2 | grep -q '\.'
then
DISTRO_VERSION=$(grep "^VERSION_ID=" "/etc/os-release" | tr -d '"' | cut -d"=" -f2 | cut -d'.' -f1);
else
DISTRO_VERSION=$(grep "^VERSION_ID=" "/etc/os-release" | tr -d '"' | cut -d"=" -f2);
fi
else
echo "Linux distribution not found.";
echo "Maybe the file \"/etc/os-release\" is just missing.";
echo "Or your linux distribution is too old.";
exit 1;
fi;
### checking if distribution is fupported.
### Preparing everything every repo to deploy puppet code and install rpms.
case "${DISTRO}" in
centos|redhat|almalinux)
centos_requirements
;;
opensuse-leap)
suse_requirements
;;
*)
echo "The distribution \"${DISTRO}\" is not supported.";
echo "Sorry.";
exit 1;
;;
esac;
# Creating search path for puppet binary for csh
if [ ! -e /etc/profile.d/puppet.csh ];
then
echo "#!/bin/csh" > /etc/profile.d/puppet.csh;
echo "PATH=\"\${PATH}:/opt/puppetlabs/puppet/bin\"" >> /etc/profile.d/puppet.csh;
fi;
# checkout submodules when git is used
if [ -d ${HERE}/.git ]
then
git submodule update --init;
fi
# check for puppet binary
if [ ! -e "$(which puppet)" ];
then
echo '"puppet" binary not found.';
exit 1;
fi;
## apply the actual puppet code
# set the module path so puppet apply finds every module
puppet apply --modulepath="${PUPPET_MODULE_PATH}:${HERE}" -e "include lanserver";
#handle return code
if [ $? -eq 0 ];
then
echo "";
echo -e "\e[32mSUCCESS\e[39m.";
echo "";
echo "Rerun the script to apply changes made in the \"params.pp\" of the puppet module.";
echo "Now you can also us the following command to update your server without running this script:";
echo "puppet apply --modulepath=${PUPPET_MODULE_PATH}:${HERE} -e \"include lanserver\"";
else
echo "";
echo -e "\e[31mERROR\e[39m:";
echo "";
echo "Please check the output of the puppet run above. Most of the errors can be fixed easily";
exit 1;
fi