Skip to content

Commit 13c3beb

Browse files
committed
Merge feature/wsl-module-script/6.6 into v6.6.75
* commit '81cf9788968652ae141d52b22667be98c78b6117': Fix shellcheck issues Expect script to be running as root/under sudo First pass at a script
2 parents f5a3a3b + 81cf978 commit 13c3beb

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
set -ueo pipefail
3+
4+
if [ $# -ne 2 ] || [ ! -d "$1" ]; then
5+
printf '%s' "Usage ./$0 <modules dir> <output file>" 1>&2
6+
exit 1
7+
fi
8+
9+
if [ -e "$2" ]; then
10+
printf '%s' "Refusing to overwrite existing file $2" 1>&2
11+
exit 2
12+
fi
13+
14+
15+
# Calculate modules size (+ 256MiB for slack)
16+
modules_size=$(du -bs "$1" | awk '{print $1;}')
17+
modules_size=$((modules_size + (256*(1<<20))))
18+
19+
# Create our scratch directory
20+
tmp_dir=$(mktemp -d)
21+
22+
# Create a blank image file of the right size
23+
dd if=/dev/zero of="$tmp_dir/modules.img" bs=1024 count=$((modules_size / 1024))
24+
25+
# Set up fs and mount
26+
lo_dev=$(losetup --find --show "$tmp_dir/modules.img")
27+
mkfs -t ext4 "$lo_dev"
28+
mkdir "$tmp_dir/modules_img"
29+
mount "$lo_dev" "$tmp_dir/modules_img"
30+
chmod a+rw "$tmp_dir/modules_img"
31+
32+
# Copy over the contents of $1
33+
cp -r "$1"/* "$tmp_dir/modules_img"
34+
umount "$tmp_dir/modules_img"
35+
36+
# Do the final conversion
37+
qemu-img convert -O vhdx "$tmp_dir/modules.img" "$2"
38+
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)