Skip to content

Commit

Permalink
Merge pull request BastilleBSD#139 from JRGTH/master
Browse files Browse the repository at this point in the history
Compare/update fstab if both variables are set
  • Loading branch information
cedwards authored Feb 4, 2020
2 parents 7e43c10 + 96fcc6b commit 70eb3e6
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions usr/local/share/bastille/import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,17 @@ update_jailconf() {

update_fstab() {
# Update fstab .bastille mountpoint on thin containers only
# Check if is a thin container
if [ ! -d "${bastille_jailsdir}/${TARGET_TRIM}/root/.bastille" ]; then
break
elif ! grep -qw ".bastille" "${bastille_jailsdir}/${TARGET_TRIM}/fstab"; then
break
fi

# Set some variables
FSTAB_CONFIG="${bastille_jailsdir}/${TARGET_TRIM}/fstab"
FSTAB_RELEASE=$(grep -owE '([1-9]{2,2})\.[0-9](-RELEASE|-RC[1-2]|-stable-build-[0-9]{1,3})' ${FSTAB_CONFIG})
FSTAB_CURRENT=$(cat ${FSTAB_CONFIG} | grep -w ".*/releases/.*/jails/${TARGET_TRIM}/root/.bastille")
FSTAB_CURRENT=$(grep -w ".*/releases/.*/jails/${TARGET_TRIM}/root/.bastille" ${FSTAB_CONFIG})
FSTAB_NEWCONF="${bastille_releasesdir}/${FSTAB_RELEASE} ${bastille_jailsdir}/${TARGET_TRIM}/root/.bastille nullfs ro 0 0"
if ! grep -qw "${bastille_releasesdir}/${FSTAB_RELEASE}.*${bastille_jailsdir}/${TARGET_TRIM}/root/.bastille" ${FSTAB_CONFIG}; then
echo -e "${COLOR_GREEN}Updating fstab...${COLOR_RESET}"
sed -i '' "s|${FSTAB_CURRENT}|${FSTAB_NEWCONF}|" ${FSTAB_CONFIG}
if [ -n "${FSTAB_CURRENT}" ] && [ -n "${FSTAB_NEWCONF}" ]; then
# If both variables are set, compare and update as needed
if ! grep -qw "${bastille_releasesdir}/${FSTAB_RELEASE}.*${bastille_jailsdir}/${TARGET_TRIM}/root/.bastille" ${FSTAB_CONFIG}; then
echo -e "${COLOR_GREEN}Updating fstab...${COLOR_RESET}"
sed -i '' "s|${FSTAB_CURRENT}|${FSTAB_NEWCONF}|" ${FSTAB_CONFIG}
fi
fi
}

Expand Down

0 comments on commit 70eb3e6

Please sign in to comment.