This commit is contained in:
j3d1 2020-01-29 13:33:53 +01:00
parent 8292892021
commit cc3834f211
2 changed files with 73 additions and 1 deletions

View file

@ -1,5 +1,7 @@
#!/bin/bash #!/bin/bash
source $(dirname $0)/utils.sh
function first_stage(){ function first_stage(){
echo foo first_stage echo foo first_stage
echo creating image file echo creating image file
@ -16,12 +18,29 @@ function first_stage(){
) | fdisk ${LODEV} ) | fdisk ${LODEV}
losetup -d ${LODEV} losetup -d ${LODEV}
LODEV=$(losetup --show -fP /root/disk.img) LODEV=$(losetup --show -fP /root/disk.img)
lsblk
echo using device $LODEV echo using device $LODEV
echo mount divice to $TARGET echo mount divice to $TARGET
mount $LODEVp1 $TARGET
echo debootstrap sid $TARGET
} }
function second_stage(){ function second_stage(){
echo bar second_stage echo bar second_stage
} }
function test_fun(){
#choose_one test1 | prefix_time
#sleep 1
block_devices | choose_one -
echo "> "$test
#sleep 1
#choose_one | prefix_time
}
if [ $# -eq 1 ]; then
if [ $1 = "test" ]; then
test_fun
fi
fi

53
utils.sh Executable file
View file

@ -0,0 +1,53 @@
#!/bin/bash
function prefix_time(){
while read LINE; do
echo "["$(date)"] "$LINE
done
}
function one_token_per_line(){
for L in $1; do
echo $L
done
}
function choose_one(){
if [ $# -eq 0 ]; then
echo missing argument 1>&2
exit 1
fi
if [ "$1" = "-" ]; then
touch internal_pipe
CNT=0
tee internal_pipe | while read LINE; do
CNT=$(($CNT+1))
echo " "$CNT" > "$LINE
done
read -p "enter a number: " -u 1 NUM
CNT=$(cat internal_pipe | wc -l)
if [ "" = $NUM ]; then echo empty input; exit 1; fi
if [ 0 -ge $NUM ]; then echo too small; exit 1; fi
if [ $CNT -lt $NUM ]; then echo too large; exit 1; fi
cat internal_pipe | head -n +$NUM | tail -n +$NUM
rm internal_pipe
else
cat $1 | choose_one -
fi
}
function block_devices(){
#lsblk -fPpo NAME,FSTYPE,LABEL,UUID,FSAVAIL,MOUNTPOINT
lsblk -frpno NAME
}
function foo(){
while read LINE; do
(
export $LINE
echo "> "$NAME
)
done
}