88 lines
4.7 KiB
Bash
Executable File
88 lines
4.7 KiB
Bash
Executable File
#!/bin/bash
|
|
cntName=osx-builder
|
|
docker create --name $cntName --network host --entrypoint tail --privileged -v /dev/kvm:/dev/kvm git.ivasoft.cz/sw/osx:base -f /dev/null
|
|
docker start $cntName
|
|
cat <<"EOF" | docker exec --interactive $cntName bash
|
|
set -eux
|
|
sudo pacman -Sy gnu-netcat sshpass --noconfirm
|
|
sed -i -r 's:^.*\-audiodev .*$:-display none \\:' /home/arch/OSX-KVM/Launch-nopicker.sh
|
|
sed -i -r 's:^(.*)\-device ide\-hd.*,drive=MacHDD.*$:\1\-device nvme,drive=MacHDD,serial=nvme-1 \\:' /home/arch/OSX-KVM/Launch-nopicker.sh
|
|
sed -i -r 's:^(.*)\-monitor .*$:\1\-monitor telnet\:\:55773,server,nowait \\:' /home/arch/OSX-KVM/Launch-nopicker.sh
|
|
# Enable VNC during the build as we will need to manually authenticate into the Mac App Store
|
|
export EXTRA="-vnc 0.0.0.0:99,password=off"
|
|
((/home/arch/OSX-KVM/Launch-nopicker.sh)&)
|
|
# Enable password-less connection to the VM
|
|
/usr/bin/ssh-keygen -t rsa -f ~/.ssh/id_docker_osx -q -N ""
|
|
chmod 600 ~/.ssh/id_docker_osx
|
|
until [[ "$(sshpass -p${PASSWORD} ssh-copy-id -o "StrictHostKeyChecking no" -f -i ~/.ssh/id_docker_osx.pub -p 10022 ${USERNAME}@127.0.0.1)" ]]; do
|
|
echo "Waiting for the VM to start up..."
|
|
sleep 15
|
|
done
|
|
tee -a ~/.ssh/config <<< 'Host 127.0.0.1'
|
|
tee -a ~/.ssh/config <<< " User ${USERNAME}"
|
|
tee -a ~/.ssh/config <<< ' Port 10022'
|
|
tee -a ~/.ssh/config <<< ' IdentityFile ~/.ssh/id_docker_osx'
|
|
tee -a ~/.ssh/config <<< ' StrictHostKeyChecking no'
|
|
# Enable password-less sudo
|
|
echo -e "${PASSWORD}\nmac ALL=(ALL) NOPASSWD: ALL"|ssh 127.0.0.1 'sudo -S tee "/etc/sudoers.d/mac"'
|
|
# Change uid
|
|
echo -e "chown -Rh 1000 /Users/mac\ndscl . -change /Users/mac UniqueID 501 1000"|ssh 127.0.0.1 sudo bash
|
|
# Instal homebrew and software
|
|
echo Installing Homebrew ...
|
|
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh|ssh 127.0.0.1 bash
|
|
# (gmp is a hack for ruby)
|
|
echo Installing packages ...
|
|
echo /usr/local/bin/brew install node@20 yarn libyaml gmp mas|ssh 127.0.0.1 bash
|
|
echo /usr/local/bin/brew link node@20|ssh 127.0.0.1 bash
|
|
# Create base directories for act and drone
|
|
echo mkdir /Users/mac/drone|ssh 127.0.0.1 bash
|
|
echo -e "drone\tUsers/mac/drone" | ssh 127.0.0.1 'sudo tee "/etc/synthetic.conf"'
|
|
# Fix problems with encoding (https://stackoverflow.com/questions/68809929/unicode-normalization-not-appropriate-for-ascii-8bit)
|
|
echo export LC_ALL=en_US.UTF-8 | ssh 127.0.0.1 'tee ~/.zshrc'
|
|
echo export LC_ALL=en_US.UTF-8 | ssh 127.0.0.1 'tee ~/.bashrc'
|
|
# Redirect all commands to VM
|
|
echo Redirecting executables
|
|
sed -i -r 's:^\#\!/bin/bash$:\#\!/usr.orig/bin/bash:' /home/arch/OSX-KVM/Launch-nopicker.sh
|
|
sudo rm /bin /sbin
|
|
# ... all executables will stop working in the container after this command
|
|
sudo mv /usr /usr.orig
|
|
EOF
|
|
|
|
chown 1000:1000 run.sh
|
|
chmod +x run.sh
|
|
docker cp run.sh ${cntName}:/home/arch/OSX-KVM/
|
|
rm -rf /tmp/links_
|
|
mkdir /tmp/links_
|
|
cd /tmp/links_
|
|
ln -s usr.orig/lib lib && docker cp lib ${cntName}:/
|
|
ln -s usr.orig/lib lib64 && docker cp lib64 ${cntName}:/
|
|
mkdir -p usr/bin && mkdir -p usr/local/bin && chmod -R 755 usr && ln -s /usr.orig/lib usr/lib && docker cp usr ${cntName}:/
|
|
mkdir bin && chmod 755 bin && docker cp bin ${cntName}:/
|
|
ln -s /home/arch/OSX-KVM/run.sh bash && docker cp bash ${cntName}:/bin/
|
|
ln -s /home/arch/OSX-KVM/run.sh uname && docker cp uname ${cntName}:/usr/bin/
|
|
ln -s /home/arch/OSX-KVM/run.sh node && docker cp node ${cntName}:/usr/local/bin/
|
|
ln -s /home/arch/OSX-KVM/run.sh brew && docker cp brew ${cntName}:/usr/local/bin/
|
|
# Fix our container entrypoint
|
|
ln -s /usr.orig/bin/tail tail && docker cp tail osx-builder:/usr/bin
|
|
# Allow sudo to work
|
|
ln -s /usr.orig/bin/unix_chkpwd unix_chkpwd && docker cp unix_chkpwd osx-builder:/usr/bin
|
|
cd /tmp
|
|
rm -rf /tmp/links_
|
|
|
|
echo Please connect using VNC to port :5999 and log into the Mac App Store manually
|
|
echo or install Xcode by manually downloading from https://developer.apple.com/download/all/?q=xcode
|
|
echo and expanding the .xip and moving the result to /Applications
|
|
read -p "Press any key to when done.. " -n1 -s
|
|
|
|
## Install apps from Mac App Store (497799835 - Xcode) ...
|
|
echo Installing apps from Mac App Store
|
|
docker exec -i $cntName /usr.orig/bin/ssh 127.0.0.1 '/usr/local/bin/mas install 497799835'
|
|
## ... or download Xcode.xip manually from https://developer.apple.com/download/all/?q=xcode, double click for expand and move it to /Applications
|
|
docker exec -i $cntName /usr.orig/bin/ssh 127.0.0.1 'sudo xcode-select -s /Applications/Xcode.app/Contents/Developer'
|
|
# May need to be run interactively
|
|
docker exec -i $cntName /usr.orig/bin/ssh 127.0.0.1 'sudo xcodebuild -license accept'
|
|
#
|
|
docker exec -i $cntName /usr.orig/bin/ssh 127.0.0.1 'sudo xcodebuild -runFirstLaunch'
|
|
docker exec -i $cntName /usr.orig/bin/ssh 127.0.0.1 'sudo xcodebuild -downloadPlatform iOS'
|
|
|
|
echo If all went smoothly then execute docker commit $cntName osx:act |