#!/usr/bin/with-contenv bash

if ! dpkg -s zsh >/dev/null 2>&1; then
    echo "**** Adding zsh to package install list ****"
    echo "zsh" >> /mod-repo-packages-to-install.list
else
    echo "**** zsh already installed, skipping ****"
fi

# Install oh-my-zsh if not installed already
if [ -d /config/.oh-my-zsh ]; then
    echo "**** Oh My Zsh is already installed. You can update it via \"omz update\" in terminal. ****"
elif [ -d /.oh-my-zsh ]; then
    echo "**** Installing Oh My Zsh. You can update it via \"omz update\" in terminal. ****"
    mv /.oh-my-zsh /config/.oh-my-zsh
    cp /config/.oh-my-zsh/templates/zshrc.zsh-template /config/.zshrc
else
    echo "**** It looks like Oh My Zsh was manually deleted after install. Please recreate the code-server container to reinstall Oh My Zsh. ****"
fi

lsiown -R abc:abc \
    /config/.oh-my-zsh \
    /config/.zshrc
