diff --git a/post-install.sh b/post-install.sh index 1b92708..7cb5149 100755 --- a/post-install.sh +++ b/post-install.sh @@ -85,47 +85,66 @@ echo "[+] Configuring passwordless sudo for ${ALMA_USER}..." echo "${ALMA_USER} ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/99-${ALMA_USER} chmod 440 /etc/sudoers.d/99-${ALMA_USER} -# Install oh-my-zsh and powerlevel10k -echo "[+] Installing oh-my-zsh and powerlevel10k for ${ALMA_USER} and root..." +# Setup terminal environment for both user and root +echo "[+] Setting up terminal environment for ${ALMA_USER} and root..." -# Install for user -su - ${ALMA_USER} -c 'export RUNZSH=no CHSH=no KEEP_ZSHRC=yes && bash -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"' 2>/dev/null || echo "WARNING: user oh-my-zsh installation failed" -su - ${ALMA_USER} -c 'git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ~/.oh-my-zsh/custom/themes/powerlevel10k' 2>/dev/null || echo "WARNING: user powerlevel10k installation failed" - -# Install for root -export RUNZSH=no CHSH=no KEEP_ZSHRC=yes && bash -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" 2>/dev/null || echo "WARNING: root oh-my-zsh installation failed" -git clone --depth=1 https://github.com/romkatv/powerlevel10k.git /root/.oh-my-zsh/custom/themes/powerlevel10k 2>/dev/null || echo "WARNING: root powerlevel10k installation failed" - -# Install dotfiles from git repo (cloning needed as we're in chroot) -echo "[+] Installing dotfiles for ${ALMA_USER} and root..." - -# Install for user -su - ${ALMA_USER} -c ' - cd && - git clone https://git.dominik-roth.eu/dodox/nullpoint.git /tmp/nullpoint-dotfiles && - cd /tmp/nullpoint-dotfiles/dotfiles && - for file in .*; do - if [ -f "$file" ] && [ "$file" != "." ] && [ "$file" != ".." ]; then - cp "$file" ~/ 2>/dev/null || true - fi - done && - cd && rm -rf /tmp/nullpoint-dotfiles -' || echo "WARNING: user dotfiles installation failed" - -# Install for root -cd /root && -git clone https://git.dominik-roth.eu/dodox/nullpoint.git /tmp/nullpoint-dotfiles-root && -cd /tmp/nullpoint-dotfiles-root/dotfiles && -for file in .*; do - if [ -f "$file" ] && [ "$file" != "." ] && [ "$file" != ".." ]; then - cp "$file" /root/ 2>/dev/null || true +for user_account in "${ALMA_USER}" "root"; do + echo " - Setting up $user_account..." + + if [ "$user_account" = "root" ]; then + home_dir="/root" + user_prefix="" + else + home_dir="/home/${user_account}" + user_prefix="su - ${user_account} -c" fi -done && -cd /root && rm -rf /tmp/nullpoint-dotfiles-root || echo "WARNING: root dotfiles installation failed" - -# Set zsh as default shell for root -echo "[+] Setting zsh as default shell for root..." -chsh -s /bin/zsh root + + # Install oh-my-zsh + if [ "$user_account" = "root" ]; then + export RUNZSH=no CHSH=no KEEP_ZSHRC=yes && bash -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" 2>/dev/null || echo "WARNING: $user_account oh-my-zsh installation failed" + else + su - ${user_account} -c 'export RUNZSH=no CHSH=no KEEP_ZSHRC=yes && bash -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"' 2>/dev/null || echo "WARNING: $user_account oh-my-zsh installation failed" + fi + + # Install powerlevel10k + if [ "$user_account" = "root" ]; then + git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${home_dir}/.oh-my-zsh/custom/themes/powerlevel10k 2>/dev/null || echo "WARNING: $user_account powerlevel10k installation failed" + else + su - ${user_account} -c 'git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ~/.oh-my-zsh/custom/themes/powerlevel10k' 2>/dev/null || echo "WARNING: $user_account powerlevel10k installation failed" + fi + + # Install dotfiles + if [ "$user_account" = "root" ]; then + cd ${home_dir} && + git clone https://git.dominik-roth.eu/dodox/nullpoint.git /tmp/nullpoint-dotfiles-${user_account} && + cd /tmp/nullpoint-dotfiles-${user_account}/dotfiles && + for file in .*; do + if [ -f "$file" ] && [ "$file" != "." ] && [ "$file" != ".." ]; then + cp "$file" ${home_dir}/ 2>/dev/null || true + fi + done && + cd ${home_dir} && rm -rf /tmp/nullpoint-dotfiles-${user_account} || echo "WARNING: $user_account dotfiles installation failed" + else + su - ${user_account} -c " + cd && + git clone https://git.dominik-roth.eu/dodox/nullpoint.git /tmp/nullpoint-dotfiles-${user_account} && + cd /tmp/nullpoint-dotfiles-${user_account}/dotfiles && + for file in .*; do + if [ -f \"\$file\" ] && [ \"\$file\" != \".\" ] && [ \"\$file\" != \"..\" ]; then + cp \"\$file\" ~/ 2>/dev/null || true + fi + done && + cd && rm -rf /tmp/nullpoint-dotfiles-${user_account} + " || echo "WARNING: $user_account dotfiles installation failed" + fi + + # Set zsh as default shell + if [ "$user_account" = "root" ]; then + sed -i 's|^root:.*:/bin/bash$|root:x:0:0:root:/root:/bin/zsh|' /etc/passwd + else + sed -i "s|^${user_account}:.*:/bin/bash$|${user_account}:x:$(id -u ${user_account}):$(id -g ${user_account})::/home/${user_account}:/bin/zsh|" /etc/passwd + fi +done # Set up MOTD if [ "$ENABLE_MOTD" = true ]; then