-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathresize-disk.bash
executable file
·45 lines (45 loc) · 1.42 KB
/
resize-disk.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
set -exo pipefail
[[ ! $EUID -eq 0 ]] && echo "RUN AS ROOT!" && exit 1
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd $SCRIPT_DIR
. ./_helpers.bash
fin() {
echo "finished" > /tmp/resize-disk.status
}
trap fin EXIT
echo "running" > /tmp/resize-disk.status
if [[ ! -e "${RESIZE_DISK_PLIST_PATH}" ]]; then
cat > "${RESIZE_DISK_PLIST_PATH}" <<EOD
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>aws-ec2-mac-amis-resize-disk</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/env</string>
<string>bash</string>
<string>-c</string>
<string>/Users/${AWS_INSTANCE_USER:-"ec2-user"}/aws-ec2-mac-amis/resize-disk.bash</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>WorkingDirectory</key>
<string>/Users/${AWS_INSTANCE_USER:-"ec2-user"}</string>
<key>StandardErrorPath</key>
<string>/var/log/resize-disk.log</string>
<key>StandardOutPath</key>
<string>/var/log/resize-disk.log</string>
</dict>
</plist>
EOD
launchctl load -w "${RESIZE_DISK_PLIST_PATH}"
else
# Modify the disk
PDISK=$(diskutil list physical external | head -n1 | cut -d" " -f1)
APFSCONT=$(diskutil list physical external | grep "Apple_APFS" | tr -s " " | cut -d" " -f8)
echo "y" | diskutil repairDisk $PDISK
diskutil apfs resizeContainer $APFSCONT 0
fi