Skip to content

Commit

Permalink
postinstall fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
v1nsai committed Dec 8, 2024
1 parent 3bf7790 commit e85889b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 27 deletions.
36 changes: 20 additions & 16 deletions apps/services/devbox/app/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@ apiVersion: v1
data:
postinstall.sh: "#!/bin/bash\n\nset -e\n\n# if the file /postinstall-has-run exists,
then the postinstall script has already run and exit gracefully\nif [ -f /postinstall-has-run
]; then\n exit 0\nfi\n\napt update\napt install -y openssh-server vim unminimize
sudo nnn git wget\necho -e \"y\\n\" | unminimize\n\n# ssh\necho \"PermitRootLogin
no\" >> /etc/ssh/sshd_config\necho \"PasswordAuthentication no\" >> /etc/ssh/sshd_config\nservice
ssh restart\n\n# user\nadduser --disabled-password --gecos \"\" $USERNAME\necho
\"$USERNAME ALL=(ALL) NOPASSWD:ALL\" >> /etc/sudoers\ncp /authorized_keys /home/$USERNAME/.ssh/authorized_keys\nchown
$USERNAME:$USERNAME /home/$USERNAME/.ssh/authorized_keys\nchmod 600 /home/$USERNAME/.ssh/authorized_keys\n\n#
docker\n# Add Docker's official GPG key:\nsudo apt-get update\nsudo apt-get install
ca-certificates curl\nsudo install -m 0755 -d /etc/apt/keyrings\nsudo curl -fsSL
https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc\nsudo
chmod a+r /etc/apt/keyrings/docker.asc\n\n# Add the repository to Apt sources:\necho
\\\n \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc]
https://download.docker.com/linux/ubuntu \\\n $(. /etc/os-release && echo \"$VERSION_CODENAME\")
stable\" | \\\n sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\nsudo
apt-get update \n\n# Node\ncurl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh
| bash\nnvm install 18\nnvm use 18\n\n# If everything runs successfully, don't
bother running next startup\ntouch /postinstall-has-run"
]; then\n echo \"Postinstall script has already run, skipping...\"\n exit
0\nfi\n\necho \"Installing packages...\"\napt update\napt install -y openssh-server
vim unminimize sudo nnn git wget\necho -e \"y\\n\" | unminimize\n\necho \"Configuring
SSH...\"\necho \"PermitRootLogin no\" >> /etc/ssh/sshd_config\necho \"PasswordAuthentication
no\" >> /etc/ssh/sshd_config\nservice ssh restart\n\necho \"Configuring user...\"\nadduser
--disabled-password --gecos \"\" $USERNAME\necho \"$USERNAME ALL=(ALL) NOPASSWD:ALL\"
>> /etc/sudoers\nmkdir -p /home/$USERNAME/.ssh\ncp /root/.ssh/authorized_keys
/home/$USERNAME/.ssh/authorized_keys\nchown $USERNAME:$USERNAME /home/$USERNAME/.ssh/authorized_keys\nchmod
600 /home/$USERNAME/.ssh/authorized_keys\n\necho \"Installing Docker...\"\n# Add
Docker's official GPG key:\nsudo apt-get update\nsudo apt-get install ca-certificates
curl\nsudo install -m 0755 -d /etc/apt/keyrings\nsudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg
-o /etc/apt/keyrings/docker.asc\nsudo chmod a+r /etc/apt/keyrings/docker.asc\n\n#
Add the repository to Apt sources:\necho \\\n \"deb [arch=$(dpkg --print-architecture)
signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu
\\\n $(. /etc/os-release && echo \"$VERSION_CODENAME\") stable\" | \\\n sudo
tee /etc/apt/sources.list.d/docker.list > /dev/null\nsudo apt-get update \nsudo
apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin
docker-compose-plugin\n\necho \"Installing Node...\"\ncurl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh
| bash\nsource ~/.bashrc\nnvm install 18\nnvm use 18\n\n# If everything runs successfully,
don't bother running next startup\ntouch /postinstall-has-run"
kind: ConfigMap
metadata:
creationTimestamp: null
Expand Down
8 changes: 2 additions & 6 deletions apps/services/devbox/app/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@ spec:
- name: devbox
image: ubuntu:24.04
# image: docker:dind
# securityContext:
# privileged: true
# lifecycle:
# postStart:
# exec:
# command: ["/bin/bash", "-c", "/postinstall.sh"]
securityContext:
privileged: true
env:
- name: USERNAME
valueFrom:
Expand Down
15 changes: 10 additions & 5 deletions apps/services/devbox/files/postinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,29 @@ set -e

# if the file /postinstall-has-run exists, then the postinstall script has already run and exit gracefully
if [ -f /postinstall-has-run ]; then
echo "Postinstall script has already run, skipping..."
exit 0
fi

echo "Installing packages..."
apt update
apt install -y openssh-server vim unminimize sudo nnn git wget
echo -e "y\n" | unminimize

# ssh
echo "Configuring SSH..."
echo "PermitRootLogin no" >> /etc/ssh/sshd_config
echo "PasswordAuthentication no" >> /etc/ssh/sshd_config
service ssh restart

# user
echo "Configuring user..."
adduser --disabled-password --gecos "" $USERNAME
echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
cp /authorized_keys /home/$USERNAME/.ssh/authorized_keys
mkdir -p /home/$USERNAME/.ssh
cp /root/.ssh/authorized_keys /home/$USERNAME/.ssh/authorized_keys
chown $USERNAME:$USERNAME /home/$USERNAME/.ssh/authorized_keys
chmod 600 /home/$USERNAME/.ssh/authorized_keys

# docker
echo "Installing Docker..."
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
Expand All @@ -37,9 +40,11 @@ echo \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# Node
echo "Installing Node..."
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
source ~/.bashrc
nvm install 18
nvm use 18

Expand Down

0 comments on commit e85889b

Please sign in to comment.