Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make install.sh detect shell type #15

Closed
MrAureliusR opened this issue Dec 1, 2021 · 2 comments
Closed

Make install.sh detect shell type #15

MrAureliusR opened this issue Dec 1, 2021 · 2 comments

Comments

@MrAureliusR
Copy link

MrAureliusR commented Dec 1, 2021

Heard about this project on Linux Unplugged, wanted to give it a try. I use zsh, and the install.sh butchered my prompt by trying to source ~/.bashrc into a zsh session. I re-wrote the script to detect if the user is running bash or zsh and change the output file accordingly, but this install.sh doesn't seem to be in the git tree anywhere so I wasn't able to make a pull request.

Also, before editing a user's bashrc/zshrc we should give them the opportunity to do it manually if they wish. I know a lot of people (myself included) have a lot of custom stuff in their shell startup and the thought of an automated script messing with it always makes me nervous. (Yes, this script just appends lines to the end, but still.)

Here's what I wrote, it could definitely be improved upon but I wanted to at least pass on the two minutes of work I did!

#!/bin/sh

SCRIPT_DIRECTORY=$(dirname "$(readlink -f "$0")")

if [ "$SHELL" = "/bin/bash" ]; then
    RCFILE=~/.bashrc
elif [ "$SHELL" = "/usr/bin/zsh" ]; then
    RCFILE=~/.zshrc
else
    RCFILE=~/.profile # if we can't detect the shell, use a sane default that all modern shells look at
fi

echo "This installation script will try and set things up automatically."
echo "In order to do so, some environment variables will be appended to $RCFILE"
echo "If you want to do this manually, hit CTRL-C now and examine this script."
echo "Otherwise, just hit enter and we'll do the work for you!"
read wait # just wait for the user to read

echo "" >> $RCFILE # in case the rcfile doesn't end with a newline, forcefully add one
echo "# mp4grep environment variables -------" >> $RCFILE
echo "export MP4GREP_CACHE='$SCRIPT_DIRECTORY/.mp4grep_cache'" >> $RCFILE
echo "export MP4GREP_MODEL='$SCRIPT_DIRECTORY/model'" >> $RCFILE

echo -n 'export PATH="$PATH:' >> $RCFILE
echo "$SCRIPT_DIRECTORY/bin\"" >> $RCFILE
echo "# --------------------------------------" >> $RCFILE

echo "Completed environment setup for mp4grep: "
echo "MP4GREP_CACHE=$SCRIPT_DIRECTORY/.mp4grep_cache"
echo "MP4GREP_MODEL=$SCRIPT_DIRECTORY/model"
echo -n 'PATH=$PATH:'
echo "$SCRIPT_DIRECTORY/bin"
echo ""
echo "Variables exported in $RCFILE"

source $RCFILE
@o-oconnell
Copy link
Owner

o-oconnell commented Dec 15, 2021

Good idea @MrAureliusR. I have pushed install.sh if you would like to make a pull request. Thank you!

@o-oconnell
Copy link
Owner

Installation doesn't use a shell script any more, so I'm closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants