Skip to content

Commit

Permalink
fix(install): remove sudo requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
Dartypier committed Jun 13, 2024
1 parent 821e45e commit 10af9c6
Showing 1 changed file with 14 additions and 37 deletions.
51 changes: 14 additions & 37 deletions website/static/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ help() {
echo "Install script for Oh My Posh"
echo
echo "Syntax: install.sh [-h|d|t]"
echo "\noptions:"
echo "options:"
echo "-h Print this help."
echo "-d Specify the installation directory. Defaults to /usr/local/bin or the directory where oh-my-posh is installed."
echo "-t Specify the themes installation directory. Defaults to the oh-my-posh cache directory."
Expand Down Expand Up @@ -80,17 +80,14 @@ set_install_directory() {
}

validate_install_directory() {
#check if installation dir exists
if [ ! -d "$install_dir" ]; then
error "Directory ${install_dir} does not exist, set a different directory and try again."
fi

# Check if sudo has write permission
if ! sudo test -w "$install_dir"; then
error "Cannot write to ${install_dir}. Please set a different directory and try again: \n curl -s https://ohmyposh.dev/install.sh | bash -s -- -d {directory}"

# Check if regular user has write permission
elif [ ! -w "$install_dir" ]; then
error "Cannot write to ${install_dir}. Please set a different directory and try again: \n curl -s https://ohmyposh.dev/install.sh | bash -s -- -d {directory} OR use sudo"
if [ ! -w "$install_dir" ]; then
error "Cannot write to ${install_dir}. Please check write permissions or set a different directory and try again: \ncurl -s https://ohmyposh.dev/install.sh | bash -s -- -d {directory}"
fi

# check if the directory is in the PATH
Expand All @@ -110,32 +107,15 @@ validate_install_directory() {
}

validate_themes_directory() {
if [ ! -d "$install_dir" ]; then
error "Directory ${install_dir} does not exist, set a different directory and try again."

# Validate if the themes directory exists
if ! mkdir -p "$themes_dir" > /dev/null 2>&1; then
error "Cannot write to ${themes_dir}. Please check write permissions or set a different directory and try again: \ncurl -s https://ohmyposh.dev/install.sh | bash -s -- -t {directory}"
fi

# Check if sudo has write permission
if ! sudo test -w "$install_dir"; then
error "Cannot write to ${install_dir}. Please set a different directory and try again: \n curl -s https://ohmyposh.dev/install.sh | bash -s -- -d {directory}"

# Check if regular user has write permission
elif [ ! -w "$install_dir" ]; then
error "Cannot write to ${install_dir}. Please set a different directory and try again: \n curl -s https://ohmyposh.dev/install.sh | bash -s -- -d {directory} OR use sudo"
fi

# check if the directory is in the PATH
good=$(
IFS=:
for path in $PATH; do
if [ "${path%/}" = "${install_dir}" ]; then
printf 1
break
fi
done
)

if [ "${good}" != "1" ]; then
warn "Installation directory ${install_dir} is not in your \$PATH"
#check user write permission
if [ ! -w "$themes_dir" ]; then
error "Cannot write to ${themes_dir}. Please check write permissions or set a different directory and try again: \ncurl -s https://ohmyposh.dev/install.sh | bash -s -- -t {directory}"
fi
}

Expand All @@ -152,10 +132,7 @@ install_themes() {
themes_dir="${cache_dir}/themes"
fi

# Validate if the themes directory exists
if [ ! -d "$themes_dir" ]; then
mkdir -p $themes_dir
fi
validate_themes_directory

info "🎨 Installing oh-my-posh themes in ${themes_dir}\n"

Expand Down Expand Up @@ -214,8 +191,8 @@ install() {
info "🚀 Installation complete.\n\nYou can follow the instructions at https://ohmyposh.dev/docs/installation/prompt"
info "to setup your shell to use oh-my-posh."
if [ $http_response = "200" ]; then
info "\nIf you want to use a built-in theme, you can find them in the ${theme_dir} directory:"
info " oh-my-posh init {shell} --config ${theme_dir}/{theme}.omp.json\n"
info "\nIf you want to use a built-in theme, you can find them in the ${themes_dir} directory:"
info " oh-my-posh init {shell} --config ${themes_dir}/{theme}.omp.json\n"
fi
}

Expand Down

0 comments on commit 10af9c6

Please sign in to comment.