Commit 81ae21f6 authored by Natanael Copa's avatar Natanael Copa

setup-disk: add magic environemnt var ERASE_DISKS as confirmation

Add a magic environment variable ERASE_DISKS as confirmation for
erasing disks. This is useful for scripted installs.

fixes #2863
parent ab92d94c
...@@ -107,7 +107,7 @@ unpack_apkovl() { ...@@ -107,7 +107,7 @@ unpack_apkovl() {
n*|N*) return 1;; n*|N*) return 1;;
esac esac
fi fi
return 0 return 0
fi fi
apk add --quiet openssl apk add --quiet openssl
...@@ -315,7 +315,7 @@ EOF ...@@ -315,7 +315,7 @@ EOF
for i in $repos; do for i in $repos; do
repoflags="$repoflags --repository $i" repoflags="$repoflags --repository $i"
done done
chroot_caps=$(set_grsec chroot_caps 0) chroot_caps=$(set_grsec chroot_caps 0)
init_chroot_mounts "$mnt" init_chroot_mounts "$mnt"
apk add --root "$mnt" $apkflags --overlay-from-stdin \ apk add --root "$mnt" $apkflags --overlay-from-stdin \
...@@ -386,7 +386,7 @@ is_available_disk() { ...@@ -386,7 +386,7 @@ is_available_disk() {
# check if its a "root" block device and not a partition # check if its a "root" block device and not a partition
[ -e /sys/block/$b ] || return 1 [ -e /sys/block/$b ] || return 1
# check so it does not have mounted partitions # check so it does not have mounted partitions
has_mounted_part $dev && return 1 has_mounted_part $dev && return 1
...@@ -437,10 +437,14 @@ show_disk_info() { ...@@ -437,10 +437,14 @@ show_disk_info() {
confirm_erase() { confirm_erase() {
local answer= local answer=
local erasedisks="$@"
if [ "$ERASE_DISKS" = "$erasedisks" ]; then
reeturn 0
fi
echo "WARNING: The following disk(s) will be erased:" echo "WARNING: The following disk(s) will be erased:"
show_disk_info $@ show_disk_info $@
echo -n "WARNING: Erase the above disk(s) and continue? [y/N]: " echo -n "WARNING: Erase the above disk(s) and continue? [y/N]: "
read answer read answer
case "$answer" in case "$answer" in
y*|Y*) return 0;; y*|Y*) return 0;;
...@@ -449,7 +453,7 @@ confirm_erase() { ...@@ -449,7 +453,7 @@ confirm_erase() {
} }
# setup partitions on given disk dev in $1. # setup partitions on given disk dev in $1.
# usage: setup_partitions <diskdev> size1,type1 [size2,type2 ...] # usage: setup_partitions <diskdev> size1,type1 [size2,type2 ...]
setup_partitions() { setup_partitions() {
local diskdev="$1" local diskdev="$1"
shift shift
...@@ -558,7 +562,7 @@ setup_lvm_volume_group() { ...@@ -558,7 +562,7 @@ setup_lvm_volume_group() {
if [ -n "$USE_RAID" ]; then if [ -n "$USE_RAID" ]; then
setup_non_boot_raid_dev /dev/md1 $@ || return 1 setup_non_boot_raid_dev /dev/md1 $@ || return 1
lvmdev=/dev/md1 lvmdev=/dev/md1
else else
lvmdev=$(find_lvm_partition $1) lvmdev=$(find_lvm_partition $1)
fi fi
...@@ -654,7 +658,7 @@ data_only_disk_install_lvm() { ...@@ -654,7 +658,7 @@ data_only_disk_install_lvm() {
for diskdev in "$@"; do for diskdev in "$@"; do
setup_partitions $diskdev "$size,$part_type" || return 1 setup_partitions $diskdev "$size,$part_type" || return 1
done done
setup_lvm_volume_group $vgname $@ || return 1 setup_lvm_volume_group $vgname $@ || return 1
setup_lvm_swap $vgname setup_lvm_swap $vgname
lvcreate --quiet -n ${var_dev##*/} -l 100%FREE $vgname lvcreate --quiet -n ${var_dev##*/} -l 100%FREE $vgname
...@@ -699,7 +703,7 @@ data_only_disk_install() { ...@@ -699,7 +703,7 @@ data_only_disk_install() {
setup_var $var_dev setup_var $var_dev
} }
# setup # setup
setup_root() { setup_root() {
local root_dev="$1" boot_dev="$2" local root_dev="$1" boot_dev="$2"
mkfs.$ROOTFS -q "$root_dev" mkfs.$ROOTFS -q "$root_dev"
...@@ -777,7 +781,7 @@ native_disk_install() { ...@@ -777,7 +781,7 @@ native_disk_install() {
# will find BOOT_DEV for us # will find BOOT_DEV for us
setup_boot_dev $@ setup_boot_dev $@
if [ "$USE_RAID" ]; then if [ "$USE_RAID" ]; then
[ $SWAP_SIZE -gt 0 ] && setup_non_boot_raid_dev /dev/md1 $@ [ $SWAP_SIZE -gt 0 ] && setup_non_boot_raid_dev /dev/md1 $@
setup_non_boot_raid_dev /dev/md2 $@ || return 1 setup_non_boot_raid_dev /dev/md2 $@ || return 1
...@@ -812,7 +816,7 @@ You can select between 'sys' or 'data'. ...@@ -812,7 +816,7 @@ You can select between 'sys' or 'data'.
sys: sys:
This mode is a traditional disk install. The following partitions will be This mode is a traditional disk install. The following partitions will be
created on the disk: /boot, / (filesystem root) and swap. created on the disk: /boot, / (filesystem root) and swap.
This mode may be used for development boxes, desktops, virtual servers, etc. This mode may be used for development boxes, desktops, virtual servers, etc.
data: data:
...@@ -935,7 +939,7 @@ if [ -z "$disks" ]; then ...@@ -935,7 +939,7 @@ if [ -z "$disks" ]; then
fi fi
if [ $# -gt 0 ]; then if [ $# -gt 0 ]; then
# check that they are # check that they are
for i in "$@"; do for i in "$@"; do
j=$(readlink -f "$i" | sed 's:^/dev/::; s:/:!:g') j=$(readlink -f "$i" | sed 's:^/dev/::; s:/:!:g')
if ! [ -e "/sys/block/$j/device" ]; then if ! [ -e "/sys/block/$j/device" ]; then
...@@ -965,7 +969,7 @@ if [ -n "$diskdevs" ] && [ -z "$DISK_MODE" ]; then ...@@ -965,7 +969,7 @@ if [ -n "$diskdevs" ] && [ -z "$DISK_MODE" ]; then
disk_is_or_disks_are="disks are" disk_is_or_disks_are="disks are"
it_them="them" it_them="them"
fi fi
while true; do while true; do
echo "The following $disk_is_or_disks_are selected:" echo "The following $disk_is_or_disks_are selected:"
show_disk_info $diskdevs show_disk_info $diskdevs
......
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