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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 export SYS_BLOCK="/sys/class/block"
18 export CONSOLE_DEV="/dev/tty0"
19 export BOOTCD_LOCATION="/run/boot.iso"
20 export CLOUD_CONFIGS="/tmp/cloud_configs"
21 if (! declare -f warn );then
22 echo "warn function not defined assume running outside of dracut" > $CONSOLE_DEV
26 function is_using_boot_cd(){
27 if [ -a $BOOTCD_LOCATION ];then
35 echo $message > $CONSOLE_DEV
40 OUTPUT=$(echo $@ | /bin/bash)
42 logmsg "Failed to execute $@::$OUTPUT"
48 function read_devices(){
49 # Get list of block devices on the system
50 device_list=$(ls $SYS_BLOCK)
51 read -r -a hd_devices <<< $device_list
55 function check_params()
57 if [ $1 -ne $(($#-1)) ];then
58 echo "Not enough params for ${FUNCNAME[ 1 ]}" > $CONSOLE_DEV
68 if [ -e $dev ] && [ -b $dev ];then
70 mount -o ro -t iso9660 $dev $device_mount
74 if [ -e "$device_mount/guest-image.img" ];then
75 if ( $umount_on_found ); then
92 if [ -e $SYS_BLOCK/$device/loop ]; then
98 function is_partition(){
101 if [ -e $SYS_BLOCK/$device/partition ];then
107 function is_removable(){
110 sysdev=$SYS_BLOCK/$device
111 if ( is_partition $device );then
112 removable=$(readlink -f $sysdev/..)/removable
114 removable=$sysdev/removable
116 if [ -e $removable ] && [ $(cat $removable) -eq 1 ];then
124 function get_config_from_device_end(){
128 if [ -b $BOOTDEVICE ]; then
129 SKIP=$(($(blockdev --getsize64 $BOOTDEVICE)/2048-32))
130 dd if=$BOOTDEVICE of=/tmp/cloudconf.tgz bs=2k skip=$SKIP
131 if gzip -t /tmp/cloudconf.tgz 2>/dev/null ; then
132 logmsg "Copying cloud configurations to $CLOUD_CONFIGS"
133 mkdir -p $CLOUD_CONFIGS
134 tar xzf /tmp/cloudconf.tgz -C $CLOUD_CONFIGS
149 if [ ! -d $device_mount ];then
150 mkdir -p $device_mount
153 for device in ${hd_devices[@]}; do
154 if ( is_removable $device );then
155 if ( try_mount /dev/$device $device_mount $umount_on_found );then
156 logmsg "installmedia: found image from device $device."
157 export BOOTDEVICE=/dev/${device}