Seed code for image-provision
[ta/image-provision.git] / dracut / modules / 00readfloppyconf / copy_floppy_config.sh
1 #!/bin/sh
2
3 # Copyright 2019 Nokia
4
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 USER_CONFIG_NAME="user_config.yaml"
18 CLOUD_CONFIGS="/tmp/cloud_configs"
19
20 source /usr/lib/installmedia-lib.sh
21
22 FLOPPYMOUNT="/tmp/floppy"
23
24 warn "copy_floppy_config: Checking if there are any floppy devices and cloud user yaml files in it."
25 if [ -d ${CLOUD_CONFIGS} ];then
26   warn "copy_floppy_config: Seems Configs are fetched from CD. Returning from this module"
27   return
28 fi
29
30 mkdir -p $FLOPPYMOUNT
31
32 # Define function to copy files to /tmp/cloud_configs
33 function copyfilesfromfloppy() {
34     mount -o ro ${floppydev} $FLOPPYMOUNT
35     if [ ! -e "$FLOPPYMOUNT/$USER_CONFIG_NAME" ];then
36         warn "This filesystem does not contain user config... bailing out"
37         umount $FLOPPYMOUNT
38         return 1
39     fi
40     warn "copy files in ${floppydev} to ${CLOUD_CONFIGS}..."
41     mkdir -p ${CLOUD_CONFIGS}
42     cp -rf $FLOPPYMOUNT/* ${CLOUD_CONFIGS}
43     umount $FLOPPYMOUNT
44     return 0
45 }
46
47 read_devices
48 for device in "${hd_devices[@]}"; do
49     if ( is_removable $device ); then
50         #This device is a removable device. Check if it contains user_config
51         floppydev="/dev/${device}"
52         if ( copyfilesfromfloppy ); then
53             warn "copy_floppy_config: Device found on ${floppydev}"
54             break
55         else
56             floppydev=""
57         fi
58     fi
59 done
60
61 if [ -z ${floppydev} ]; then
62     warn "copy_floppy_config: No floppy device found"
63 else
64     warn "copy_floppy_config: Cloud configurations copied to ${CLOUD_CONFIGS}"
65 fi