File size: 1,138 Bytes
b206c4d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/with-contenv bash

mkdir -p /config/{workspace,.ssh}

if [ -n "${SUDO_PASSWORD}" ] || [ -n "${SUDO_PASSWORD_HASH}" ]; then
    echo "setting up sudo access"
    if ! grep -q 'abc' /etc/sudoers; then
        echo "adding abc to sudoers"
        echo "abc ALL=(ALL:ALL) ALL" >> /etc/sudoers
    fi
    if [ -n "${SUDO_PASSWORD_HASH}" ]; then
        echo "setting sudo password using sudo password hash"
        sed -i "s|^abc:\!:|abc:${SUDO_PASSWORD_HASH}:|" /etc/shadow
    else
        echo "setting sudo password using SUDO_PASSWORD env var"
        echo -e "${SUDO_PASSWORD}\n${SUDO_PASSWORD}" | passwd abc
    fi
fi

[[ ! -f /config/.bashrc ]] && \
    cp /root/.bashrc /config/.bashrc
[[ ! -f /config/.profile ]] && \
    cp /root/.profile /config/.profile

# fix permissions (ignore contents of /config/workspace)
echo "setting permissions::config"
find /config -path /config/workspace -prune -o -exec chown abc:abc {} +
chown abc:abc /config/workspace
echo "setting permissions::app"
chown -R abc:abc /app/openvscode-server

chmod 700 /config/.ssh
if [ -n "$(ls -A /config/.ssh)" ]; then
    chmod 600 /config/.ssh/*
fi