mirror of
https://github.com/hackacad/bastille.git
synced 2025-12-19 16:51:00 +01:00
Code review/cleanup routine
This commit is contained in:
@@ -436,10 +436,10 @@ ubuntu_bionic|bionic|ubuntu-bionic)
|
|||||||
warn "linprocfs_load, linsysfs_load, tmpfs_load not enabled in /boot/loader.conf or linux_enable not active. Should I do that for you? (N|y)"
|
warn "linprocfs_load, linsysfs_load, tmpfs_load not enabled in /boot/loader.conf or linux_enable not active. Should I do that for you? (N|y)"
|
||||||
read answer
|
read answer
|
||||||
case $answer in
|
case $answer in
|
||||||
no|No|n|N|"")
|
[Nn][Oo]|[Nn]|"")
|
||||||
error_exit "Exiting."
|
error_exit "Exiting."
|
||||||
;;
|
;;
|
||||||
yes|Yes|y|Y)
|
[Yy][Ee][Ss]|[Yy])
|
||||||
info "Loading modules"
|
info "Loading modules"
|
||||||
kldload linux linux64 linprocfs linsysfs tmpfs
|
kldload linux linux64 linprocfs linsysfs tmpfs
|
||||||
info "Persisting modules"
|
info "Persisting modules"
|
||||||
@@ -456,10 +456,10 @@ ubuntu_bionic|bionic|ubuntu-bionic)
|
|||||||
warn "Debootstrap not found. Should it be installed? (N|y)"
|
warn "Debootstrap not found. Should it be installed? (N|y)"
|
||||||
read answer
|
read answer
|
||||||
case $answer in
|
case $answer in
|
||||||
no|No|n|N|"")
|
[Nn][Oo]|[Nn]|"")
|
||||||
error_exit "Exiting. You need to install debootstap before boostrapping a Linux jail."
|
error_exit "Exiting. You need to install debootstap before boostrapping a Linux jail."
|
||||||
;;
|
;;
|
||||||
yes|Yes|y|Y)
|
[Yy][Ee][Ss]|[Yy])
|
||||||
pkg install -y debootstrap
|
pkg install -y debootstrap
|
||||||
debootstrap --foreign --arch=amd64 --no-check-gpg bionic "${bastille_releasesdir}"/Ubuntu_1804
|
debootstrap --foreign --arch=amd64 --no-check-gpg bionic "${bastille_releasesdir}"/Ubuntu_1804
|
||||||
;;
|
;;
|
||||||
@@ -474,10 +474,10 @@ ubuntu_focal|focal|ubuntu-focal)
|
|||||||
warn "linprocfs_load, linsysfs_load, tmpfs_load not enabled in /boot/loader.conf or linux_enable not active. Should I do that for you? (N|y)"
|
warn "linprocfs_load, linsysfs_load, tmpfs_load not enabled in /boot/loader.conf or linux_enable not active. Should I do that for you? (N|y)"
|
||||||
read answer
|
read answer
|
||||||
case $answer in
|
case $answer in
|
||||||
no|No|n|N|"")
|
[Nn][Oo]|[Nn]|"")
|
||||||
error_exit "Exiting."
|
error_exit "Exiting."
|
||||||
;;
|
;;
|
||||||
yes|Yes|y|Y)
|
[Yy][Ee][Ss]|[Yy])
|
||||||
info "Loading modules"
|
info "Loading modules"
|
||||||
kldload linux linux64 linprocfs linsysfs tmpfs
|
kldload linux linux64 linprocfs linsysfs tmpfs
|
||||||
info "Persisting modules"
|
info "Persisting modules"
|
||||||
@@ -494,10 +494,10 @@ ubuntu_focal|focal|ubuntu-focal)
|
|||||||
warn "Debootstrap not found. Should it be installed? (N|y)"
|
warn "Debootstrap not found. Should it be installed? (N|y)"
|
||||||
read answer
|
read answer
|
||||||
case $answer in
|
case $answer in
|
||||||
no|No|n|N|"")
|
[Nn][Oo]|[Nn]|"")
|
||||||
error_exit "Exiting. You need to install debootstap before boostrapping a Linux jail."
|
error_exit "Exiting. You need to install debootstap before boostrapping a Linux jail."
|
||||||
;;
|
;;
|
||||||
yes|Yes|y|Y)
|
[Yy][Ee][Ss]|[Yy])
|
||||||
pkg install -y debootstrap
|
pkg install -y debootstrap
|
||||||
debootstrap --foreign --arch=amd64 --no-check-gpg focal "${bastille_releasesdir}"/Ubuntu_2004
|
debootstrap --foreign --arch=amd64 --no-check-gpg focal "${bastille_releasesdir}"/Ubuntu_2004
|
||||||
;;
|
;;
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ for _jail in ${JAILS}; do
|
|||||||
MATCH_FOUND=$?
|
MATCH_FOUND=$?
|
||||||
|
|
||||||
if [ "${ACTION}" = 'get' ]; then
|
if [ "${ACTION}" = 'get' ]; then
|
||||||
if [ $MATCH_FOUND -ne 0 ]; then
|
if [ "${MATCH_FOUND}" -ne 0 ]; then
|
||||||
warn "not set"
|
warn "not set"
|
||||||
elif ! echo "${MATCH_LINE}" | grep '=' > /dev/null 2>&1; then
|
elif ! echo "${MATCH_LINE}" | grep '=' > /dev/null 2>&1; then
|
||||||
echo "enabled"
|
echo "enabled"
|
||||||
@@ -99,7 +99,7 @@ for _jail in ${JAILS}; do
|
|||||||
LINE=" ${PROPERTY};"
|
LINE=" ${PROPERTY};"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $MATCH_FOUND -ne 0 ]; then # No match, so insert the property at the end. -- cwells
|
if [ "${MATCH_FOUND}" -ne 0 ]; then # No match, so insert the property at the end. -- cwells
|
||||||
echo "$(awk -v line="${LINE}" '$0 == "}" { print line; } 1 { print $0; }' "${FILE}")" > "${FILE}"
|
echo "$(awk -v line="${LINE}" '$0 == "}" { print line; } 1 { print $0; }' "${FILE}")" > "${FILE}"
|
||||||
else # Replace the existing value. -- cwells
|
else # Replace the existing value. -- cwells
|
||||||
sed -i '' -E "s/ *${ESCAPED_PROPERTY}[ =;].*/${LINE}/" "${FILE}"
|
sed -i '' -E "s/ *${ESCAPED_PROPERTY}[ =;].*/${LINE}/" "${FILE}"
|
||||||
|
|||||||
@@ -358,8 +358,7 @@ create_jail() {
|
|||||||
FILE_LIST=".cshrc .profile COPYRIGHT dev etc media mnt net proc root tmp var usr/obj usr/tests"
|
FILE_LIST=".cshrc .profile COPYRIGHT dev etc media mnt net proc root tmp var usr/obj usr/tests"
|
||||||
for files in ${FILE_LIST}; do
|
for files in ${FILE_LIST}; do
|
||||||
if [ -f "${bastille_releasesdir}/${RELEASE}/${files}" ] || [ -d "${bastille_releasesdir}/${RELEASE}/${files}" ]; then
|
if [ -f "${bastille_releasesdir}/${RELEASE}/${files}" ] || [ -d "${bastille_releasesdir}/${RELEASE}/${files}" ]; then
|
||||||
cp -a "${bastille_releasesdir}/${RELEASE}/${files}" "${bastille_jail_path}/${files}"
|
if ! cp -a "${bastille_releasesdir}/${RELEASE}/${files}" "${bastille_jail_path}/${files}"; then
|
||||||
if [ "$?" -ne 0 ]; then
|
|
||||||
## notify and clean stale files/directories
|
## notify and clean stale files/directories
|
||||||
bastille destroy "${NAME}"
|
bastille destroy "${NAME}"
|
||||||
error_exit "Failed to copy release files. Please retry create!"
|
error_exit "Failed to copy release files. Please retry create!"
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ fi
|
|||||||
|
|
||||||
for _jail in ${JAILS}; do
|
for _jail in ${JAILS}; do
|
||||||
info "[${_jail}]:"
|
info "[${_jail}]:"
|
||||||
if [ -f /usr/sbin/pkg ]; then
|
if [ -f "/usr/sbin/pkg" ]; then
|
||||||
jexec -l "${_jail}" /usr/sbin/pkg "$@"
|
jexec -l "${_jail}" /usr/sbin/pkg "$@"
|
||||||
else
|
else
|
||||||
jexec -l "${_jail}" /usr/sbin/mport "$@"
|
jexec -l "${_jail}" /usr/sbin/mport "$@"
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ if [ "${TARGET}" = "ALL" ]; then
|
|||||||
error_exit "Batch upgrade is unsupported."
|
error_exit "Batch upgrade is unsupported."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f /bin/midnightbsd-version ]; then
|
if [ -f "/bin/midnightbsd-version" ]; then
|
||||||
echo -e "${COLOR_RED}Not yet supported on MidnightBSD.${COLOR_RESET}"
|
echo -e "${COLOR_RED}Not yet supported on MidnightBSD.${COLOR_RESET}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ if [ "${TARGET}" = "ALL" ]; then
|
|||||||
error_exit "Batch upgrade is unsupported."
|
error_exit "Batch upgrade is unsupported."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f /bin/midnightbsd-version ]; then
|
if [ -f "/bin/midnightbsd-version" ]; then
|
||||||
echo -e "${COLOR_RED}Not yet supported on MidnightBSD.${COLOR_RESET}"
|
echo -e "${COLOR_RED}Not yet supported on MidnightBSD.${COLOR_RESET}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ bastille_usage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
verify_release() {
|
verify_release() {
|
||||||
if [ -f /bin/midnightbsd-version ]; then
|
if [ -f "/bin/midnightbsd-version" ]; then
|
||||||
echo -e "${COLOR_RED}Not yet supported on MidnightBSD.${COLOR_RESET}"
|
echo -e "${COLOR_RED}Not yet supported on MidnightBSD.${COLOR_RESET}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@@ -69,7 +69,7 @@ verify_template() {
|
|||||||
echo
|
echo
|
||||||
error_exit "Template validation failed."
|
error_exit "Template validation failed."
|
||||||
## if INCLUDE; recursive verify
|
## if INCLUDE; recursive verify
|
||||||
elif [ ${_hook} = 'INCLUDE' ]; then
|
elif [ "${_hook}" = 'INCLUDE' ]; then
|
||||||
info "[${_hook}]:"
|
info "[${_hook}]:"
|
||||||
cat "${_path}"
|
cat "${_path}"
|
||||||
echo
|
echo
|
||||||
@@ -92,13 +92,13 @@ verify_template() {
|
|||||||
done < "${_path}"
|
done < "${_path}"
|
||||||
|
|
||||||
## if tree; tree -a bastille_template/_dir
|
## if tree; tree -a bastille_template/_dir
|
||||||
elif [ ${_hook} = 'OVERLAY' ]; then
|
elif [ "${_hook}" = 'OVERLAY' ]; then
|
||||||
info "[${_hook}]:"
|
info "[${_hook}]:"
|
||||||
cat "${_path}"
|
cat "${_path}"
|
||||||
echo
|
echo
|
||||||
while read _dir; do
|
while read _dir; do
|
||||||
info "[${_hook}]:[${_dir}]:"
|
info "[${_hook}]:[${_dir}]:"
|
||||||
if [ -x /usr/local/bin/tree ]; then
|
if [ -x "/usr/local/bin/tree" ]; then
|
||||||
/usr/local/bin/tree -a "${_template_path}/${_dir}"
|
/usr/local/bin/tree -a "${_template_path}/${_dir}"
|
||||||
else
|
else
|
||||||
find "${_template_path}/${_dir}" -print | sed -e 's;[^/]*/;|___;g;s;___|; |;g'
|
find "${_template_path}/${_dir}" -print | sed -e 's;[^/]*/;|___;g;s;___|; |;g'
|
||||||
@@ -114,7 +114,7 @@ verify_template() {
|
|||||||
done
|
done
|
||||||
|
|
||||||
## remove bad templates
|
## remove bad templates
|
||||||
if [ ${_hook_validate} -lt 1 ]; then
|
if [ "${_hook_validate}" -lt 1 ]; then
|
||||||
error_notify "No valid template hooks found."
|
error_notify "No valid template hooks found."
|
||||||
error_notify "Template discarded."
|
error_notify "Template discarded."
|
||||||
rm -rf "${bastille_template}"
|
rm -rf "${bastille_template}"
|
||||||
@@ -122,7 +122,7 @@ verify_template() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
## if validated; ready to use
|
## if validated; ready to use
|
||||||
if [ ${_hook_validate} -gt 0 ]; then
|
if [ "${_hook_validate}" -gt 0 ]; then
|
||||||
info "Template ready to use."
|
info "Template ready to use."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user