-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-puppet-environment.sh
executable file
·68 lines (61 loc) · 2.01 KB
/
create-puppet-environment.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
#!/bin/bash
# This script sets up a work environment in the PWD for reading and writing puppet modules.
# This script will do the following
# 1. checkout the repos from puppet01 that match the runuser's groups
# 2. checkout the git hooks repo which includes pre/post commit actions
# 3. symlink .git/hooks to the hooks git repo.
runuser=$(whoami)
while getopts "h?vu:" opt; do
case "$opt" in
h|\?)
echo " USAGE: -u $USER"
exit 0
;;
u) runuser=$OPTARG
;;
esac
done
#clear OPTIND in case getopt is used elsewhere on this system. We use getopts since it's POSIX compliant
shift $((OPTIND-1))
if [ -d pe-puppet ]; then
read -p $'WARNING: pe-puppet exists. This will remove it and create a fresh environment. Any local modifications will be discarded. \n Are you sure? ' -n 1 -r -e
if [[ $REPLY =~ ^[Yy]$ ]]
then
rm -rf pe-puppet
fi
fi
repo_checkout () {
echo "Checking out $1 repo as $runuser"
git clone $runuser@puppet01:/opt/git/$1.git
cd $1 && git pull origin production
git checkout -b production
git branch -d master
cd ..
if [[ ! -d $(pwd)/hooks ]]; then
echo "Checking out hooks repo as $runuser"
git clone $runuser@puppet01:/opt/git/hooks.git && repolist+="hooks "
cd hooks && git pull origin production
fi
echo "Creating hooks symlink"
#symlink .git/hooks to the hooks repo
rm -rf $(pwd)/$1/.git/hooks && ln -s $(pwd)/hooks $(pwd)/$1/.git/hooks
}
if [ "$(id -u)" != "0" ]; then
mkdir pe-puppet && cd pe-puppet
for group in $(id -Gn $runuser); do
case $group in
"linux_admins")
repo_checkout linux_admins && repolist+="linux_admins "
;;
"linux_it")
repo_checkout linux_it && repolist+="linux_it "
;;
"linux_grove_dev")
repo_checkout linux_grove_dev && repolist+="linux_grove_dev "
;;
esac
done
echo "Successfully Cloned repos: " ${repolist[*]}
else
echo "This must be exectued as a non-root user with access to the puppet repo"
fi