|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# trunk-ignore-all(shellcheck/SC2312) |
| 4 | +set -e |
| 5 | + |
| 6 | +CONFIG=${CONFIG:-'https://raw.githubusercontent.com/ebizbase/dev-infras/refs/heads/main/devcontainer-features/powerlevel10k/p10k.zsh'} |
| 7 | +VERSION=${VERSION:-'latest'} |
| 8 | +DELETE_PREINSTALL_THEMES=${DELETEPREINSTALLEDTHEMES:-false} |
| 9 | +DEBUG=${DEBUG:-false} |
| 10 | + |
| 11 | +debug() { |
| 12 | + if [[ ${DEBUG} == true ]]; then |
| 13 | + echo "$1" >>/tmp/powerlevel10k.log |
| 14 | + fi |
| 15 | +} |
| 16 | + |
| 17 | +if [[ -n ${_REMOTE_USER_HOME} ]]; then |
| 18 | + USER_HOME="${_REMOTE_USER_HOME}" |
| 19 | +elif [[ ${_REMOTE_USER} == "root" ]]; then |
| 20 | + USER_HOME="/root" |
| 21 | +# Check if user already has a home directory other than /home/${USERNAME} |
| 22 | +elif [[ "/home/${_REMOTE_USER}" != $(getent passwd "${_REMOTE_USER}" | cut -d: -f6) ]]; then |
| 23 | + USER_HOME=$(getent passwd "${_REMOTE_USER}" | cut -d: -f6) |
| 24 | +else |
| 25 | + USER_HOME="/home/${_REMOTE_USER}" |
| 26 | +fi |
| 27 | + |
| 28 | +if [[ ${VERSION} == "latest" ]]; then |
| 29 | + VERSION=$(curl --silent "https://api.github.com/repos/romkatv/powerlevel10k/releases/latest" | grep '"tag_name":' | sed -E 's/.*"v([^"]+)".*/\1/') |
| 30 | +fi |
| 31 | + |
| 32 | +debug "===============================" |
| 33 | +debug "VERSION: ${VERSION}" |
| 34 | +debug "CONFIG: ${CONFIG}" |
| 35 | +debug "REMOTE_USER: ${_REMOTE_USER}" |
| 36 | +debug "USER_HOME: ${USER_HOME}" |
| 37 | +debug "===============================" |
| 38 | + |
| 39 | +if [[ ${DELETE_PREINSTALL_THEMES} == true ]]; then |
| 40 | + debug "Deleting other themes" |
| 41 | + rm -rf "${USER_HOME}"/.oh-my-zsh/themes/* |
| 42 | +fi |
| 43 | + |
| 44 | +curl -L https://github.com/romkatv/powerlevel10k/archive/refs/tags/v"${VERSION}".zip -o /tmp/powerlevel10k.zip |
| 45 | +unzip /tmp/powerlevel10k.zip -d /tmp |
| 46 | +cp -r /tmp/powerlevel10k-"${VERSION}" "${USER_HOME}"/.oh-my-zsh/custom/themes/powerlevel10k |
| 47 | +rm -rf /tmp/powerlevel10k.zip /tmp/powerlevel10k-"${VERSION}" |
| 48 | +sed -i 's/ZSH_THEME=".*"/ZSH_THEME="powerlevel10k\/powerlevel10k"/g' "${USER_HOME}/.zshrc" |
| 49 | +echo 'source ~/.oh-my-zsh/custom/themes/powerlevel10k/powerlevel10k.zsh-theme' >>"${USER_HOME}/.zshrc" |
| 50 | +echo '[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh' >>"${USER_HOME}/.zshrc" |
| 51 | + |
| 52 | +curl -L "${CONFIG}" -o "${USER_HOME}/.p10k.zsh" |
0 commit comments