diff --git a/Dockerfile b/Dockerfile index 3061f89..93f482e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,10 +7,11 @@ COPY --from=0 --chmod=0755 /src/bubble.sh /bin/bubble RUN <> /etc/sudoers sudo -u user mkdir -p /home/user/.config/fish/ +ln -s /usr/lib/openssh/sftp-server /usr/sbin/bubble-sftp EOF COPY ./init.fish /init.fish COPY --chown=user ./user.fish /home/user/.config/fish/config.fish diff --git a/init.fish b/init.fish index 26a4d1f..8d1054d 100644 --- a/init.fish +++ b/init.fish @@ -1,3 +1,30 @@ +function init + if test -f /tmp/bubble_container_started + return + end + echo "First login detected, initializing container environment..." + if ! touch /tmp/bubble_container_started + echo "FAILED to mark status. The initialization was cancelled." + echo "Certain services (like Tailscale) won't work." + end + if test -f /usr/sbin/tailscaled + echo "Starting tailscaled" + chmod +x /usr/sbin/tailscaled + nohup /usr/sbin/tailscaled \ + --tun=userspace-networking \ + --socks5-server=localhost:1080 > /dev/null 2>&1 & + echo "Started!" + end + echo "Looking for services from /etc/init.d/" + for script in /etc/init.d/* + if test -x script + nohup $script start > /dev/null 2>&1 & + end + end +end + +init + if ! cat /etc/passwd | grep -E "^user" echo "User was not created correctly. Creating user..." useradd -m -s /usr/bin/fish user @@ -17,12 +44,13 @@ function resume return end if sudo -u user tmux has-session -t 0 - if sudo -u user tmux ls | grep -E "^0.*attached)" - echo "The default tmux session has been attached, dropping you to a normal shell." - cd /home/user && sudo -u user /usr/bin/fish - else - sudo -u user tmux attach -t 0 - end + # if sudo -u user tmux ls | grep -E "^0.*attached)" + # echo "The default tmux session has been attached, dropping you to a normal shell." + # cd /home/user && sudo -u user /usr/bin/fish + # else + # sudo -u user tmux attach -t 0 + # end + sudo -u user tmux attach -t 0 else cd /home/user sudo -u user tmux new-session -c /usr/bin/fish diff --git a/user.fish b/user.fish index 5f52f68..8c5d61b 100644 --- a/user.fish +++ b/user.fish @@ -1,9 +1,7 @@ -if test -e $BUBBLE_SOCK - echo "Manager capability is detected. Type 'bubble' for help." -end +echo "Type 'bubble' for help." -if test ! -e /usr/bin/docker - echo "Docker is not installed. Type 'install-docker' to install if needed." +if test ! -e /usr/sbin/tailscaled + echo "Tailscale is not installed. Type 'install-tailscale' to install if needed." end function exit @@ -18,31 +16,16 @@ function logout exit end -function install-docker - if test -e /usr/bin/docker - echo "Docker is already present at /bin/docker." - return - end - echo "Installing docker in 3s." - sleep 3s - echo "[DOCKER] Updating software registry." - sudo apt-get update - sudo apt-get install ca-certificates - echo "[DOCKER] Updating package manager keyrings" - sudo install -m 0755 -d /etc/apt/keyrings - echo "[DOCKER] Adding trust for docker repository" - sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc - sudo chmod a+r /etc/apt/keyrings/docker.asc - echo "[DOCKER] Adding docker repository" - bash -c 'echo \ - "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \ - $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ - sudo tee /etc/apt/sources.list.d/docker.list > /dev/null' - sudo apt-get update - echo "[DOCKER] Installing docker" - if sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin - echo "[DOCKER] Docker should be installed successfully" - else - echo "Unexpected error." - end +function install-tailscale + if test -f /usr/sbin/tailscaled + echo "Tailscale is already installed at /usr/sbin/tailscaled" + return + end + if curl -fsSL https://tailscale.com/install.sh | sh + echo "[TAILSCALE] Tailscale should be installed successfully. Starting tailscaled..." + sudo nohup /usr/sbin/tailscaled --tun=userspace-networking --socks5-server=localhost:1080 > /dev/null 2>&1 & + echo "Tailscaled is running in background. try running 'tailscale status'" + else + echo "Failed to install tailscale." + end end