X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=blobdiff_plain;f=work%2Fdib-ipa-element%2Fvirtmedia-netconf%2Fironic-virtmedia-netconfig%2Fbin%2Ferase-oldfs.sh;h=ffe03771e2f4452d605d98741d224cbaaef3bade;hb=d5fbdc015ecb5379809b00d21ee5064582d368a4;hp=006963ed99b5da108ece41683114e121c7f03ee3;hpb=ffee968ccc39318c855aa9ac2b161c06681a6b5a;p=ta%2Fipa-deployer.git diff --git a/work/dib-ipa-element/virtmedia-netconf/ironic-virtmedia-netconfig/bin/erase-oldfs.sh b/work/dib-ipa-element/virtmedia-netconf/ironic-virtmedia-netconfig/bin/erase-oldfs.sh index 006963e..ffe0377 100755 --- a/work/dib-ipa-element/virtmedia-netconf/ironic-virtmedia-netconfig/bin/erase-oldfs.sh +++ b/work/dib-ipa-element/virtmedia-netconf/ironic-virtmedia-netconfig/bin/erase-oldfs.sh @@ -16,41 +16,59 @@ SYS_BLOCK="/sys/class/block" -function is_partition(){ - device=$1 - if [ -e $SYS_BLOCK/$device/partition ];then - return 0 - else - return 1 - fi -} - -function is_removable(){ - device=$1 - sysdev=$SYS_BLOCK/$device - if ( is_partition $device );then - removable=$(readlink -f $sysdev/..)/removable - else - removable=$sysdev/removable - fi - if [ -e $removable ] && [ $(cat $removable) -eq 1 ];then - return 0 - else +if ( grep -q "^flags.*hypervisor" /proc/cpuinfo ); then + echo "Not excuting in Virtual machine" +else + function is_partition(){ + device=$1 + if [ -e $SYS_BLOCK/$device/partition ];then + return 0 + else + return 1 + fi + } + + function is_removable(){ + device=$1 + sysdev=$SYS_BLOCK/$device + if ( is_partition $device );then + removable=$(readlink -f $sysdev/..)/removable + else + removable=$sysdev/removable + fi + if [ -e $removable ] && [ $(cat $removable) -eq 1 ];then + return 0 + else + return 1 + fi + + } + + function is_loop(){ + device=$1 + if [ -e $SYS_BLOCK/$device/loop ]; then + return 0 + fi return 1 - fi + } -} -device_list=$(ls $SYS_BLOCK) -read -r -a hd_devices <<< $device_list + device_list=$(ls $SYS_BLOCK) + read -r -a hd_devices <<< $device_list -for hd_dev in ${hd_devices[@]}; do - if [ -b /dev/$hd_dev ] && (( is_removable $hd_dev ) || ( is_partition $hd_dev )); then - echo "Removable or partition $hd_dev. Skipping..." - continue - fi - wipefs --all /dev/$hd_dev - sgdisk -Z -o /dev/$hd_dev - dd if=/dev/zero of=/dev/$hd_dev bs=1M count=200 -done + for hd_dev in ${hd_devices[@]}; do + if [ -b /dev/$hd_dev ] && (( is_removable $hd_dev ) || ( is_partition $hd_dev ) || ( is_loop $hd_dev )); then + echo "Removable or partition $hd_dev. Skipping..." + continue + elif ! [ -b /dev/$hd_dev ]; then + continue + fi + wipefs --all /dev/$hd_dev + sgdisk -Z -o /dev/$hd_dev + dd if=/dev/zero of=/dev/$hd_dev bs=1M count=1 + done + sync + udevadm settle + partprobe +fi