-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathmac-install.sh
More file actions
executable file
·476 lines (409 loc) · 18.9 KB
/
Copy pathmac-install.sh
File metadata and controls
executable file
·476 lines (409 loc) · 18.9 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
#!/bin/bash
#==============================================================================
#==============================================================================
# Copyright (c) 2015 Jonathan Yantis
# yantis@yantis.net
# Released under the MIT license
#==============================================================================
#==============================================================================
###############################################################################
# USAGE:
# sh mac-install.sh 50 (would leave 50GB for mac and the rest for Arch Linux)
# sh mac-install.sh USB (Installs to USB drive - Still needs more work on boot)
###############################################################################
# Set the disk we are working on. For USB this may change later.
# The default is disk0
###############################################################################
ROOTDISK=disk0
###############################################################################
# Exit on any error whatsoever
# You should be able to just rerun the script at any point and it should
# recover where it left off from.
###############################################################################
set -e
set -u
###############################################################################
# Usage
###############################################################################
# Exit the script if the user didn't specify MacOS volume size
if [ "$#" -ne 1 ]; then
echo "You must either specify USB or the new MacOs Volume size"
echo ""
echo "In specifiing the size you want your MacOs Volume to be"
echo "It must be at least as big as the data it contains"
echo "On a new install 30GB probably works OK if you are going for minimal"
echo "In this case you would run the script with 30 as the argument"
exit 1
fi
###############################################################################
# Keep trying to unmount for up to 10 seconds. Some slow USBs can take a bit.
###############################################################################
unmount()
{
timeout=$(($(date +%s) + 10))
until sudo diskutil umount "${1}" 2>/dev/null || [[ $(date +%s) -gt $timeout ]]; do
:
done
}
###############################################################################
# Disable sudo password request time out for now.
# Editing sudoers this way on a mac really is no big deal.
# You can quickly fix any mistakes you make to it by:
# Hitting shift+⌘-+g typing /etc. Selecting sudoers and hitting ⌘-+i
# then unlock it and change your permissions to fix it.
###############################################################################
echo "Temporarily Disabling sudo password timeout"
sudo sh -c 'echo "\nDefaults timestamp_timeout=-1">>/etc/sudoers'
###############################################################################
# Mute startup chime
# Unrem this to mute the startup chime (or set the volume 01 to 99 I think)
###############################################################################
# sudo /usr/sbin/nvram SystemAudioVolume=%01
###############################################################################
# Update Mac OSX
# particually any firmware updates (though lets leave this up to the user)
###############################################################################
# sudo softwareupdate -i -a
###############################################################################
# Convert from Core Storage to HFS+ if needed.
###############################################################################
if diskutil info ${ROOTDISK}s2 | grep -q "Core Storage" ; then
#TODO check if encrypted first.and decrypt
#https://derflounder.wordpress.com/2011/11/23/using-the-command-line-to-unlock-or-decrypt-your-filevault-2-encrypted-boot-drive/
#TODO Play with the fusion drive (the latest imac retina has one)
# Note if they have a fusion drive then this will most likely fail with an error.
# "This operation can only be performed if there is one Core Storage physical voluume present in the group"
echo "Disk ${ROOTDISK}s2 is a Core Storage Volume. Converting to HFS+"
COREVOLUME=$(diskutil list | grep -A1 "Logical Volume on ${ROOTDISK}s2" | tail -1)
sudo diskutil coreStorage revert $COREVOLUME
echo "YOU MUST REBOOT and rerun the script to continue from this point."
exit 1
fi
###############################################################################
# Install CLI developer tools (a dependency for homebrew and more)
###############################################################################
echo "Installing CLI developer tools"
if ! hash brew 2> /dev/null; then
curl -O https://raw.githubusercontent.com/timsutton/osx-vm-templates/master/scripts/xcode-cli-tools.sh
sudo sh xcode-cli-tools.sh
rm xcode-cli-tools.sh
else
echo "CLI developer tools already installed."
fi
###############################################################################
# Install homebrew
###############################################################################
if ! hash brew 2> /dev/null; then
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" </dev/null
else
echo "Updating homebrew"
if ! brew update; then
echo "Homebrew Update Error. Fixing Permissions"
sudo chown -R $(whoami) /usr/local
echo "Attempting to fix and update homebrew"
brew uninstall --force brew-cask
brew update
fi
fi
###############################################################################
# Install wget to download Virtualbox
###############################################################################
# if ! hash wget 2> /dev/null; then
# brew install wget
# fi
###############################################################################
# Install Virtualbox
###############################################################################
if ! hash vboxmanage 2> /dev/null; then
echo "*** Installing VirtualBox ***"
# curl -OL http://download.virtualbox.org/virtualbox/5.1.8/VirtualBox-5.1.8-111374-OSX.dmg
curl -OL http://download.virtualbox.org/virtualbox/5.1.14/VirtualBox-5.1.14-112924-OSX.dmg
# hdiutil mount VirtualBox-5.1.8-111374-OSX.dmg
hdiutil mount VirtualBox-5.1.14-112924-OSX.dmg
sudo installer -pkg /Volumes/VirtualBox/VirtualBox.pkg -target /
sleep 2
hdiutil unmount /Volumes/VirtualBox/
# rm VirtualBox-5.0.24-108355-OSX.dmg
fi
###############################################################################
# Install docker-machine
###############################################################################
if ! hash docker-machine 2> /dev/null; then
echo "*** Installing Docker Machine***"
if ! brew install docker-machine; then
echo "Xcode 8.1 error most likely. Sadly for now you need to get this from developer.apple.com and install by hand "
exit 1
# echo "Xcode 8.1 error most likely so installing from the source site"
# curl -L https://github.com/docker/machine/releases/download/v0.8.2/docker-machine-`uname -s`-`uname -m` >/usr/local/bin/docker-machine
# chmod +x /usr/local/bin/docker-machine
fi
fi
###############################################################################
echo "Initialize docker-machine"
###############################################################################
if ! docker-machine status docker-vm 2> /dev/null; then
echo "*** Initialize docker-machine ***"
docker-machine create --driver virtualbox docker-vm
fi
###############################################################################
# Install Docker
###############################################################################
if ! hash docker 2> /dev/null; then
echo "Installing docker"
if ! brew install docker; then
echo "Xcode 8.1 error most likely. Sadly for now you need to get this from developer.apple.com and install by hand "
exit 1
fi
fi
###############################################################################
# Install boot2docker
###############################################################################
if ! hash boot2docker 2> /dev/null; then
echo "Installing boot2docker"
if ! brew install boot2docker; then
echo "Xcode 8.1 error most likely. Sadly for now you need to get this from developer.apple.com and install by hand "
exit 1
fi
fi
###############################################################################
# Install ZSH and Oh-my-zsh
# You don't need this but I like it when working with this since while debugging this script
###############################################################################
if ! hash zsh 2> /dev/null; then
echo "brew install zsh" > install_zsh.sh
echo "curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh" >> install_zsh.sh
fi
###############################################################################
# Install Paragon ExtFS
###############################################################################
if ! hash fsck_ufsd_ExtFS 2> /dev/null; then
curl -O http://dl.paragon-software.com/demo/extmac10_trial.dmg
hdiutil attach extmac10_trial.dmg
# sudo installer -pkg /Volumes/ParagonFS.localized/FSInstaller.app/Contents/Resources/Paragon\ ExtFS\ for\ Mac\ OS\ X.pkg -target /
sudo installer -pkg /Volumes/ParagonFS.localized/FSInstaller.app/Contents/Resources/Paragon\ ExtFS\ for\ Mac.pkg -target /
sleep 2
hdiutil detach -force /Volumes/ParagonFS.localized
rm extmac10_trial.dmg
fi
###############################################################################
echo "Resize Disk"
###############################################################################
# Did the user select USB, Usb, usb instead of a disk size?
INSTALL_TYPE=$(echo $1 | tr '[:upper:]' '[:lower:]')
if [ $INSTALL_TYPE == "usb" ]; then
# Detect the first USB disk
USBDISK="NONE"
for i in $(diskutil list | grep -E "[ ]+[0-9]+:.*disk[0-9]+" | sed 's/.*\(disk.*\)/\1/');
do
if diskutil info $i | grep -q "USB"; then
USBDISK=$i
break
fi
done
if [ $USBDISK == "NONE" ]; then
echo "No USB Disk found. Exiting"
exit 1
else
echo USB DISK $USBDISK found.
ROOTDISK=$USBDISK
if ! diskutil eraseDISK UFSD_EXTFS4 "1" $USBDISK; then
echo "Erase failed. Try rebooting and rerunning the script"
fi
fi
else
echo "Resize MacOs drive to X gb and create ext4 volume"
# TODO: This could be improved to detect disks like we do with the USB above.
# if diskutil list ${ROOTDISK} | grep -q "Microsoft Basic Data" ; then
if diskutil list ${ROOTDISK} | grep -q "Linux Filesystem" ; then
echo "Skipping disk resize and ext4 volume creation since already done."
echo "Formating Disk."
diskutil eraseVolume UFSD_EXTFS4 "1" ${ROOTDISK}s4
echo "Disk formated"
else
sudo diskutil resizeVolume ${ROOTDISK}s2 ${1}g 1 UFSD_EXTFS4 "1" 0g
fi
fi
echo "Get our ext4 volume. It should always be at disk0s4. But just in case."
# EXT4VOL=$(diskutil list ${ROOTDISK} | grep "Microsoft Basic Data" | awk '{print $8}')
EXT4VOL=$(diskutil list ${ROOTDISK} | grep "Linux Filesystem" | awk '{print $7}')
echo $EXT4VOL
# Sanity Check
if echo $EXT4VOL | grep -q "${ROOTDISK}s" ; then
echo "Our ext4 volume is $EXT4VOL"
else
echo "Could not find our ext4 volume. Try deleting all the volumes except Macintosh HD and restarting your computer."
echo "It is also possible that your Paragon ExtFS Trial has expired."
exit 1
fi
###############################################################################
echo "Setting up Virtual Disk to Physical Disk mapping"
###############################################################################
# If boo2docker is already running then something went wrong and the user restarted the script
if ! [ "$(docker-machine status docker-vm)" = "Running" ] ; then
# Create some temp file names for our virtual disks.
MAINDISK=`mktemp /tmp/main.vmdk.XXXXXX` || exit 1
rm $MAINDISK
# Make sure main disk is unmounted
if [ -d /Volumes/1 ];
then
unmount $EXT4VOL
fi
echo "Creating vmdk"
sudo vboxmanage internalcommands createrawvmdk -filename $MAINDISK -rawdisk /dev/$EXT4VOL
sudo chmod 666 $MAINDISK
sudo chmod 666 /dev/$EXT4VOL
echo "storageattach"
vboxmanage storageattach docker-vm --storagectl "SATA" --port 2 --device 0 --type hdd --medium $MAINDISK
echo "starting docker-vm"
docker-machine start docker-vm
fi
###############################################################################
echo "Get Boot2Docker exports"
docker-machine regenerate-certs docker-vm --force
eval "$(docker-machine env docker-vm)"
###############################################################################
###############################################################################
# Generate system profile so we have information about this machine inside the VM
# If it exists as a directory delete it. (why does this keep getting created?)
###############################################################################
if [ -d ~/systeminfo.txt ];
then
echo "Removing systeminfo.txt directory"
rm -r ~/systeminfo.txt
fi
if [ ! -f ~/systeminfo.txt ];
then
echo "Generating system profile"
system_profiler -detailLevel mini > ~/systeminfo.txt
fi
###############################################################################
# Download the rootfs
###############################################################################
if [ ! -f ~/airootfs.sfs ];
then
echo "Downloading rootfs image"
cd ~
# curl -OL http://mirror.rackspace.com/archlinux/iso/2016.10.01/arch/x86_64/airootfs.sfs
curl -OL http://mirror.rackspace.com/archlinux/iso/2017.05.01/arch/x86_64/airootfs.sfs
fi
###############################################################################
# Pull latest image
# Not really needed for one time use but while working on the script it is nice.
###############################################################################
docker pull yantis/instant-archlinux-on-mac
###############################################################################
# Install rEFInd
###############################################################################
# Check if rEFInd already installed
if [ ! -d /Volumes/ESP ]; then
echo "Mounting EFI volume"
sudo mkdir -p /Volumes/ESP
sudo mount -t msdos /dev/${ROOTDISK}s1 /Volumes/ESP
fi
# # Remove rEFInd
# if [ -d /Volumes/ESP/EFI/refind ]; then
# echo "rEFInd installed uninstalling it."
# # Delete rEFInd
# sudo rm -rf /Volumes/ESP/EFI/refind
# fi
if [ -d /Volumes/ESP/EFI/refind ]; then
echo "rEFInd already installed so not reinstalling."
unmount /Volumes/ESP
else
if [ $INSTALL_TYPE != "usb" ]; then
unmount /Volumes/ESP
fi
# Install rEFInd
curl -OL http://downloads.sourceforge.net/project/refind/0.10.4/refind-bin-0.10.4.zip
unzip -o refind-bin-0.10.4.zip
if [ $INSTALL_TYPE == "usb" ]; then
# (cd refind-bin-0.8.7 && sudo sh install.sh --alldrivers --usedefault /dev/${ROOTDISK}s1 )
echo "Installing rEFInd to USB"
mkdir -p /Volumes/ESP/EFI
cp -R refind-bin-0.10.4/refind /Volumes/ESP/EFI
cp refind-bin-0.10.4/refind/refind.conf-sample /Volumes/ESP/EFI/refind/refind.conf
else
sh refind-bin-0.10.4/refind-install --alldrivers --yes
fi
rm -r refind-bin-0.10.4
rm refind-bin-0.10.4.zip
# Sometimes rEFInd fails to unmount /Volumes/ESP so lets use that if its already open
if [ ! -d /Volumes/ESP ];
then
sudo mkdir -p /Volumes/ESP
sudo mount -t msdos /dev/${ROOTDISK}s1 /Volumes/ESP
fi
# Install the reFInd minimal theme if the user doesn't already have it installed
# I moved this out of the docker container so it isn't as clean (ie: re-remounting etc)
echo "Checking if rEFInd minimal theme is installed"
if [ ! -d /Volumes/ESP/EFI/refind/rEFInd-minimal ];
then
cd /Volumes/ESP/EFI/refind
# You can pick different forks of this to your taste.
git clone https://github.com/dylansm/rEFInd-minimal
# Default is 128x128 Lets make it is 256x256 (still tiny on retina displays)
sed -i.bak "s/#big_icon_size 256/big_icon_size 256/" refind.conf
rm refind.conf.bak
echo "include rEFInd-minimal/theme.conf" >> refind.conf
# Leave or we can't unmount
cd ~
fi
sudo diskutil unmount /Volumes/ESP
fi
###############################################################################
# Even if we failed clean up what we can
# so no more exits on errors from this point on.
###############################################################################
set +e
###############################################################################
# Run the container but make the script user definable as who knows what changes
# a user might want to make to the install script.
###############################################################################
SUCCESSFUL_INSTALL=0
docker run \
--privileged \
-v ~/systeminfo.txt:/systeminfo \
-v ~/airootfs.sfs:/root/airootfs.sfs \
-u root \
--rm \
-ti \
yantis/instant-archlinux-on-mac \
bash -c "run-remote-script https://raw.githubusercontent.com/yantis/instant-archlinux-on-mac/master/mac-install-internal.sh"
# Flag that we did or did not have a successful install
SUCCESSFUL_INSTALL=$?
###############################################################################
# Shut down the boo2docker virtual machine
###############################################################################
timeout=$(($(date +%s) + 60))
# until docker-image stop 2>/dev/null || [[ $(date +%s) -gt $timeout ]]; do
until docker-machine stop docker-vm 2>/dev/null || [[ $(date +%s) -gt $timeout ]]; do
:
done
###############################################################################
# Remove our physical harddrive from the boot2docker virtualmachine
###############################################################################
echo "Remove our physical harddrive from the boot2docker virtualmachine"
vboxmanage storageattach docker-vm --storagectl "SATA" --port 2 --device 0 --type hdd --medium none
###############################################################################
# Remove our docker image
###############################################################################
# docker rmi yantis/instant-archlinux-on-mac
###############################################################################
# Restore security
###############################################################################
sudo chmod 660 /dev/${ROOTDISK}s1
sudo sed -i.bak "s/Defaults timestamp_timeout=-1/#Defaults timestamp_timeout=-1/" /etc/sudoers
###############################################################################
# All Done
###############################################################################
echo "*******************************************************"
if [ $SUCCESSFUL_INSTALL -ne 0 ]; then
echo "ERROR: The install was not successful please try again."
echo "*******************************************************"
else
echo "DONE - REBOOT NOW TO USE ARCH LINUX."
echo "*******************************************************"
read -p "Press [Enter] key to REBOOT or CTRL C to keep using Mac OSX"
sudo reboot
fi
# vim:set ts=2 sw=2 et: