-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1.setup.sh
executable file
·151 lines (131 loc) · 4.63 KB
/
1.setup.sh
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
#!/bin/bash
#######################
## Assumptions
##
## Running Ubuntu 22.04 LTS (or later?)
# Default Variable Values and Reporting
if [ -z ${SRC_ORG+x} ]; then
SRC_ORG=loveworks
fi
if [ -z ${SRC_DIR+x} ]; then
SRC_DIR=/src/$SRC_ORG
fi
if [ -z ${PROMPT+x} ]; then
PROMPT='%(?.%F{green}√.%F{red}%?)%f %B%F{240}%1~%f%b | '
fi
if [ -z ${RPROMPT+x} ]; then
RPROMPT='%*'
fi
set -euo pipefail
echo Running with...
echo \$NAME=$NAME
echo \$EMAIL=$EMAIL
echo \$SRC_DIR=$SRC_DIR
echo \$SRC_ORG=$SRC_ORG
echo \$PROMPT=$PROMPT
echo \$RPROMPT=$RPROMPT
echo \$SSO_START_URL=$SSO_START_URL
#####################
## Utility Functions
function idem() { # $1 must be side effect free && $2 must be a command (perhaps complex)
($1 &> /dev/null) || ($2)
}
function idem_cmd() { idem "command -v $1" "init_$(echo $1 | sed 's/-/_/g')"; }
function init_dir() {
sudo -s mkdir -p $1;
sudo -s chown \$SUDO_UID:\$SUDO_GID $1;
}
function idem_dir() { idem "ls $1" "init_dir $(echo $1 | sed 's/-/_/g')"; }
function idem_git() { idem "ls $1" "git clone [email protected]:$SRC_ORG/$1.git"; }
#########################################
## Install and configure important tools
sudo apt update
function init_zsh() {
sudo apt install zsh
chsh -s $(which zsh)
cp ./default.zshrc ~/.zshrc
printf '%s\n' "" "export NAME='$NAME'" "export EMAIL=$EMAIL" >> ~/.zshrc
printf '%s\n' "" "PROMPT='$PROMPT'" "RPROMPT=$RPROMPT" >> ~/.zshrc
}
idem_cmd zsh
function init_git() {
sudo apt-get install git-all
git config --global user.name "$NAME"
git config --global user.email "$EMAIL"
}
idem_cmd git
idem "command -v curl" "sudo apt install curl"
function init_aws () {
# install CLI
mkdir ~/awstmp
pushd ~/awstmp
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip ./awscliv2.zip
sudo ./aws/install
popd
rm -rf ~/awstmp
# defaults for CLI auth
mkdir ~/.aws
echo "[profile default]" >> ~/.aws/config
echo "sso_start_url = $SSO_START_URL" >> ~/.aws/config
echo "sso_region = us-west-2" >> ~/.aws/config
# trigger initial log in
echo "This script will start the SSO flow for AWS, opening a browser."
echo "Please..."
echo "1. accept defaults as given (except for step 4, after you're back to the terminal)"
echo "2. select the 'sand' account"
echo "3. choose your default role for the 'sand' account"
echo "4. set the CLI profile name to 'sand' so that documentation and scripts can use it"
aws configure sso
SAND_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text --profile sand)
aws configure set role_arn arn:aws:iam::$SAND_ACCOUNT_ID:role/cicd --profile sand-cicd
aws configure set source_profile sand --profile sand-cicd
}
idem_cmd aws
function init_nvm() {
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
nvm install --lts
nvm use --lts
nvm alias default node
npm config set script-shell $(which zsh)
}
idem_cmd nvm
idem "command -v pnpm" "npm install -g pnpm"
idem "command -v tsx" "npm install -g tsx"
function init_sdk() { # in fact, the JDK (sdk is a version manager for Java, much like nvm)
curl -s "https://get.sdkman.io" | bash
set +euo pipefail # disable for next script
source ~/.sdkman/bin/sdkman-init.sh
set -euo pipefail # reenable
sdk install java 21.0.1-tem # keep this in sync with cicd.yml
}
idem_cmd sdk
idem "command -v code" "sudo snap install --classic code"
idem "command -v convert" "sudo apt install imagemagick"
idem "command -v chromium" "sudo apt-get install chromium-browser"
function init_google_chrome() {
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo apt install ./google-chrome-stable_current_amd64.deb
rm ./google-chrome-stable_current_amd64.deb
}
idem_cmd google-chrome
################
## Get Source
echo "You are about to be challenged for GitHub's fingerprint. Please copy the Ed25519 key from the following page"
echo https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/githubs-ssh-key-fingerprints
idem_dir $SRC_DIR
idem_dir $SRC_DIR/.vscode
idem "ls $SRC_DIR/.vscode/launch.json" "cp ./launch.json $SRC_DIR/.vscode/"
idem "ls $SRC_DIR/.vscode/settings.json" "cp ./settings.json $SRC_DIR/.vscode/"
pushd $SRC_DIR
idem_git _
idem_git loveworks
idem_git onboarding
popd
# echo Wiki ... & # TODO - Knowledge Management
# echo Backlog ... & # TODO - Project Management
echo GitHub https://github.com/$SRC_ORG & # GitHub Org
xdg-open $SSO_START_URL # AWS Console