Skip to content

Commit 931296a

Browse files
committed
Expect script to be running as root/under sudo
1 parent b8d707d commit 931296a

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

Microsoft/scripts/gen_modules_vhdx.sh

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,21 @@ tmp_dir=$(mktemp -d)
2323
dd if=/dev/zero of="$tmp_dir/modules.img" bs=1024 count=$((modules_size / 1024))
2424

2525
# Set up fs and mount
26-
lo_dev=$(sudo losetup --find --show "$tmp_dir/modules.img")
27-
sudo mkfs -t ext4 "$lo_dev"
26+
lo_dev=$(losetup --find --show "$tmp_dir/modules.img")
27+
mkfs -t ext4 "$lo_dev"
2828
mkdir "$tmp_dir/modules_img"
29-
sudo mount "$lo_dev" "$tmp_dir/modules_img"
30-
sudo chmod a+rw "$tmp_dir/modules_img"
29+
mount "$lo_dev" "$tmp_dir/modules_img"
30+
chmod a+rw "$tmp_dir/modules_img"
3131

3232
# Copy over the contents of $1
3333
cp -r "$1"/* "$tmp_dir/modules_img"
34-
sudo umount "$tmp_dir/modules_img"
34+
umount "$tmp_dir/modules_img"
3535

3636
# Do the final conversion
3737
qemu-img convert -O vhdx "$tmp_dir/modules.img" "$2"
3838

39+
# Fix ownership since we're probably running under sudo
40+
if [ -n "$SUDO_USER" ]; then
41+
chown "$SUDO_USER:$SUDO_USER" $2
42+
fi
43+

0 commit comments

Comments
 (0)