fixes and cleanup
[webi-installers/.git] / macos / macos.bash
1 # title: macOS
2 # homepage: https://bootableinstaller.com/macos/
3 # tagline: Bootable macOS Installer
4 # description: |
5 #   Downloads the official OS X / macOS dmg from Apple to create bootable installers - works from macOS, Linux, or even Windows (through VirtualBox).
6 # examples: |
7 #
8 #   Use with Balena Etcher to burn ISO to USB, or boot with VirtualBox.
9 #
10 #   ```txt
11 #   Created ~/Downloads/el-capitan.iso
12 #   ```
13
14 set -e
15 set -u
16
17 if [ -z "${WEBI_PKG_URL:-}" ]; then
18   # dmg
19   release_tab="${WEBI_HOST}/api/releases/macos@${WEBI_VERSION:-}.csv?os=$(uname -s)&arch=$(uname -m)&limit=1"
20   WEBI_CSV=$(curl -fsSL "$release_tab" -H "User-Agent: $(uname -a)")
21   WEBI_CHANNEL=$(echo $WEBI_CSV | cut -d ',' -f 3)
22   if [ "error" == "$WEBI_CHANNEL" ]; then
23      echo "could not find release for macOS v${WEBI_VERSION}"
24      exit 1
25   fi
26   WEBI_VERSION=$(echo $WEBI_CSV | cut -d ',' -f 1)
27   WEBI_PKG_URL=$(echo $WEBI_CSV | cut -d ',' -f 9)
28 fi
29
30 mkdir -p ~/Downloads
31 pushd ~/Downloads 2>&1 >/dev/null
32
33 # TODO use downloads directory because this is big
34 set +e
35 if [ -n "$(command -v wget)" ]; then
36   # better progress bar
37   wget -c "${WEBI_PKG_URL}"
38 else
39   curl -fL "${WEBI_PKG_URL}" -o "$(echo "${WEBI_PKG_FILE}" | sed 's:.*/::' )"
40 fi
41 set -e
42
43 if [ "Darwin" == "$(uname -s)" ]; then
44   curl -fsSL 'https://gist.githubusercontent.com/solderjs/8c36d132250163011c83bad8284975ee/raw/5a291955813743c20c12ca2d35c7b1bb34f8aecc/create-bootable-installer-for-os-x-el-capitan.sh' -o create-bootable-installer-for-os-x-el-capitan.sh
45   bash create-bootable-installer-for-os-x-el-capitan.sh
46 else
47   curl -fsSL 'https://gist.githubusercontent.com/solderjs/9834a45a6c21a41e8882698a00b55787/raw/c43061cd0c53ec675996f5cb66c7077e666aabd4/install-mac-tools.sh' -o install-mac-tools.sh
48   bash install-mac-tools.sh
49
50   curl -fsSL 'https://gist.github.com/solderjs/04fd06560a8465a695337eb502f5b0e9/raw/0a06fb4dce91399d374d9a12958dabb48a9bd42a/empty.7400m.img.bz2' -o empty.7400m.img.bz2
51
52   curl -fsSL 'https://gist.githubusercontent.com/solderjs/9834a45a6c21a41e8882698a00b55787/raw/c43061cd0c53ec675996f5cb66c7077e666aabd4/linux-create-bootable-macos-recovery-image.sh' -o linux-create-bootable-macos-recovery-image.sh
53   bash linux-create-bootable-macos-recovery-image.sh
54 fi
55
56 echo ""
57 echo "Created $HOME/Downloads/el-capitan.iso"
58 echo ""
59
60 popd 2>&1 >/dev/null