Skip to content

Commit

Permalink
Merge pull request #419 from JRGTH/master
Browse files Browse the repository at this point in the history
Code review/cleanup routine
  • Loading branch information
cedwards authored Jul 14, 2021
2 parents fb74bcb + f39168b commit c649171
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 21 deletions.
16 changes: 8 additions & 8 deletions usr/local/share/bastille/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
read answer
case $answer in
no|No|n|N|"")
[Nn][Oo]|[Nn]|"")
error_exit "Exiting."
;;
yes|Yes|y|Y)
[Yy][Ee][Ss]|[Yy])
info "Loading modules"
kldload linux linux64 linprocfs linsysfs tmpfs
info "Persisting modules"
Expand All @@ -456,10 +456,10 @@ ubuntu_bionic|bionic|ubuntu-bionic)
warn "Debootstrap not found. Should it be installed? (N|y)"
read answer
case $answer in
no|No|n|N|"")
[Nn][Oo]|[Nn]|"")
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
debootstrap --foreign --arch=amd64 --no-check-gpg bionic "${bastille_releasesdir}"/Ubuntu_1804
;;
Expand All @@ -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)"
read answer
case $answer in
no|No|n|N|"")
[Nn][Oo]|[Nn]|"")
error_exit "Exiting."
;;
yes|Yes|y|Y)
[Yy][Ee][Ss]|[Yy])
info "Loading modules"
kldload linux linux64 linprocfs linsysfs tmpfs
info "Persisting modules"
Expand All @@ -494,10 +494,10 @@ ubuntu_focal|focal|ubuntu-focal)
warn "Debootstrap not found. Should it be installed? (N|y)"
read answer
case $answer in
no|No|n|N|"")
[Nn][Oo]|[Nn]|"")
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
debootstrap --foreign --arch=amd64 --no-check-gpg focal "${bastille_releasesdir}"/Ubuntu_2004
;;
Expand Down
4 changes: 2 additions & 2 deletions usr/local/share/bastille/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ for _jail in ${JAILS}; do
MATCH_FOUND=$?

if [ "${ACTION}" = 'get' ]; then
if [ $MATCH_FOUND -ne 0 ]; then
if [ "${MATCH_FOUND}" -ne 0 ]; then
warn "not set"
elif ! echo "${MATCH_LINE}" | grep '=' > /dev/null 2>&1; then
echo "enabled"
Expand All @@ -99,7 +99,7 @@ for _jail in ${JAILS}; do
LINE=" ${PROPERTY};"
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}"
else # Replace the existing value. -- cwells
sed -i '' -E "s/ *${ESCAPED_PROPERTY}[ =;].*/${LINE}/" "${FILE}"
Expand Down
3 changes: 1 addition & 2 deletions usr/local/share/bastille/create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,7 @@ create_jail() {
FILE_LIST=".cshrc .profile COPYRIGHT dev etc media mnt net proc root tmp var usr/obj usr/tests"
for files in ${FILE_LIST}; do
if [ -f "${bastille_releasesdir}/${RELEASE}/${files}" ] || [ -d "${bastille_releasesdir}/${RELEASE}/${files}" ]; then
cp -a "${bastille_releasesdir}/${RELEASE}/${files}" "${bastille_jail_path}/${files}"
if [ "$?" -ne 0 ]; then
if ! cp -a "${bastille_releasesdir}/${RELEASE}/${files}" "${bastille_jail_path}/${files}"; then
## notify and clean stale files/directories
bastille destroy "${NAME}"
error_exit "Failed to copy release files. Please retry create!"
Expand Down
2 changes: 2 additions & 0 deletions usr/local/share/bastille/export.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ usage() {
-v | --verbose -- Be more verbose during the ZFS send operation.
--xz -- Export a ZFS jail using XZ(.xz) compressed image.
Tip: If no option specified, container should be exported to standard output.
EOF
exit 1
}
Expand Down
2 changes: 2 additions & 0 deletions usr/local/share/bastille/import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ usage() {
-f | --force -- Force an archive import regardless if the checksum file does not match or missing.
-v | --verbose -- Be more verbose during the ZFS receive operation.
Tip: If no option specified, container should be imported from standard input.
EOF
exit 1
}
Expand Down
2 changes: 1 addition & 1 deletion usr/local/share/bastille/pkg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fi

for _jail in ${JAILS}; do
info "[${_jail}]:"
if [ -f /usr/sbin/pkg ]; then
if [ -f "/usr/sbin/pkg" ]; then
jexec -l "${_jail}" /usr/sbin/pkg "$@"
else
jexec -l "${_jail}" /usr/sbin/mport "$@"
Expand Down
2 changes: 1 addition & 1 deletion usr/local/share/bastille/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ if [ "${TARGET}" = "ALL" ]; then
error_exit "Batch upgrade is unsupported."
fi

if [ -f /bin/midnightbsd-version ]; then
if [ -f "/bin/midnightbsd-version" ]; then
echo -e "${COLOR_RED}Not yet supported on MidnightBSD.${COLOR_RESET}"
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion usr/local/share/bastille/upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ if [ "${TARGET}" = "ALL" ]; then
error_exit "Batch upgrade is unsupported."
fi

if [ -f /bin/midnightbsd-version ]; then
if [ -f "/bin/midnightbsd-version" ]; then
echo -e "${COLOR_RED}Not yet supported on MidnightBSD.${COLOR_RESET}"
exit 1
fi
Expand Down
12 changes: 6 additions & 6 deletions usr/local/share/bastille/verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ bastille_usage() {
}

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}"
exit 1
fi
Expand Down Expand Up @@ -69,7 +69,7 @@ verify_template() {
echo
error_exit "Template validation failed."
## if INCLUDE; recursive verify
elif [ ${_hook} = 'INCLUDE' ]; then
elif [ "${_hook}" = 'INCLUDE' ]; then
info "[${_hook}]:"
cat "${_path}"
echo
Expand All @@ -92,13 +92,13 @@ verify_template() {
done < "${_path}"

## if tree; tree -a bastille_template/_dir
elif [ ${_hook} = 'OVERLAY' ]; then
elif [ "${_hook}" = 'OVERLAY' ]; then
info "[${_hook}]:"
cat "${_path}"
echo
while read _dir; do
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}"
else
find "${_template_path}/${_dir}" -print | sed -e 's;[^/]*/;|___;g;s;___|; |;g'
Expand All @@ -114,15 +114,15 @@ verify_template() {
done

## remove bad templates
if [ ${_hook_validate} -lt 1 ]; then
if [ "${_hook_validate}" -lt 1 ]; then
error_notify "No valid template hooks found."
error_notify "Template discarded."
rm -rf "${bastille_template}"
exit 1
fi

## if validated; ready to use
if [ ${_hook_validate} -gt 0 ]; then
if [ "${_hook_validate}" -gt 0 ]; then
info "Template ready to use."
fi
}
Expand Down

0 comments on commit c649171

Please sign in to comment.