66 lines
2 KiB
Text
66 lines
2 KiB
Text
|
#!/bin/sh
|
||
|
#
|
||
|
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
||
|
#
|
||
|
# This file is part of cdist.
|
||
|
#
|
||
|
# cdist is free software: you can redistribute it and/or modify
|
||
|
# it under the terms of the GNU General Public License as published by
|
||
|
# the Free Software Foundation, either version 3 of the License, or
|
||
|
# (at your option) any later version.
|
||
|
#
|
||
|
# cdist is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU General Public License
|
||
|
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
||
|
#
|
||
|
|
||
|
# show command output in debug mode
|
||
|
cat << DONE
|
||
|
__debug=$__cdist_debug
|
||
|
if [ "\$__debug" != "yes" ]; then
|
||
|
# Link file descriptor #6 with stdout
|
||
|
exec 6>&1
|
||
|
# redirect all output to /dev/null
|
||
|
exec > /dev/null
|
||
|
fi
|
||
|
DONE
|
||
|
|
||
|
uri="$(cat "$__object/parameter/uri")"
|
||
|
target="$(cat "$__object/parameter/target")"
|
||
|
post_install="$(cat "$__object/parameter/post_install" 2>/dev/null || true)"
|
||
|
|
||
|
|
||
|
[ "$__debug" = "yes" ] && curl="curl" || curl="curl -s"
|
||
|
[ "$__debug" = "yes" ] && tar="tar -xvzp" || tar="tar -xzp"
|
||
|
|
||
|
echo "$curl '$uri' | $tar -C '$target'"
|
||
|
if [ -n "$post_install" ]; then
|
||
|
post_install_script="$(cat "$__object/parameter/post_install_script")"
|
||
|
cat << DONE
|
||
|
[ -d "${target}/proc" ] || mkdir "${target}/proc"
|
||
|
mount -t proc none "${target}/proc"
|
||
|
[ -d "${target}/sys" ] || mkdir "${target}/sys"
|
||
|
mount -t sysfs none "${target}/sys"
|
||
|
[ -d "${target}/dev" ] || mkdir "${target}/dev"
|
||
|
mount --rbind /dev "${target}/dev"
|
||
|
[ -d "${target}/tmp" ] || mkdir -m 1777 "${target}/tmp"
|
||
|
mount -t tmpfs none "${target}/tmp"
|
||
|
cp "$post_install_script" "${target}/tmp/post_install"
|
||
|
chmod +x "${target}/tmp/post_install"
|
||
|
cp /etc/resolv.conf "${target}/etc/"
|
||
|
chroot "$target" /tmp/post_install
|
||
|
umount -l "${target}/tmp" "${target}/dev" "${target}/sys" "${target}/proc"
|
||
|
DONE
|
||
|
fi
|
||
|
|
||
|
cat << DONE
|
||
|
if [ "\$__debug" != "yes" ]; then
|
||
|
# Restore stdout and close file descriptor #6.
|
||
|
exec 1>&6 6>&-
|
||
|
fi
|
||
|
DONE
|