Kickstart helper modules to be used on recipes
This commit is contained in:
parent
749fbae08c
commit
c4379c5baf
3
kickstart/install.sh
Normal file
3
kickstart/install.sh
Normal file
@ -0,0 +1,3 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
source recipes/kickstart.sh
|
29
kickstart/recipes/kickstart.sh
Normal file
29
kickstart/recipes/kickstart.sh
Normal file
@ -0,0 +1,29 @@
|
||||
kickstart.os() {
|
||||
( uname -a | grep -q Ubuntu ) && echo "Ubuntu"
|
||||
}
|
||||
|
||||
kickstart.codename() {
|
||||
lsb_release -sc
|
||||
}
|
||||
|
||||
kickstart.info() {
|
||||
echo $@ >&2
|
||||
}
|
||||
|
||||
kickstart.mute() {
|
||||
echo "Running \"$@\""
|
||||
`$@ >/dev/null 2>&1`
|
||||
return $?
|
||||
}
|
||||
|
||||
kickstart.add_to_profile.d() {
|
||||
file=$1
|
||||
[ ! -f files/$file ] && echo "File files/$file not found" && exit 1
|
||||
|
||||
cp files/$file /etc/profile.d/$file
|
||||
grep -q $file /etc/zshenv 2>&1 || ( echo "[[ -f /etc/profile.d/$file ]] && source /etc/profile.d/$file" >> /etc/zshenv )
|
||||
}
|
||||
|
||||
for recipe in recipes/kickstart/*; do
|
||||
source $recipe
|
||||
done
|
20
kickstart/recipes/kickstart/apt.sh
Normal file
20
kickstart/recipes/kickstart/apt.sh
Normal file
@ -0,0 +1,20 @@
|
||||
kickstart.apt.update() {
|
||||
kickstart.mute "apt-get update -y"
|
||||
}
|
||||
|
||||
kickstart.apt.upgrade() {
|
||||
kickstart.mute "apt-get -y upgrade"
|
||||
}
|
||||
|
||||
kickstart.apt.ppa() {
|
||||
kickstart.mute "add-apt-repository -y $1"
|
||||
kickstart.apt.update
|
||||
}
|
||||
|
||||
kickstart.apt.add_key_from_url() {
|
||||
kickstart.download.stream $1 | kickstart.mute 'apt-key add -'
|
||||
}
|
||||
|
||||
kickstart.apt.add_key_from_keychain() {
|
||||
kickstart.mute "apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv $1"
|
||||
}
|
14
kickstart/recipes/kickstart/download.sh
Normal file
14
kickstart/recipes/kickstart/download.sh
Normal file
@ -0,0 +1,14 @@
|
||||
kickstart.download.file() {
|
||||
kickstart.download.stream $1 > $2
|
||||
}
|
||||
|
||||
kickstart.download.stream() {
|
||||
if [ `which curl` ]; then
|
||||
curl $1
|
||||
elif [ `which wget` ]; then
|
||||
wget -qO - $1
|
||||
else
|
||||
kickstart.info "No download application found"
|
||||
exit 1
|
||||
fi
|
||||
}
|
3
kickstart/recipes/kickstart/group.sh
Normal file
3
kickstart/recipes/kickstart/group.sh
Normal file
@ -0,0 +1,3 @@
|
||||
kickstart.group.create() {
|
||||
grep -q $1 /etc/group || groupadd docker
|
||||
}
|
31
kickstart/recipes/kickstart/package.sh
Normal file
31
kickstart/recipes/kickstart/package.sh
Normal file
@ -0,0 +1,31 @@
|
||||
# Set $kickstart_pkg to "apt-get" or "yum", or abort.
|
||||
if which apt-get >/dev/null 2>&1; then
|
||||
export kickstart_pkg=apt-get
|
||||
elif which yum >/dev/null 2>&1; then
|
||||
export kickstart_pkg=yum
|
||||
fi
|
||||
|
||||
if [ "$kickstart_pkg" = '' ]; then
|
||||
echo 'kickstart only supports apt-get or yum!' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
kickstart.package.installed() {
|
||||
if [ "$kickstart_pkg" = 'apt-get' ]; then
|
||||
dpkg -s $@ >/dev/null 2>&1
|
||||
elif [ "$kickstart_pkg" = 'yum' ]; then
|
||||
rpm -qa | grep $@ >/dev/null
|
||||
fi
|
||||
return $?
|
||||
}
|
||||
|
||||
kickstart.package.install() {
|
||||
if kickstart.package.installed "$@"; then
|
||||
echo "$@ already installed"
|
||||
return 1
|
||||
else
|
||||
echo "No packages found matching $@. Installing..."
|
||||
kickstart.mute "$kickstart_pkg -y install $@"
|
||||
return 0
|
||||
fi
|
||||
}
|
20
kickstart/recipes/kickstart/service.sh
Normal file
20
kickstart/recipes/kickstart/service.sh
Normal file
@ -0,0 +1,20 @@
|
||||
kickstart.service.enable() {
|
||||
[ `which enable` ] && enable $1
|
||||
}
|
||||
kickstart.service.disable() {
|
||||
[ `which disable` ] && disable $1
|
||||
}
|
||||
|
||||
kickstart.service.start() {
|
||||
[ `which start` ] && start $1
|
||||
}
|
||||
|
||||
kickstart.service.stop() {
|
||||
[ `which stop` ] && stop $1
|
||||
}
|
||||
|
||||
kickstart.service.restart() {
|
||||
kickstart.service.stop $1
|
||||
kickstart.service.start $1
|
||||
}
|
||||
|
3
kickstart/recipes/kickstart/user.sh
Normal file
3
kickstart/recipes/kickstart/user.sh
Normal file
@ -0,0 +1,3 @@
|
||||
kickstart.user.add_group() {
|
||||
grep -q $2 <(groups $1) || usermod -a -G $2 $1
|
||||
}
|
Loading…
Reference in New Issue
Block a user