1
This commit is contained in:
commit
b5c7f1fdc4
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
images/*.qcow2
|
10
Makefile
Normal file
10
Makefile
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
all: install-deps choose-image
|
||||||
|
|
||||||
|
install-deps:
|
||||||
|
apt update
|
||||||
|
apt install qemu-utils -y
|
||||||
|
|
||||||
|
choose-image:
|
||||||
|
bash gen-write-image-command.sh
|
||||||
|
|
||||||
|
|
93
gen-write-image-command.sh
Normal file
93
gen-write-image-command.sh
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
function showDisksInfo() {
|
||||||
|
echo "blkid output:"
|
||||||
|
echo "###"
|
||||||
|
blkid
|
||||||
|
echo "###"
|
||||||
|
echo
|
||||||
|
echo "lsblk outpu:"
|
||||||
|
echo "####"
|
||||||
|
lsblk
|
||||||
|
echo "####"
|
||||||
|
}
|
||||||
|
|
||||||
|
function listImages() {
|
||||||
|
find images/ -name *.qcow2 -type f
|
||||||
|
}
|
||||||
|
|
||||||
|
function listDisks() {
|
||||||
|
disk=()
|
||||||
|
size=()
|
||||||
|
name=()
|
||||||
|
while IFS= read -r -d $'\0' device; do
|
||||||
|
device=${device/\/dev\//}
|
||||||
|
disk+=($device)
|
||||||
|
name+=("`cat "/sys/class/block/$device/device/model"`")
|
||||||
|
size+=("`cat "/sys/class/block/$device/size"`")
|
||||||
|
done < <(find "/dev/" -regex '/dev/sd[a-z]\|/dev/vd[a-z]\|/dev/hd[a-z]' -print0)
|
||||||
|
|
||||||
|
for i in `seq 0 $((${#disk[@]}-1))`; do
|
||||||
|
echo -e "${disk[$i]}\t${name[$i]}\t${size[$i]}"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
showDisksInfo
|
||||||
|
|
||||||
|
echo 'Please select from the DISKS list:'
|
||||||
|
disks=$(listDisks)
|
||||||
|
echo -e "$disks" | nl;
|
||||||
|
count="$(echo -e "$disks" | wc -l)"
|
||||||
|
read -p 'Select option: ' n
|
||||||
|
for i in `echo -e "$disks" | nl`;
|
||||||
|
do
|
||||||
|
if [ "$n" == "$i" ]; then
|
||||||
|
value=$(echo -e "$disks" | sed -n ${i}p) 2>&1
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done;
|
||||||
|
echo "The user selected option number $n: '$value'"
|
||||||
|
DISK="${value}"
|
||||||
|
DISK_FD="$(echo "/dev/$(echo "${value}" |awk '{ print $1}')")"
|
||||||
|
|
||||||
|
echo "You choose the next disk:"
|
||||||
|
echo "${DISK_FD}"
|
||||||
|
|
||||||
|
read -r -p "Are you sure? [y/N] " response
|
||||||
|
case "$response" in
|
||||||
|
[yY][eE][sS]|[yY])
|
||||||
|
echo 'Please select image from the list:'
|
||||||
|
images=$(listImages)
|
||||||
|
echo -e "$images" | nl;
|
||||||
|
count="$(echo -e "$images" | wc -l)"
|
||||||
|
read -p 'Select option: ' n
|
||||||
|
for i in `echo -e "$images" | nl`;
|
||||||
|
do
|
||||||
|
if [ "$n" == "$i" ]; then
|
||||||
|
value=$(echo -e "$images" | sed -n ${i}p) 2>&1
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done;
|
||||||
|
echo "The user selected option number $n: '$value'"
|
||||||
|
IMAGE="${value}"
|
||||||
|
|
||||||
|
read -r -p "Are you sure? [y/N] " response
|
||||||
|
case "$response" in
|
||||||
|
[yY][eE][sS]|[yY])
|
||||||
|
echo "Command is:"
|
||||||
|
echo "qemu-img convert -p -f qcow2 -O raw ${IMAGE} ${DISK_FD}"
|
||||||
|
echo "Good luck"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "You choose to exit"
|
||||||
|
# Exit politly
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "You choose to exit"
|
||||||
|
|
||||||
|
# Exit politly
|
||||||
|
;;
|
||||||
|
esac
|
0
images/.placeholder
Normal file
0
images/.placeholder
Normal file
11
scripts/are-you-sure.sh
Normal file
11
scripts/are-you-sure.sh
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
read -r -p "Are you sure? [y/N] " response
|
||||||
|
case "$response" in
|
||||||
|
[yY][eE][sS]|[yY])
|
||||||
|
# Write to disk
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
# Exit politly
|
||||||
|
;;
|
||||||
|
esac
|
93
scripts/gen-write-image-command.sh
Normal file
93
scripts/gen-write-image-command.sh
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
function showDisksInfo() {
|
||||||
|
echo "blkid output:"
|
||||||
|
echo "###"
|
||||||
|
blkid
|
||||||
|
echo "###"
|
||||||
|
echo
|
||||||
|
echo "lsblk outpu:"
|
||||||
|
echo "####"
|
||||||
|
lsblk
|
||||||
|
echo "####"
|
||||||
|
}
|
||||||
|
|
||||||
|
function listImages() {
|
||||||
|
find images/ -name *.qcow2 -type f
|
||||||
|
}
|
||||||
|
|
||||||
|
function listDisks() {
|
||||||
|
disk=()
|
||||||
|
size=()
|
||||||
|
name=()
|
||||||
|
while IFS= read -r -d $'\0' device; do
|
||||||
|
device=${device/\/dev\//}
|
||||||
|
disk+=($device)
|
||||||
|
name+=("`cat "/sys/class/block/$device/device/model"`")
|
||||||
|
size+=("`cat "/sys/class/block/$device/size"`")
|
||||||
|
done < <(find "/dev/" -regex '/dev/sd[a-z]\|/dev/vd[a-z]\|/dev/hd[a-z]' -print0)
|
||||||
|
|
||||||
|
for i in `seq 0 $((${#disk[@]}-1))`; do
|
||||||
|
echo -e "${disk[$i]}\t${name[$i]}\t${size[$i]}"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
showDisksInfo
|
||||||
|
|
||||||
|
echo 'Please select from the DISKS list:'
|
||||||
|
disks=$(listDisks)
|
||||||
|
echo -e "$disks" | nl;
|
||||||
|
count="$(echo -e "$disks" | wc -l)"
|
||||||
|
read -p 'Select option: ' n
|
||||||
|
for i in `echo -e "$disks" | nl`;
|
||||||
|
do
|
||||||
|
if [ "$n" == "$i" ]; then
|
||||||
|
value=$(echo -e "$disks" | sed -n ${i}p) 2>&1
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done;
|
||||||
|
echo "The user selected option number $n: '$value'"
|
||||||
|
DISK="${value}"
|
||||||
|
DISK_FD="$(echo "/dev/$(echo "${value}" |awk '{ print $1}')")"
|
||||||
|
|
||||||
|
echo "You choose the next disk:"
|
||||||
|
echo "${DISK_FD}"
|
||||||
|
|
||||||
|
read -r -p "Are you sure? [y/N] " response
|
||||||
|
case "$response" in
|
||||||
|
[yY][eE][sS]|[yY])
|
||||||
|
echo 'Please select image from the list:'
|
||||||
|
images=$(listImages)
|
||||||
|
echo -e "$images" | nl;
|
||||||
|
count="$(echo -e "$images" | wc -l)"
|
||||||
|
read -p 'Select option: ' n
|
||||||
|
for i in `echo -e "$images" | nl`;
|
||||||
|
do
|
||||||
|
if [ "$n" == "$i" ]; then
|
||||||
|
value=$(echo -e "$images" | sed -n ${i}p) 2>&1
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done;
|
||||||
|
echo "The user selected option number $n: '$value'"
|
||||||
|
IMAGE="${value}"
|
||||||
|
|
||||||
|
read -r -p "Are you sure? [y/N] " response
|
||||||
|
case "$response" in
|
||||||
|
[yY][eE][sS]|[yY])
|
||||||
|
echo "Command is:"
|
||||||
|
echo "qemu-img convert -p -f qcow2 -O raw ${IMAGE} ${DISK_FD}"
|
||||||
|
echo "Good luck"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "You choose to exit"
|
||||||
|
# Exit politly
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "You choose to exit"
|
||||||
|
|
||||||
|
# Exit politly
|
||||||
|
;;
|
||||||
|
esac
|
15
scripts/list-disks.sh
Normal file
15
scripts/list-disks.sh
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
disk=()
|
||||||
|
size=()
|
||||||
|
name=()
|
||||||
|
while IFS= read -r -d $'\0' device; do
|
||||||
|
device=${device/\/dev\//}
|
||||||
|
disk+=($device)
|
||||||
|
name+=("`cat "/sys/class/block/$device/device/model"`")
|
||||||
|
size+=("`cat "/sys/class/block/$device/size"`")
|
||||||
|
done < <(find "/dev/" -regex '/dev/sd[a-z]\|/dev/vd[a-z]\|/dev/hd[a-z]' -print0)
|
||||||
|
|
||||||
|
for i in `seq 0 $((${#disk[@]}-1))`; do
|
||||||
|
echo -e "${disk[$i]}\t${name[$i]}\t${size[$i]}"
|
||||||
|
done
|
Loading…
Reference in New Issue
Block a user