Skip to content

Commit 4a274c7

Browse files
committed
create bash script
0 parents  commit 4a274c7

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

script.sh

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
3+
# READ FILE
4+
echo -e "\n📄 Enter absolute path to img or iso file:"
5+
read FILE_PATH
6+
FILE=$(basename $FILE_PATH)
7+
FILE_NAME="${FILE%.*}"
8+
FILE_EXT="${FILE/*./}"
9+
10+
11+
# CHECK DEPENDENCIES
12+
# TODO
13+
14+
15+
# CHECK IF FILE EXISTS
16+
if [ ! -f "$FILE_PATH" ]; then
17+
echo -e "\n💥 Error: Could not find \"$FILE_PATH\""
18+
exit 1
19+
fi
20+
21+
22+
# CHECK FILE EXTENSION
23+
if [ "$FILE_EXT" != "img" ] && [ "$FILE_EXT" != "iso" ]; then
24+
echo -e "\n💥 Error: Expected file to be img or iso but recived \"$FILE_EXT\" instead"
25+
exit 1
26+
fi
27+
28+
29+
# TRANSFORM ISO TO IMG
30+
if [ "$FILE_EXT" == "iso" ]; then
31+
echo -e "\n💿 Creating img from iso"
32+
TEMPDIR=$(mktemp -d)
33+
hdiutil convert -format UDRW -o $TEMPDIR/$FILE_NAME.img $FILE_PATH
34+
mv $TEMPDIR/$FILE_NAME.img.dmg $TEMPDIR/$FILE_NAME.img
35+
FILE_PATH=$TEMPDIR/$FILE_NAME.img
36+
fi
37+
38+
39+
# WRITE IMG TO DISK
40+
echo -e "\n💾 Insert USB or SD card now"
41+
read -n 1 -s -r -p " Press any key to continue..."
42+
echo -e "\n"
43+
44+
diskutil list
45+
echo -e "\n⚠️ Enter the name of the volume you want to write the img on (e.g. disk3s1).\n The volume will be formatted and all data be lost, so select carefully!\n\n📝 Enter the name of your volume:"
46+
read VOLUME
47+
48+
echo -e "\n📀 Writing img to $VOLUME. This may take a while."
49+
diskutil unmountDisk /dev/$VOLUME
50+
sudo dd if=$FILE_PATH of=/dev/$VOLUME bs=1m
51+
afplay /System/Library/Sounds/Ping.aiff
52+
53+
54+
# CLEANUP
55+
echo -e "\n🧹 Cleaning up"
56+
rm -r $TEMPDIR&>/dev/null
57+
58+
59+
# DONE
60+
echo -e "\n🏁 Done"
61+
exit

0 commit comments

Comments
 (0)