-
Notifications
You must be signed in to change notification settings - Fork 3
/
cloud-init-user-data
73 lines (69 loc) · 2.56 KB
/
cloud-init-user-data
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
#cloud-config
# users
users:
- name: ${user}
sudo: ALL=(ALL) NOPASSWD:ALL
shell: /bin/zsh
groups: docker
# packages
package_update: true
package_upgrade: true
packages:
- curl
- jq
- git
- sudo
- unzip
- zip
- zsh
runcmd:
# copy authorized SSH keys for the created user
- 'mkdir -p /home/${user}/.ssh'
- 'cp /root/.ssh/authorized_keys /home/${user}/.ssh/authorized_keys'
- 'chown ${user}:root /home/${user}/.ssh/authorized_keys'
%{if feature_omz ~}
# install Oh My ZSH for root
- 'git clone --depth=1 https://github.com/robbyrussell/oh-my-zsh.git /root/.oh-my-zsh'
- 'cp /root/.oh-my-zsh/templates/zshrc.zsh-template /root/.zshrc'
- 'sed -i "s/ZSH_THEME=\".*\"/ZSH_THEME=\"ys\"/" /root/.zshrc'
- 'chsh -s /usr/bin/zsh'
# install Oh My ZSH for user
- 'runuser -l ${user} -c "git clone --depth=1 https://github.com/robbyrussell/oh-my-zsh.git /home/${user}/.oh-my-zsh"'
- 'runuser -l ${user} -c "cp /home/${user}/.oh-my-zsh/templates/zshrc.zsh-template /home/${user}/.zshrc"'
- 'sed -i "s/ZSH_THEME=\".*\"/ZSH_THEME=\"ys\"/" /home/${user}/.zshrc'
%{endif~}
%{if feature_docker ~}
# install Docker
- 'apt-get update'
- 'apt-get install -y apt-transport-https ca-certificates curl gnupg lsb-release'
- 'curl -fsSL https://download.docker.com/linux/${distrib}/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg'
- 'echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/${distrib} $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null'
- 'apt-get update'
- 'apt-get install -y docker-ce docker-ce-cli containerd.io'
%{endif~}
%{if feature_nvm ~}
# install NVM
- 'runuser -l ${user} -c "curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/$(curl -s https://api.github.com/repos/nvm-sh/nvm/releases/latest | jq -r .tag_name)/install.sh | bash"'
- 'runuser -l ${user} -c "touch /home/${user}/.zshrc"'
- |
cat << 'EOF' >> /home/${user}/.zshrc
export NVM_DIR="$([ -z "$${XDG_CONFIG_HOME-}" ] && printf %s "$${HOME}/.nvm" || printf %s "$${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
EOF
%{endif~}
%{if feature_sdkman ~}
# install SDKMAN!
- 'runuser -l ${user} -c "curl -s "https://get.sdkman.io" | bash"'
- 'runuser -l ${user} -c "touch /home/${user}/.zshrc"'
- |
cat << 'EOF' >> /home/${user}/.zshrc
source "$HOME/.sdkman/bin/sdkman-init.sh"
EOF
%{endif~}
#
power_state:
delay: "+1"
timeout: 0
mode: reboot
message: Reboot after system upgrade
condition: True