Skip to content

Instantly share code, notes, and snippets.

@jackfrancis
Last active September 27, 2021 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackfrancis/474a565ab0968a64cc0ac77d26bf09e4 to your computer and use it in GitHub Desktop.
Save jackfrancis/474a565ab0968a64cc0ac77d26bf09e4 to your computer and use it in GitHub Desktop.
macOS init
#!/bin/bash
if [ -z "$GITHUB_USERNAME" ]; then
echo "Must set the GITHUB_USERNAME variable"
exit 1
fi
if [ -z "$GITHUB_REPOS" ]; then
# You may set up a bash string array of github repositories for which your GITHUB_USERNAME has a fork, e.g.:
export GITHUB_REPOS="https://github.com/kubernetes-sigs/cluster-api-provider-azure.git https://github.com/Azure/aks-engine.git \
https://github.com/weaveworks/kured.git https://github.com/kubernetes-sigs/cluster-api.git https://github.com/kubernetes/perf-tests.git \
https://github.com/kubernetes/test-infra.git https://github.com/jackfrancis/kamino.git https://github.com/kubernetes/autoscaler.git \
https://github.com/kubernetes-sigs/image-builder.git https://github.com/kubernetes/community.git https://github.com/kubernetes-sigs/cloud-provider-azure.git \
https://github.com/jackfrancis/kustodian.git https://github.com/Azure/homebrew-aks-engine.git https://github.com/deis/docker-go-dev.git \
https://github.com/helm/helm.git https://github.com/Azure/container-compute-upstream.git https://github.com/jakepearson/k.git \
https://github.com/cncf/k8s-conformance.git https://github.com/kubernetes/kubernetes.git https://github.com/kubernetes/kubectl.git \
https://github.com/vmware-tanzu/sonobuoy.git"
echo "GITHUB_REPOS environment variable was empty, no github repos will be installed in \$GOPATH"
fi
if [ -z "$GITHUB_EMAIL" ]; then
echo "Must set the GITHUB_EMAIL variable"
exit 1
fi
if [ -z "$GITHUB_FULL_NAME" ]; then
echo "Must set the GITHUB_FULL_NAME variable"
exit 1
fi
CWD=$(pwd)
chsh -s /bin/bash
scutil --get HostName | grep $(scutil --get LocalHostName) || sudo scutil --set HostName $(scutil --get LocalHostName)
xcode-select --install
which brew || /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
which go || brew install go
which gopls || brew install gopls
which az || brew install azure-cli
which pwsh || brew install --cask powershell
which helm || brew install helm
which envsubst || brew install gettext
if ! [ -f $HOME/.bash_profile ]; then
cat << EOF >> $HOME/.bash_profile
export GOPATH=$HOME/go
export GOROOT=/usr/local/opt/go/libexec
export PATH="\$PATH:$GOPATH/bin:$GOROOT/bin:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
export GITHUB_USERNAME=${GITHUB_USERNAME}
export GITHUB_EMAIL=${GITHUB_EMAIL}
export GITHUB_FULL_NAME=${GITHUB_FULL_NAME}
export TEST_AZURE_SUB_ID=${TEST_AZURE_SUB_ID}
export LARGE_AZURE_SUB_ID=${LARGE_AZURE_SUB_ID}
export TEST_AZURE_SP_ID=${TEST_AZURE_SP_ID}
export SOAK_AZURE_SP_ID=${SOAK_AZURE_SP_ID}
export LARGE_AZURE_SP_ID=${LARGE_AZURE_SP_ID}
export TEST_AZURE_SP_PW=${TEST_AZURE_SP_PW}
export SOAK_AZURE_SP_PW=${SOAK_AZURE_SP_PW}
export LARGE_AZURE_SP_PW=${LARGE_AZURE_SP_PW}
export TEST_AZURE_TENANT_ID=${TEST_AZURE_TENANT_ID}
export AZURE_SUBSCRIPTION_ID=$TEST_AZURE_SUB_ID
export AZURE_TENANT_ID=$TEST_AZURE_TENANT_ID
export AZURE_CLIENT_ID=$TEST_AZURE_SP_ID
export AZURE_CLIENT_SECRET=$TEST_AZURE_SP_PW
EOF
fi
chmod 600 $HOME/.bash_profile
source $HOME/.bash_profile
if ! [ -f $HOME/.ssh/id_ed25519 ]; then
ssh-keygen -t rsa -C "${GITHUB_EMAIL}" -f $HOME/.ssh/id_ed25519 -N ""
fi
mkdir -p $GOPATH $GOPATH/src $GOPATH/pkg $GOPATH/bin
which jq || brew install jq
which kind || brew install kind
which golangci-lint || brew install golangci-lint
which tilt || curl -fsSL https://raw.githubusercontent.com/tilt-dev/tilt/master/scripts/install.sh | bash
if ! [ -f /usr/local/bin/k ]; then
curl -OL https://raw.githubusercontent.com/jakepearson/k/master/k && chmod +x k && mv k /usr/local/bin/k
fi
[ -d "/Applications/Microsoft Edge.app" ] || open "https://www.microsoft.com/en-us/edge"
[ -d "/Applications/Docker.app" ] || open "https://docs.docker.com/docker-for-mac/install/"
[ -d "/Applications/Visual Studio Code.app" ] || open "https://code.visualstudio.com"
[ -d "/Applications/Slack.app" ] || open "https://slack.com/downloads/instructions/mac"
if [ -d "${HOME}/Library/Application Support/Code/User/" ]; then
cat << EOF > $HOME/Library/Application\ Support/Code/User/settings.json
{
"files.eol": "\n",
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"go.formatTool": "gofmt",
"go.lintTool": "golangci-lint",
"go.lintOnSave": "file",
"go.testTimeout": "10m",
"editor.maxTokenizationLineLength": 90000,
"go.useLanguageServer": true,
"go.toolsEnvVars": {
//"GOOS": "linux",
"GO111MODULE": "on",
},
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
"go.toolsManagement.autoUpdate": true,
}
EOF
fi
if [ -d $GOPATH/src/github.com/kubernetes-sigs/cluster-api-provider-azure/ ]; then
AZURE_SUBSCRIPTION_ID_B64=$(echo $AZURE_SUBSCRIPTION_ID | base64)
AZURE_TENANT_ID_B64=$(echo $AZURE_TENANT_ID | base64)
AZURE_CLIENT_SECRET_B64=$(echo $AZURE_CLIENT_SECRET | base64)
AZURE_CLIENT_ID_B64=$(echo $AZURE_CLIENT_ID | base64)
AZURE_SSH_PUBLIC_KEY_B64=$(cat ${HOME}/.ssh/id_ed25519.pub | base64)
cat << EOF > $GOPATH/src/github.com/kubernetes-sigs/cluster-api-provider-azure/tilt-settings.json
{
"kustomize_substitutions": {
"AZURE_SUBSCRIPTION_ID": "${AZURE_SUBSCRIPTION_ID}",
"AZURE_TENANT_ID": "${AZURE_TENANT_ID}",
"AZURE_CLIENT_SECRET": "${AZURE_CLIENT_SECRET}",
"AZURE_CLIENT_ID": "${AZURE_CLIENT_ID}",
"AZURE_ENVIRONMENT": "AzurePublicCloud",
"AZURE_SSH_PUBLIC_KEY_B64": "${AZURE_SSH_PUBLIC_KEY_B64}"
},
"worker-templates": {
"flavors": {
"default": {
"WORKER_MACHINE_COUNT": "1",
"KUBERNETES_VERSION": "v1.20.9",
"AZURE_LOCATION": "westus2",
"AZURE_NODE_MACHINE_TYPE": "Standard_D2s_v3",
"CONTROL_PLANE_MACHINE_COUNT": "1"
}
},
"metadata": {}
}
}
EOF
fi
go install github.com/go-delve/delve/cmd/dlv@latest
go install honnef.co/go/tools/cmd/staticcheck@latest
go install github.com/ramya-rao-a/go-outline@latest
go install github.com/uudashr/gopkgs/v2/cmd/gopkgs@latest
git config --global user.email $GITHUB_EMAIL
git config --global user.name $GITHUB_FULL_NAME
re="^(https|git)(:\/\/|@)([^\/:]+)[\/:]([^\/:]+)\/(.+).git$"
for repo in $GITHUB_REPOS; do
if [[ $repo =~ $re ]]; then
protocol=${BASH_REMATCH[1]}
separator=${BASH_REMATCH[2]}
hostname=${BASH_REMATCH[3]}
user=${BASH_REMATCH[4]}
name=${BASH_REMATCH[5]}
local_git_dir=$HOME/go/src/$hostname/$user/$name
if ! [ -d $local_git_dir ]; then
if [ "$user" = "$GITHUB_USERNAME" ]; then
clone_url=$repo
else
clone_url=$(echo $repo | sed -e "s/$user/$GITHUB_USERNAME/");
fi
git clone $clone_url $local_git_dir || exit 1
cd $local_git_dir
git remote add upstream $repo && git fetch upstream
fi
fi
done
if [ -d "/Applications/Company Portal.app" ]; then
[ -d "/Applications/Microsoft Teams.app" ] || open "https://teams.microsoft.com/downloads"
[ -d "/Applications/GlobalProtect.app" ] || open "https://microsoft.sharepoint.com/sites/Network_Connectivity/SitePages/RemoteAccess/GlobalProtect-Desktop-VPN-app-for-Mac.aspx"
[ -d "/Applications/Microsoft Outlook.app" ] || open "https://aka.ms/getoffice"
else
open "https://aka.ms/intune"
fi
cd $CWD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment