|
| 1 | +#!/bin/bash |
1 | 2 | set -e
|
2 | 3 |
|
3 |
| -cd /tmp |
| 4 | +# Detect the operating system |
| 5 | +if [ -f /etc/os-release ]; then |
| 6 | + . /etc/os-release |
| 7 | + OS=$NAME |
| 8 | +elif [ -f /etc/lsb-release ]; then |
| 9 | + . /etc/lsb-release |
| 10 | + OS=$DISTRIB_ID |
| 11 | +else |
| 12 | + OS=$(uname -s) |
| 13 | +fi |
| 14 | + |
| 15 | +# Set the appropriate user based on the detected OS |
| 16 | +if [[ "$OS" == "Ubuntu" ]]; then |
| 17 | + USER="ubuntu" |
| 18 | + COMMENT="Setting password for Ubuntu default user" |
| 19 | +elif [[ "$OS" == "Amazon Linux" ]]; then |
| 20 | + USER="ec2-user" |
| 21 | + COMMENT="Setting password for Amazon Linux default user" |
| 22 | +else |
| 23 | + echo "Unsupported operating system: $OS" |
| 24 | + exit 1 |
| 25 | +fi |
4 | 26 |
|
5 |
| -echo "Installing Terraform ..." |
6 |
| -sudo yum install -y yum-utils |
7 |
| -sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo |
8 |
| -sudo yum -y install terraform |
| 27 | +# Check if Homebrew is already installed |
| 28 | +if ! command -v brew &> /dev/null; then |
| 29 | + echo "Homebrew not found. Installing Homebrew..." |
9 | 30 |
|
10 |
| -echo "Installing Argo CD cli" |
11 |
| -curl -sSL -o argocd-linux-amd64 https://github.com/argoproj/argo-cd/releases/latest/download/argocd-linux-amd64 |
12 |
| -chmod +x argocd-linux-amd64 |
13 |
| -sudo mv argocd-linux-amd64 /usr/local/bin/argocd |
| 31 | + # Install Homebrew with better error handling |
| 32 | + export NONINTERACTIVE=1 |
| 33 | + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" || { |
| 34 | + echo "First Homebrew install attempt failed, trying with CI=1..." |
| 35 | + CI=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" |
| 36 | + } |
| 37 | + |
| 38 | + (echo; echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"') >> ~/.bashrc |
| 39 | + eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" |
14 | 40 |
|
15 |
| -echo "Installing kubectx" |
16 |
| -if [ ! -d /opt/kubectx ]; then |
17 |
| - sudo git clone https://github.com/ahmetb/kubectx /opt/kubectx |
| 41 | + echo "Homebrew installation completed." |
| 42 | +else |
| 43 | + echo "Homebrew is already installed." |
18 | 44 | fi
|
19 |
| -sudo ln -sf /opt/kubectx/kubectx /usr/local/bin/kubectx |
20 |
| -sudo ln -sf /opt/kubectx/kubens /usr/local/bin/kubens |
21 |
| - |
22 |
| -echo "Installing zsh and development tools" |
23 |
| -export HOMEBREW_CURL_RETRIES=5 |
24 |
| -rm -rf /home/ec2-user/.oh-my-zsh |
25 |
| -mkdir -p ~/tmp |
26 |
| -cd ~/tmp |
27 |
| -curl -sSL https://raw.githubusercontent.com/aws-samples/fleet-management-on-amazon-eks-workshop/refs/heads/mainline/hack/.zshrc -o .zshrc |
28 |
| -curl -sSL https://raw.githubusercontent.com/aws-samples/fleet-management-on-amazon-eks-workshop/refs/heads/mainline/hack/.p10k.zsh -o .p10k.zsh |
29 |
| - |
30 |
| -# Use the local fixed installbox script |
31 |
| -bash ~/java-on-aws/infrastructure/scripts/setup/installbox.sh |
| 45 | + |
| 46 | +if [[ "$OS" == "Ubuntu" ]]; then |
| 47 | + sudo apt update && sudo apt install -y sqlite telnet jq strace tree python3 python3-pip gettext bash-completion zsh golang-go plocate |
| 48 | +else |
| 49 | + sudo yum update && sudo yum -y install sqlite telnet jq strace tree gcc glibc-static python3 python3-pip gettext bash-completion npm zsh util-linux-user golang-go |
| 50 | + sudo dnf install findutils |
| 51 | +fi |
| 52 | + |
| 53 | +#install utils |
| 54 | +echo "Installing brew utilities..." |
| 55 | +brew install ag || echo "Warning: Failed to install ag" |
| 56 | +brew install findutils || echo "Warning: Failed to install findutils" |
| 57 | +brew install fzf || echo "Warning: Failed to install fzf" |
| 58 | + |
| 59 | +#source <(fzf --zsh) |
| 60 | + |
| 61 | +# Install eksdemo with retry logic to handle broken pipe errors |
| 62 | +echo "Installing aws/tap/eksdemo..." |
| 63 | +for i in {1..3}; do |
| 64 | + if brew install aws/tap/eksdemo; then |
| 65 | + echo "Successfully installed eksdemo" |
| 66 | + break |
| 67 | + else |
| 68 | + echo "Attempt $i failed, retrying in 5 seconds..." |
| 69 | + sleep 5 |
| 70 | + if [ $i -eq 3 ]; then |
| 71 | + echo "Failed to install eksdemo after 3 attempts" |
| 72 | + exit 1 |
| 73 | + fi |
| 74 | + fi |
| 75 | +done |
| 76 | + |
| 77 | +aws configure set cli_pager "" |
| 78 | + |
| 79 | +# start of cloud9-init script |
| 80 | +kubectl completion bash >> ~/.bash_completion |
| 81 | +#argocd completion bash >> ~/.bash_completion |
| 82 | +#helm completion bash >> ~/.bash_completion |
| 83 | +echo "alias k=kubectl" >> ~/.bashrc |
| 84 | +echo "alias ll='ls -la'" >> ~/.bashrc |
| 85 | +echo "alias code=/usr/lib/code-server/bin/code-server" >> ~/.bashrc |
| 86 | +echo "complete -F __start_kubectl k" >> ~/.bashrc |
| 87 | +curl -sS https://webinstall.dev/k9s | bash |
| 88 | + |
| 89 | +#Install some VsCode plugins |
| 90 | +alias code=/usr/lib/code-server/bin/code-server |
| 91 | +/usr/lib/code-server/bin/code-server --install-extension hashicorp.terraform |
| 92 | +/usr/lib/code-server/bin/code-server --install-extension moshfeu.compare-folders |
| 93 | + |
| 94 | + |
| 95 | + |
| 96 | +#git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf |
| 97 | +#~/.fzf/install --all |
| 98 | + |
| 99 | +curl -sfL https://direnv.net/install.sh | bash |
| 100 | +eval "$(direnv hook bash)" |
| 101 | + |
| 102 | +#Install oh-my-zsh zsh |
| 103 | +sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" || true |
| 104 | + |
| 105 | +echo "continue" |
| 106 | + |
| 107 | +#chsh -s $(which zsh) |
| 108 | + |
| 109 | +# Customize ZSH |
| 110 | +git clone https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/themes/powerlevel10k |
| 111 | +export ZSH_THEME="powerlevel10k/powerlevel10k" |
| 112 | +#p10k configure |
| 113 | + |
| 114 | +git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting |
| 115 | +git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions |
| 116 | +git clone https://github.com/zsh-users/zsh-history-substring-search ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-history-substring-search |
| 117 | + |
| 118 | +cp .zshrc .p10k.zsh ~/ |
| 119 | + |
| 120 | +#Install krew |
| 121 | +( |
| 122 | + set -x; cd "$(mktemp -d)" && |
| 123 | + OS="$(uname | tr '[:upper:]' '[:lower:]')" && |
| 124 | + ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')" && |
| 125 | + KREW="krew-${OS}_${ARCH}" && |
| 126 | + curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREW}.tar.gz" && |
| 127 | + tar zxvf "${KREW}.tar.gz" && |
| 128 | + ./"${KREW}" install krew |
| 129 | +) |
| 130 | +export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH" |
| 131 | + |
| 132 | +kubectl krew install stern |
| 133 | + |
| 134 | + |
0 commit comments