Seed code for ipa-deployer
[ta/ipa-deployer.git] / work / dib-ipa-element / virtmedia-netconf / ironic-virtmedia-netconfig / bin / erase-oldfs.sh
1 #!/bin/bash
2 # Copyright 2019 Nokia
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16
17 SYS_BLOCK="/sys/class/block"
18
19 function is_partition(){
20     device=$1
21     if [ -e $SYS_BLOCK/$device/partition ];then
22         return 0
23     else
24         return 1
25     fi
26 }
27
28 function is_removable(){
29     device=$1
30     sysdev=$SYS_BLOCK/$device
31     if ( is_partition $device );then
32         removable=$(readlink -f $sysdev/..)/removable
33     else
34         removable=$sysdev/removable
35     fi
36     if [ -e $removable ] && [ $(cat $removable) -eq 1 ];then
37         return 0
38     else
39         return 1
40     fi
41
42 }
43
44 device_list=$(ls $SYS_BLOCK)
45 read -r -a hd_devices <<< $device_list
46
47
48 for hd_dev in ${hd_devices[@]}; do
49     if [ -b /dev/$hd_dev ] && (( is_removable $hd_dev ) || ( is_partition $hd_dev )); then
50         echo "Removable or partition $hd_dev. Skipping..."
51         continue
52     fi
53     wipefs --all /dev/$hd_dev
54     sgdisk -Z -o /dev/$hd_dev
55     dd if=/dev/zero of=/dev/$hd_dev bs=1M count=200
56 done