Commit 84d01e3e authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

Add partial support for NetBSD and OpenBSD

Resizing NetBSD and OpenBSD partitions, as well as FFS filesystems
does not work for now
parent f59d5348
......@@ -474,6 +474,26 @@ umount_all() {
done
}
get_ufstype() {
local device ufs
device="$1"
ufs="$($DUMPFS_UFS "$device" | head -1 | awk '{ match ($3, /\((.+)\)/, ufs); print ufs[1] }')"
case "$ufs" in
UFS1)
echo 44bsd
;;
UFS2)
echo ufs2
;;
*)
log_error "Unsupported UFS type: \`$ufs' in device $device"
echo ""
;;
esac
}
cleanup() {
# if something fails here, it shouldn't call cleanup again...
trap - EXIT
......@@ -530,7 +550,6 @@ check_if_excluded() {
return 0
}
return_success() {
send_result_${HYPERVISOR} "SUCCESS"
}
......
......@@ -109,8 +109,8 @@ if [ -z "$SNF_IMAGE_PROPERTY_EXCLUDE_ALL_TASKS" ]; then
log_error "Required image property \`ROOT_PARTITION' is missing or empty."
fi
if [[ ! "$SNF_IMAGE_PROPERTY_OSFAMILY" =~ ^(linux|windows|freebsd)$ ]]; then
log_error "Supported values for OSFAMILY property are: linux|windows|freebsd"
if [[ ! "$SNF_IMAGE_PROPERTY_OSFAMILY" =~ ^(linux|windows|freebsd|openbsd|netbsd)$ ]]; then
log_error "Supported values for OSFAMILY property are: linux|windows|freebsd|openbsd|netbsd"
fi
SNF_IMAGE_RESIZE_PART="$(get_partition_to_resize "$SNF_IMAGE_DEV")"
......
......@@ -35,6 +35,12 @@ if [ ! -b "$SNF_IMAGE_DEV" ]; then
log_error "Device file:\`${SNF_IMAGE_DEV}' is not a block device"
fi
if [[ "$SNF_IMAGE_PROPERTY_OSFAMILY" =~ (net)|(open)bsd ]]; then
os=${SNF_IMAGE_PROPERTY_OSFAMILY^[bsd]}
warn "Partition resizing currently not supported for ${os^?}"
exit 0
fi
table=$(get_partition_table "$SNF_IMAGE_DEV")
if [ $(get_partition_count "$table") -eq 0 ]; then
......
......@@ -45,6 +45,12 @@ if [ -n "$SNF_IMAGE_PROPERTY_DO_SYNC" ]; then
unset EATMYDATA
fi
if [[ "$SNF_IMAGE_PROPERTY_OSFAMILY" =~ (net)|(open)bsd ]]; then
os=${SNF_IMAGE_PROPERTY_OSFAMILY^[bsd]}
warn "File sytem resizing currently not supported for ${os^?}"
exit 0
fi
table=$(get_partition_table "$SNF_IMAGE_DEV")
partition=$(get_partition_by_num "$table" "$SNF_IMAGE_RESIZE_PART")
id=$(cut -d: -f1 <<< "$partition")
......
......@@ -45,11 +45,16 @@ if [ ! -b "$rootdev" ]; then
"(=$SNF_IMAGE_PROPERTY_ROOT_PARTITION) is valid."
fi
if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "freebsd" ]; then
if [[ "$SNF_IMAGE_PROPERTY_OSFAMILY" == *bsd ]]; then
if ! $DUMPFS_UFS "$rootdev" &> /dev/null; then
log_error "For FreeBSD images only UFS root partitions are supported."
os=${SNF_IMAGE_PROPERTY_OSFAMILY^[bsd]}
log_error "For ${os^?} images only UFS root partitions are supported."
fi
$MOUNT -t ufs -o ufstype=ufs2,rw "$rootdev" "$SNF_IMAGE_TARGET"
usftype="$(get_ufstype "$rootdev")"
if [ "x$ufstype" = "x" ]; then
exit 1
fi
$MOUNT -t ufs -o ufstype="$ufstype,rw" "$rootdev" "$SNF_IMAGE_TARGET"
else
$MOUNT -o rw "$rootdev" "$SNF_IMAGE_TARGET"
fi
......
......@@ -37,7 +37,7 @@ if [ ! -d "$SNF_IMAGE_TARGET" ]; then
log_error "Target dir: \`$SNF_IMAGE_TARGET' is missing."
fi
if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" != "linux" -a "$SNF_IMAGE_PROPERTY_OSFAMILY" != "freebsd" ]; then
if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "windows" ]; then
exit 0
fi
......
......@@ -110,6 +110,26 @@ freebsd_hostname() {
fi
}
openbsd_hostname() {
local target hostname
target="$1"
hostname="$2"
echo "$hostname" > "$target/etc/myname"
}
netbsd_hoststame() {
local target hostname
target="$1"
hostname="$2"
openbsd_hostname "$@"
if grep ^hostname= "$target/etc/rc.conf"; then
sed -i -e "s/^hostname=.*$/hostname=\"$(printf "%q" "$hostname")\"/" "$target/etc/rc.conf"
fi
}
if [ ! -d "$SNF_IMAGE_TARGET" ]; then
log_error "Target dir: \`$SNF_IMAGE_TARGET' is missing"
fi
......@@ -118,13 +138,7 @@ if [ -z "$SNF_IMAGE_HOSTNAME" ]; then
log_error "Hostname is missing"
fi
if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "windows" ]; then
windows_hostname "$SNF_IMAGE_TARGET" "$SNF_IMAGE_HOSTNAME"
elif [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "linux" ]; then
linux_hostname "$SNF_IMAGE_TARGET" "$SNF_IMAGE_HOSTNAME"
elif [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "freebsd" ]; then
freebsd_hostname "$SNF_IMAGE_TARGET" "$SNF_IMAGE_HOSTNAME"
fi
${SNF_IMAGE_PROPERTY_OSFAMILY}_hostname "$SNF_IMAGE_TARGET" "$SNF_IMAGE_HOSTNAME"
exit 0
......
......@@ -56,6 +56,14 @@ freebsd_change_shadow_entry() {
echo "${entry[0]}:$encrypted:${entry[2]}:${entry[3]}:${entry[4]}:${entry[5]}:0:${entry[7]}:${entry[8]}:${entry[9]}"
}
openbsd_change_shadow_entry() {
freebsd_change_shadow_entry "$@"
}
netbsd_change_shadow_entry() {
freebsd_change_shadow_entry "$@"
}
windows_password() {
local target password
target="$1"
......@@ -149,11 +157,12 @@ SNF_IMAGE_PROPERTY_USERS=$(echo $SNF_IMAGE_PROPERTY_USERS)
if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "windows" ]; then
windows_password "$SNF_IMAGE_TARGET" "$SNF_IMAGE_PASSWORD"
elif [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "linux" ]; then
unix_password linux "$SNF_IMAGE_TARGET" "$SNF_IMAGE_PASSWORD"
elif [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "freebsd" ]; then
unix_password freebsd "$SNF_IMAGE_TARGET" "$SNF_IMAGE_PASSWORD"
else
unix_password "$SNF_IMAGE_PROPERTY_OSFAMILY" "$SNF_IMAGE_TARGET" "$SNF_IMAGE_PASSWORD"
fi
# For FreeBSD, OpenBSD and NetBSD we need to recreate the password database too
if [[ "$SNF_IMAGE_PROPERTY_OSFAMILY" == *bsd ]]; then
rm -f "$SNF_IMAGE_TARGET/etc/spwd.db"
# Make sure /etc/spwd.db is recreated on first boot
......
......@@ -50,7 +50,7 @@ if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "windows" ]; then
echo "$SNF_IMAGE_PERSONALITY" |
@scriptsdir@/inject-files.py "$SNF_IMAGE_TARGET"
exit 0
elif [[ "$SNF_IMAGE_PROPERTY_OSFAMILY" =~ ^(linux|freebsd)$ ]]; then
else
tmpdir="$(env TMPDIR="$SNF_IMAGE_TARGET/tmp" mktemp -d)"
add_cleanup rm -rf "$tmpdir"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment