forked from saltstack/salt-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap-salt-minion.sh
executable file
·992 lines (838 loc) · 30.3 KB
/
bootstrap-salt-minion.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
#!/bin/bash -
#===============================================================================
# vim: softtabstop=4 shiftwidth=4 expandtab fenc=utf-8 spell spelllang=en
#===============================================================================
#
# FILE: bootstrap-salt-minion.sh
#
# DESCRIPTION: Bootstrap salt installation for various systems/distributions
#
# BUGS: https://github.com/saltstack/salty-vagrant/issues
# AUTHOR: Pedro Algarvio (s0undt3ch), [email protected]
# Alec Koumjian (akoumjian), [email protected]
# ORGANIZATION: Salt Stack (saltstack.org)
# CREATED: 10/15/2012 09:49:37 PM WEST
#===============================================================================
set -o nounset # Treat unset variables as an error
ScriptVersion="1.1"
ScriptName="bootstrap-salt-minion.sh"
#===============================================================================
# LET THE BLACK MAGIC BEGIN!!!!
#===============================================================================
#=== FUNCTION ================================================================
# NAME: usage
# DESCRIPTION: Display usage information.
#===============================================================================
usage() {
cat << EOT
Usage : ${ScriptName} [options] <install-type> <install-type-args>
Installation types:
- stable (default)
- daily (ubuntu specific)
- git
Examples:
$ ${ScriptName}
$ ${ScriptName} stable
$ ${ScriptName} daily
$ ${ScriptName} git
$ ${ScriptName} git develop
$ ${ScriptName} git 8c3fadf15ec183e5ce8c63739850d543617e4357
Options:
-h|help Display this message
-v|version Display script version
-c|config-dir Temporary minion configuration directory
EOT
} # ---------- end of function usage ----------
#-----------------------------------------------------------------------
# Handle command line arguments
#-----------------------------------------------------------------------
TEMP_CONFIG_DIR="null"
while getopts ":hvc:" opt
do
case $opt in
h|help ) usage; exit 0 ;;
v|version ) echo "$0 -- Version $ScriptVersion"; exit 0 ;;
c|config-dir ) TEMP_CONFIG_DIR="$OPTARG" ;;
\? ) echo "\n Option does not exist : $OPTARG\n"
usage; exit 1 ;;
esac # --- end of case ---
done
shift $(($OPTIND-1))
__check_unparsed_options() {
shellopts="$1"
unparsed_options=$( echo "$shellopts" | grep -E '[-]+[[:alnum:]]' )
if [ "x$unparsed_options" != "x" ]; then
usage
echo
echo " * ERROR: options come before install arguments"
echo
exit 1
fi
}
# Define installation type
if [ "$#" -eq 0 ];then
ITYPE="stable"
else
__check_unparsed_options "$*"
ITYPE=$1
shift
fi
if [ "$ITYPE" != "stable" -a "$ITYPE" != "daily" -a "$ITYPE" != "git" ]; then
echo " ERROR: Installation type \"$ITYPE\" is not known..."
exit 1
fi
if [ $ITYPE = "git" ]; then
if [ "$#" -eq 0 ];then
GIT_REV="master"
else
__check_unparsed_options "$*"
GIT_REV="$1"
shift
fi
fi
if [ "$#" -gt 0 ]; then
__check_unparsed_options "$*"
usage
echo
echo " * ERROR: Too many arguments."
exit 1
fi
# Root permissions are required to run this script
if [ $(whoami) != "root" ] ; then
echo " * ERROR: Salt requires root privileges to install. Please re-run this script as root."
exit 1
fi
#--- FUNCTION ----------------------------------------------------------------
# NAME: __exit_cleanup
# DESCRIPTION: Cleanup any leftovers after script has ended
#-------------------------------------------------------------------------------
__exit_cleanup() {
EXIT_CODE=$?
# Remove the logging pipe when the script exits
echo " * Removing the logging pipe $LOGPIPE"
rm -f $LOGPIPE
# Kill tee when exiting, CentOS, at least requires this
TEE_PID=$(ps ax | grep tee | grep $LOGFILE | awk '{print $1}')
[ "x$TEE_PID" = "x" ] && exit $EXIT_CODE
echo " * Killing logging pipe tee's with pid(s): $TEE_PID"
# We need to trap errors since killing tee will cause a 127 errno
# We also do this as late as possible so we don't "mis-catch" other errors
__trap_errors() {
echo "Errors Trapped: $EXIT_CODE"
# Exit with the "original" exit code, not the trapped code
exit $EXIT_CODE
}
# Bash understands ERR trap signal, FreeBSD does not
trap "__trap_errors" ERR >/dev/null 2>&1 || trap "__trap_errors" INT KILL QUIT
# Now we're "good" to kill tee
kill -TERM $TEE_PID
# In case the 127 errno is not triggered, exit with the "original" exit code
exit $EXIT_CODE
}
trap "__exit_cleanup" EXIT
# Define our logging file and pipe paths
LOGFILE="/tmp/$( echo $ScriptName | sed s/.sh/.log/g )"
LOGPIPE="/tmp/$( echo $ScriptName | sed s/.sh/.logpipe/g )"
# Create our logging pipe
# On FreeBSD we have to use mkfifo instead of mknod
mknod $LOGPIPE p >/dev/null 2>&1 || mkfifo $LOGPIPE >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo " * Failed to create the named pipe required to log"
exit 1
fi
# What ever is written to the logpipe gets written to the logfile
tee < $LOGPIPE $LOGFILE &
# Close STDOUT, reopen it directing it to the logpipe
exec 1>&-
exec 1>$LOGPIPE
# Close STDERR, reopen it directing it to the logpipe
exec 2>&-
exec 2>$LOGPIPE
#--- FUNCTION ----------------------------------------------------------------
# NAME: __gather_hardware_info
# DESCRIPTION: Discover hardware information
#-------------------------------------------------------------------------------
__gather_hardware_info() {
if [ -f /proc/cpuinfo ]; then
CPU_VENDOR_ID=$(cat /proc/cpuinfo | grep -E 'vendor_id|Processor' | head -n 1 | awk '{print $3}' | cut -d '-' -f1 )
else
CPU_VENDOR_ID=$( sysctl -n hw.model )
fi
CPU_VENDOR_ID_L=$( echo $CPU_VENDOR_ID | tr '[:upper:]' '[:lower:]' )
CPU_ARCH=$(uname -m 2>/dev/null || uname -p 2>/dev/null || echo "unknown")
CPU_ARCH_L=$( echo $CPU_ARCH | tr '[:upper:]' '[:lower:]' )
}
__gather_hardware_info
#--- FUNCTION ----------------------------------------------------------------
# NAME: __gather_os_info
# DESCRIPTION: Discover operating system information
#-------------------------------------------------------------------------------
__gather_os_info() {
OS_NAME=$(uname -s 2>/dev/null)
OS_NAME_L=$( echo $OS_NAME | tr '[:upper:]' '[:lower:]' )
OS_VERSION=$(uname -r)
OS_VERSION_L=$( echo $OS_VERSION | tr '[:upper:]' '[:lower:]' )
}
__gather_os_info
#--- FUNCTION ----------------------------------------------------------------
# NAME: __parse_version_string
# DESCRIPTION: Parse version strings ignoring the revision.
# MAJOR.MINOR.REVISION becomes MAJOR.MINOR
#-------------------------------------------------------------------------------
__parse_version_string() {
VERSION_STRING="$1"
PARSED_VERSION=$(
echo $VERSION_STRING |
sed -e 's/^/#/' \
-e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\)\(\.[0-9][0-9]*\).*$/\1/' \
-e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \
-e 's/^#[^0-9]*\([0-9][0-9]*\).*$/\1/' \
-e 's/^#.*$//'
)
echo $PARSED_VERSION
}
#--- FUNCTION ----------------------------------------------------------------
# NAME: __gather_linux_system_info
# DESCRIPTION: Discover Linux system information
#-------------------------------------------------------------------------------
__gather_linux_system_info() {
DISTRO_NAME=""
DISTRO_VERSION=""
if [ -f /etc/lsb-release ]; then
DISTRO_NAME=$(grep DISTRIB_ID /etc/lsb-release | sed -e 's/.*=//')
DISTRO_VERSION=$(__parse_version_string $(grep DISTRIB_RELEASE /etc/lsb-release | sed -e 's/.*=//'))
fi
if [ "x$DISTRO_NAME" != "x" -a "x$DISTRO_VERSION" != "x" ]; then
# We already have the distribution name and version
return
fi
for rsource in $(
cd /etc && /bin/ls *[_-]release *[_-]version 2>/dev/null | env -i sort | \
sed -e '/^redhat-release$/d' -e '/^lsb-release$/d'; \
echo redhat-release lsb-release
); do
[ -L "/etc/${rsource}" ] && continue # Don't follow symlinks
[ ! -f "/etc/${rsource}" ] && continue # Does not exist
n=$(echo ${rsource} | sed -e 's/[_-]release$//' -e 's/[_-]version$//')
v=$( __parse_version_string "$( (grep VERSION /etc/${rsource}; cat /etc/${rsource}) | grep '[0-9]' | sed -e 'q' )" )
case $(echo ${n} | tr '[:upper:]' '[:lower:]') in
redhat )
if [ ".$(egrep '(Red Hat Enterprise Linux|CentOS)' /etc/${rsource})" != . ]; then
n="<R>ed <H>at <E>nterprise <L>inux"
else
n="<R>ed <H>at <L>inux"
fi
;;
arch ) n="Arch" ;;
centos ) n="CentOS" ;;
debian ) n="Debian" ;;
ubuntu ) n="Ubuntu" ;;
fedora ) n="Fedora" ;;
suse ) n="SUSE" ;;
mandrake*|mandriva ) n="Mandriva" ;;
gentoo ) n="Gentoo" ;;
slackware ) n="Slackware" ;;
turbolinux ) n="TurboLinux" ;;
unitedlinux ) n="UnitedLinux" ;;
* ) n="${n}" ;
esac
DISTRO_NAME=$n
DISTRO_VERSION=$v
break
done
}
#--- FUNCTION ----------------------------------------------------------------
# NAME: __gather_sunos_system_info
# DESCRIPTION: Discover SunOS system info
#-------------------------------------------------------------------------------
__gather_sunos_system_info() {
DISTRO_NAME="Solaris"
DISTRO_VERSION=$(
echo "${OS_VERSION}" |
sed -e 's;^4\.;1.;' \
-e 's;^5\.\([0-6]\)[^0-9]*$;2.\1;' \
-e 's;^5\.\([0-9][0-9]*\).*;\1;'
)
}
#--- FUNCTION ----------------------------------------------------------------
# NAME: __gather_bsd_system_info
# DESCRIPTION: Discover OpenBSD, NetBSD and FreeBSD systems information
#-------------------------------------------------------------------------------
__gather_bsd_system_info() {
DISTRO_NAME=${OS_NAME}
DISTRO_VERSION=$(echo "${OS_VERSION}" | sed -e 's;[()];;' -e 's/-.*$//')
}
#--- FUNCTION ----------------------------------------------------------------
# NAME: __gather_system_info
# DESCRIPTION: Discover which system and distribution we are running.
#-------------------------------------------------------------------------------
__gather_system_info() {
case ${OS_NAME_L} in
linux )
__gather_linux_system_info
;;
sunos )
__gather_sunos_system_info
;;
openbsd|freebsd|netbsd )
__gather_bsd_system_info
;;
* )
echo " * ERROR: $OS_NAME not supported.";
exit 1
;;
esac
}
#--- FUNCTION ----------------------------------------------------------------
# NAME: __function_defined
# DESCRIPTION: Checks if a function is defined within this scripts scope
# PARAMETERS: function name
# RETURNS: 0 or 1 as in defined or not defined
#-------------------------------------------------------------------------------
__function_defined() {
FUNC_NAME=$1
if [ "${DISTRO_NAME}" = "centos" ]; then
if typeset -f $FUNC_NAME &>/dev/null ; then
echo " * INFO: Found function $FUNC_NAME"
return 0
fi
elif [ "${DISTRO_NAME}" = "ubuntu" ]; then
if $( type ${FUNC_NAME} | grep -q 'shell function' ); then
echo " * INFO: Found function $FUNC_NAME"
return 0
fi
# Last resorts try POSIXLY_CORRECT or not
elif test -n "${POSIXLY_CORRECT+yes}"; then
if typeset -f $FUNC_NAME >/dev/null 2>&1 ; then
echo " * INFO: Found function $FUNC_NAME"
return 0
fi
else
# Arch linux seems to fall here
if $( type ${FUNC_NAME} >/dev/null 2>&1 ) ; then
echo " * INFO: Found function $FUNC_NAME"
return 0
fi
fi
echo " * INFO: $FUNC_NAME not found...."
return 1
}
__gather_system_info
#--- FUNCTION ----------------------------------------------------------------
# NAME: __git_clone_and_checkout
# DESCRIPTION: (DRY) Helper function to clone and checkout salt to a
# specific revision.
#-------------------------------------------------------------------------------
__git_clone_and_checkout() {
SALT_GIT_CHECKOUT_DIR=/tmp/git/salt
[ -d /tmp/git ] || mkdir /tmp/git
cd /tmp/git
[ -d $SALT_GIT_CHECKOUT_DIR ] || git clone git://github.com/saltstack/salt.git salt
cd salt
git checkout $GIT_REV
}
echo " * System Information:"
echo " CPU: ${CPU_VENDOR_ID}"
echo " CPU Arch: ${CPU_ARCH}"
echo " OS Name: ${OS_NAME}"
echo " OS Version: ${OS_VERSION}"
echo " Distribution: ${DISTRO_NAME} ${DISTRO_VERSION}"
# Simplify version naming on functions
if [ "x${DISTRO_VERSION}" = "x" ]; then
DISTRO_VERSION_NO_DOTS=""
else
DISTRO_VERSION_NO_DOTS="_$(echo $DISTRO_VERSION | tr -d '.')"
fi
# Simplify distro name naming on functions
DISTRO_NAME_L=$(echo $DISTRO_NAME | tr '[:upper:]' '[:lower:]' | sed 's/[^a-zA-Z0-9_ ]//g' | sed -e 's|[:space:]+|_|g')
#--- FUNCTION ----------------------------------------------------------------
# NAME: __apt_get_noinput
# DESCRIPTION: (DRY) apt-get install with noinput options
#-------------------------------------------------------------------------------
__apt_get_noinput() {
apt-get install -y -o DPkg::Options::=--force-confold $@
}
##############################################################################
#
# Distribution install functions
#
# In order to install salt for a distribution you need to define:
#
# To Install Dependencies, which is required, one of:
# 1. install_<distro>_<distro_version>_<install_type>_deps
# 2. install_<distro>_<distro_version>_deps
# 3. install_<distro>_<install_type>_deps
# 4. install_<distro>_deps
#
# Optionally, define a minion configuration function, which will be called if
# the -c|config-dir option is passed. One of:
# 1. config_<distro>_<distro_version>_<install_type>_minion
# 2. config_<distro>_<distro_version>_minion
# 3. config_<distro>_<install_type>_minion
# 4. config_<distro>_minion
# 5. config_minion [THIS ONE IS ALREADY DEFINED AS THE DEFAULT]
#
# To install salt, which, of course, is required, one of:
# 1. install_<distro>_<distro_version>_<install_type>
# 2. install_<distro>_<install_type>
#
# Also optionally, define a post install function, one of:
# 1. install_<distro>_<distro_versions>_<install_type>_post
# 2. install_<distro>_<distro_versions>_post
# 3. install_<distro>_<install_type>_post
# 4. install_<distro>_post
#
##############################################################################
##############################################################################
#
# Ubuntu Install Functions
#
install_ubuntu_deps() {
apt-get update
__apt_get_noinput python-software-properties
add-apt-repository -y ppa:saltstack/salt
apt-get update
}
install_ubuntu_1004_deps() {
apt-get update
__apt_get_noinput python-software-properties
add-apt-repository ppa:saltstack/salt
apt-get update
__apt_get_noinput salt-minion
}
install_ubuntu_1004_git_deps() {
install_ubuntu_1004_deps
__apt_get_noinput git-core
}
install_ubuntu_1110_deps() {
apt-get update
__apt_get_noinput python-software-properties
add-apt-repository -y 'deb http://us.archive.ubuntu.com/ubuntu/ oneiric universe'
add-apt-repository -y ppa:saltstack/salt
}
install_ubuntu_daily_deps() {
apt-get update
__apt_get_noinput python-software-properties
add-apt-repository -y ppa:saltstack/salt-depends
add-apt-repository -y ppa:saltstack/salt-daily
apt-get update
}
install_ubuntu_git_deps() {
apt-get update
__apt_get_noinput python-software-properties
add-apt-repository ppa:saltstack/salt
apt-get update
__apt_get_noinput git-core python-yaml python-m2crypto python-crypto msgpack-python python-zmq python-jinja2
}
install_ubuntu_1110_post() {
add-apt-repository -y --remove 'deb http://us.archive.ubuntu.com/ubuntu/ oneiric universe'
}
install_ubuntu_stable() {
__apt_get_noinput salt-minion
}
install_ubuntu_daily() {
__apt_get_noinput salt-minion
}
install_ubuntu_git() {
__git_clone_and_checkout
python setup.py install --install-layout=deb
}
install_ubuntu_git_post() {
for fname in $(echo "minion master syndic"); do
if [ $fname != "minion" ]; then
# Guess we should only enable and start the minion service. Right??
continue
fi
if [ -f ${SALT_GIT_CHECKOUT_DIR}/debian/salt-$fname.init ]; then
cp ${SALT_GIT_CHECKOUT_DIR}/debian/salt-$fname.init /etc/init.d/salt-$fname
fi
if [ -f ${SALT_GIT_CHECKOUT_DIR}/debian/salt-$fname.upstart ]; then
cp ${SALT_GIT_CHECKOUT_DIR}/debian/salt-$fname.upstart /etc/init/salt-$fname.conf
elif [ -f ${SALT_GIT_CHECKOUT_DIR}/pkg/salt-$fname.upstart ]; then
cp ${SALT_GIT_CHECKOUT_DIR}/pkg/salt-$fname.upstart /etc/init/salt-$fname.conf
fi
chmod +x /etc/init.d/salt-$fname
service salt-$fname start
done
}
#
# End of Ubuntu Install Functions
#
##############################################################################
##############################################################################
#
# Debian Install Functions
#
install_debian_deps() {
apt-get update
}
install_debian_stable() {
__apt_get_noinput salt-minion
}
install_debian_60_deps() {
echo "deb http://backports.debian.org/debian-backports squeeze-backports main" >> \
/etc/apt/sources.list.d/backports.list
# Add madduck's repo since squeeze packages have been deprecated
for i in {salt-common,salt-master,salt-minion,salt-syndic,salt-doc}; do
echo "Package: $i"
echo "Pin: release a=squeeze-backports"
echo "Pin-Priority: 600"
echo
done > /etc/apt/preferences.d/local-salt-backport.pref
cat <<_eof > /etc/apt/sources.list.d/local-madduck-backports.list
deb http://debian.madduck.net/repo squeeze-backports main
deb-src http://debian.madduck.net/repo squeeze-backports main
_eof
wget -q http://debian.madduck.net/repo/gpg/archive.key
apt-key add archive.key
apt-get update
}
install_debian_60() {
__apt_get_noinput salt-minion
}
install_debian_git_deps() {
apt-get update
__apt_get_noinput lsb-release python python-pkg-resources python-crypto \
python-jinja2 python-m2crypto python-yaml msgpack-python git python-zmq
}
config_debian_git_minion() {
if [ "$TEMP_CONFIG_DIR" = "null" ]; then
TEMP_CONFIG_DIR="${SALT_GIT_CHECKOUT_DIR}/conf/"
config_minion
fi
}
install_debian_git() {
__git_clone_and_checkout
python setup.py install --install-layout=deb
}
install_debian_60_git_deps() {
install_debian_60_deps # Add backports
install_debian_git_deps # Grab the actual deps
}
config_debian_60_git_minion() {
config_debian_git_minion
}
install_debian_60_git() {
apt-get -y purge salt-minion
__git_clone_and_checkout
python setup.py install --install-layout=deb
}
install_debian_git_post() {
for fname in $(echo "minion master syndic"); do
if [ $fname != "minion" ]; then
# Guess we should only enable and start the minion service. Right??
continue
fi
if [ -f ${SALT_GIT_CHECKOUT_DIR}/debian/salt-$fname.init ]; then
cp ${SALT_GIT_CHECKOUT_DIR}/debian/salt-$fname.init /etc/init.d/salt-$fname
fi
chmod +x /etc/init.d/salt-$fname
/etc/init.d/salt-$fname start
done
}
#
# Ended Debian Install Functions
#
##############################################################################
##############################################################################
#
# Fedora Install Functions
#
install_fedora_deps() {
yum install -y PyYAML libyaml m2crypto python-crypto python-jinja2 python-msgpack python-zmq
}
install_fedora_stable() {
yum install -y salt-minion
}
install_fedora_git_deps() {
install_fedora_deps
yum install -y git
}
install_fedora_git() {
__git_clone_and_checkout
python setup.py install
}
install_fedora_git_post() {
for fname in $(echo "minion master syndic"); do
if [ $fname != "minion" ]; then
# Guess we should only enable and start the minion service. Right??
continue
fi
#cp ${SALT_GIT_CHECKOUT_DIR}/pkg/rpm/salt-$fname /etc/rc.d/init.d/salt-$fname
cp ${SALT_GIT_CHECKOUT_DIR}/pkg/rpm/salt-$fname.service /lib/systemd/system/salt-$fname.service
#chmod +x /etc/rc.d/init.d/salt-$fname
# Switch from forking to simple, dunny why I can't make it work
sed -i 's/Type=forking/Type=simple/g' /lib/systemd/system/salt-$fname.service
# Remove the daemon flag because of the above
sed -ie 's;ExecStart=\(.*\) -d;ExecStart=\1;' /lib/systemd/system/salt-$fname.service
systemctl preset salt-$fname.service
systemctl enable salt-$fname.service
sleep 0.2
systemctl daemon-reload
sleep 0.2
systemctl start salt-$fname.service
done
}
#
# Ended Fedora Install Functions
#
##############################################################################
##############################################################################
#
# CentOS Install Functions
#
install_centos_63_stable_deps() {
if [ $CPU_ARCH_L = "i686" ]; then
local ARCH="i386"
else
local ARCH=$CPU_ARCH_L
fi
rpm -Uvh --force http://mirrors.kernel.org/fedora-epel/6/${ARCH}/epel-release-6-8.noarch.rpm
yum -y update
}
install_centos_63_stable() {
yum -y install salt-minion --enablerepo=epel-testing
}
install_centos_63_stable_post() {
/sbin/chkconfig salt-minion on
/etc/init.d/salt-minion start
}
install_centos_63_git_deps() {
install_centos_63_stable_deps
yum -y install git PyYAML m2crypto python-crypto python-msgpack python-zmq python-jinja2 --enablerepo=epel-testing
}
install_centos_63_git() {
rm -rf /usr/lib/python*/site-packages/salt
rm -rf /usr/bin/salt*
__git_clone_and_checkout
python2 setup.py install
mkdir -p /etc/salt/
}
install_centos_63_git_post() {
cp pkg/rpm/salt-{master,minion} /etc/init.d/
chmod +x /etc/init.d/salt-{master,minion}
/sbin/chkconfig salt-minion on
/etc/init.d/salt-minion start
}
#
# Ended CentOS Install Functions
#
##############################################################################
##############################################################################
#
# Arch Install Functions
#
install_arch_stable_deps() {
echo '[salt]
Server = http://intothesaltmine.org/archlinux
' >> /etc/pacman.conf
}
install_arch_git_deps() {
echo '[salt]
Server = http://intothesaltmine.org/archlinux
' >> /etc/pacman.conf
}
install_arch_stable() {
pacman -Sy --noconfirm pacman
pacman -Syu --noconfirm salt
}
install_arch_git() {
pacman -Sy --noconfirm pacman
pacman -Syu --noconfirm salt git
rm -rf /usr/lib/python2.7/site-packages/salt*
rm -rf /usr/bin/salt-*
__git_clone_and_checkout
python2 setup.py install
}
install_arch_post() {
/etc/rc.d/salt-minion start
}
#
# Ended Arch Install Functions
#
##############################################################################
##############################################################################
#
# FreeBSD Install Functions
#
install_freebsd_90_stable_deps() {
if [ $CPU_ARCH_L = "amd64" ]; then
local ARCH="x86:64"
elif [ $CPU_ARCH_L = "x86_64" ]; then
local ARCH="x86:64"
elif [ $CPU_ARCH_L = "i386" ]; then
local ARCH="x86:32"
elif [ $CPU_ARCH_L = "i686" ]; then
local ARCH="x86:32"
fi
fetch http://pkgbeta.freebsd.org/freebsd:9:${ARCH}/latest/Latest/pkg.txz
tar xf ./pkg.txz -s ",/.*/,,g" "*/pkg-static"
./pkg-static add ./pkg.txz
/usr/local/sbin/pkg2ng
echo "PACKAGESITE: http://pkgbeta.freebsd.org/freebsd:9:${ARCH}/latest" > /usr/local/etc/pkg.conf
/usr/local/sbin/pkg install -y swig
}
install_freebsd_git_deps() {
if [ $CPU_ARCH_L = "amd64" ]; then
local ARCH="x86:64"
elif [ $CPU_ARCH_L = "x86_64" ]; then
local ARCH="x86:64"
elif [ $CPU_ARCH_L = "i386" ]; then
local ARCH="x86:32"
elif [ $CPU_ARCH_L = "i686" ]; then
local ARCH="x86:32"
fi
fetch http://pkgbeta.freebsd.org/freebsd:9:${ARCH}/latest/Latest/pkg.txz
tar xf ./pkg.txz -s ",/.*/,,g" "*/pkg-static"
./pkg-static add ./pkg.txz
/usr/local/sbin/pkg2ng
echo "PACKAGESITE: http://pkgbeta.freebsd.org/freebsd:9:${ARCH}/latest" > /usr/local/etc/pkg.conf
/usr/local/sbin/pkg install -y swig
}
install_freebsd_90_stable() {
/usr/local/sbin/pkg install -y salt
}
install_freebsd_git() {
/usr/local/sbin/pkg install -y git salt
/usr/local/sbin/pkg delete -y salt
__git_clone_and_checkout
/usr/local/bin/python setup.py install
}
install_freebsd_90_stable_post() {
salt-minion -d
}
install_freebsd_git_post() {
salt-minion -d
}
#
# Ended FreeBSD Install Functions
#
##############################################################################
##############################################################################
#
# Default minion configuration function. Matches ANY distribution as long as
# the -c options is passed.
#
config_minion() {
# If the configuration directory is not passed, return
[ "$TEMP_CONFIG_DIR" = "null" ] && return
# If the configuration directory does not exist, error out
if [ ! -d "$TEMP_CONFIG_DIR" ]; then
echo " * The configuration directory ${TEMP_CONFIG_DIR} does not exist."
exit 1
fi
PKI_DIR=/etc/salt/pki/minion
# Let's create the necessary directories
[ -d /etc/salt ] || mkdir /etc/salt
[ -d $PKI_DIR ] || mkdir -p $PKI_DIR && chmod 700 $PKI_DIR
# Copy the minions configuration if found
[ -f "$TEMP_CONFIG_DIR/minion" ] && mv "$TEMP_CONFIG_DIR/minion" /etc/salt
# Copy the minion's keys if found
if [ -f "$TEMP_CONFIG_DIR/minion.pem" ]; then
mv "$TEMP_CONFIG_DIR/minion.pem" $PKI_DIR/
chmod 400 $PKI_DIR/minion.pem
fi
if [ -f "$TEMP_CONFIG_DIR/minion.pub" ]; then
mv "$TEMP_CONFIG_DIR/minion.pub" $PKI_DIR/
chmod 664 $PKI_DIR/minion.pub
fi
}
#
# Ended Default Configuration function
#
##############################################################################
#=============================================================================
# LET'S PROCEED WITH OUR INSTALLATION
#=============================================================================
# Let's get the dependencies install function
DEP_FUNC_NAMES="install_${DISTRO_NAME_L}${DISTRO_VERSION_NO_DOTS}_${ITYPE}_deps"
DEP_FUNC_NAMES="$DEP_FUNC_NAMES install_${DISTRO_NAME_L}${DISTRO_VERSION_NO_DOTS}_deps"
DEP_FUNC_NAMES="$DEP_FUNC_NAMES install_${DISTRO_NAME_L}_${ITYPE}_deps"
DEP_FUNC_NAMES="$DEP_FUNC_NAMES install_${DISTRO_NAME_L}_deps"
DEPS_INSTALL_FUNC="null"
for DEP_FUNC_NAME in $DEP_FUNC_NAMES; do
if __function_defined $DEP_FUNC_NAME; then
DEPS_INSTALL_FUNC=$DEP_FUNC_NAME
break
fi
done
# Let's get the install function
INSTALL_FUNC_NAMES="install_${DISTRO_NAME_L}${DISTRO_VERSION_NO_DOTS}_${ITYPE}"
INSTALL_FUNC_NAMES="$INSTALL_FUNC_NAMES install_${DISTRO_NAME_L}_${ITYPE}"
INSTALL_FUNC="null"
for FUNC_NAME in $INSTALL_FUNC_NAMES; do
if __function_defined $FUNC_NAME; then
INSTALL_FUNC=$FUNC_NAME
break
fi
done
# Let's get the minion config function
CONFIG_MINION_FUNC="null"
if [ "$TEMP_CONFIG_DIR" != "null" ]; then
CONFIG_FUNC_NAMES="config_${DISTRO_NAME_L}${DISTRO_VERSION_NO_DOTS}_${ITYPE}_minion"
CONFIG_FUNC_NAMES="$CONFIG_FUNC_NAMES config_${DISTRO_NAME_L}${DISTRO_VERSION_NO_DOTS}_minon"
CONFIG_FUNC_NAMES="$CONFIG_FUNC_NAMES config_${DISTRO_NAME_L}_${ITYPE}_minion"
CONFIG_FUNC_NAMES="$CONFIG_FUNC_NAMES config_${DISTRO_NAME_L}_minion"
CONFIG_FUNC_NAMES="$CONFIG_FUNC_NAMES config_minion"
for FUNC_NAME in $CONFIG_FUNC_NAMES; do
if __function_defined $FUNC_NAME; then
CONFIG_MINION_FUNC=$FUNC_NAME
break
fi
done
fi
# Let's get the post install function
POST_FUNC_NAMES="install_${DISTRO_NAME_L}${DISTRO_VERSION_NO_DOTS}_${ITYPE}_post"
POST_FUNC_NAMES="$POST_FUNC_NAMES install_${DISTRO_NAME_L}${DISTRO_VERSION_NO_DOTS}_post"
POST_FUNC_NAMES="$POST_FUNC_NAMES install_${DISTRO_NAME_L}_${ITYPE}_post"
POST_FUNC_NAMES="$POST_FUNC_NAMES install_${DISTRO_NAME_L}_post"
POST_INSTALL_FUNC="null"
for FUNC_NAME in $POST_FUNC_NAMES; do
if __function_defined $FUNC_NAME; then
POST_INSTALL_FUNC=$FUNC_NAME
break
fi
done
if [ $DEPS_INSTALL_FUNC = "null" ]; then
echo " * ERROR: No dependencies installation function found. Exiting..."
exit 1
fi
if [ $INSTALL_FUNC = "null" ]; then
echo " * ERROR: No installation function found. Exiting..."
exit 1
fi
# Install dependencies
echo " * Running ${DEPS_INSTALL_FUNC}()"
$DEPS_INSTALL_FUNC
if [ $? -ne 0 ]; then
echo " * Failed to run ${DEPS_INSTALL_FUNC}()!!!"
exit 1
fi
# Configure Salt
if [ "$TEMP_CONFIG_DIR" != "null" -a "$CONFIG_MINION_FUNC" != "null" ]; then
echo " * Running ${CONFIG_MINION_FUNC}()"
$CONFIG_MINION_FUNC
if [ $? -ne 0 ]; then
echo " * Failed to run ${CONFIG_MINION_FUNC}()!!!"
exit 1
fi
fi
# Install Salt
echo " * Running ${INSTALL_FUNC}()"
$INSTALL_FUNC
if [ $? -ne 0 ]; then
echo " * Failed to run ${INSTALL_FUNC}()!!!"
exit 1
fi
# Run any post install function
if [ "$POST_INSTALL_FUNC" != "null" ]; then
echo " * Running ${POST_INSTALL_FUNC}()"
$POST_INSTALL_FUNC
if [ $? -ne 0 ]; then
echo " * Failed to run ${POST_INSTALL_FUNC}()!!!"
exit 1
fi
fi
# Done!
echo " * Salt installed!"
exit 0