-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add install script #15
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've left some changes I'd like to be made - but I need mini to see if a file like this is viable. It's going to need some testing, especially on certain distros that have a /usr/bin directory, but don't use it - such as NixOS.
install.sh
Outdated
echo "Directory to install to (default: $defaultdir)" | ||
read installdir | ||
|
||
if [[ $installdir = "" ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This syntax can be simplified to
[ -z "$installdir" ] && installdir=$defaultdir
This can be done for other if statements true, where a condition is ran in [ ], then a logical operator is used, such as && where if the first one is true, the second one is ran. Or ||, where if the first one fails or is false, then the next one is ran. This is cleaner and neater syntax which will also make the script smaller. If you don't understand this I can make these changes so you can see what I mean.
install.sh
Outdated
echo -e "\nPridefetch installed successfully" | ||
exit | ||
else | ||
echo -e "\nSomething went wrong" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something went wrong, and pridefetch couldn't install properly.
Would sound better here
install.sh
Outdated
#!/bin/bash | ||
|
||
if [[ $(whoami) != "root" ]]; then | ||
echo "This file needs to be executed as root or with sudo." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This "script" sounds better instead of "file."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This script may not require root if the directory the user chooses is owned by them (e.g. ~/bin/
); could this check be moved down along with a permissions check to see if it is needed?
Due to NixOS we we know this script will not work on it with default options; that's ok, we have separate Nix packages and people who use Nix are aware that scripts are likely to break. If it works everywhere else that would be enough to merge it along with a note saying such. It could be helpful to include a bit of detection for where we should install (i.e. with nonstandard paths) however that isn't required. |
That's what I was thinking - we need at least something, like a message, so someone new to Nix doesn't go and run it and cause damage or leave files in there. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally pretty good; and I'd be happy to merge after the few nits highlighted are sorted out
install.sh
Outdated
#!/bin/bash | ||
|
||
if [[ $(whoami) != "root" ]]; then | ||
echo "This file needs to be executed as root or with sudo." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This script may not require root if the directory the user chooses is owned by them (e.g. ~/bin/
); could this check be moved down along with a permissions check to see if it is needed?
install.sh
Outdated
if [[ -f "$installdir/pridefetch" ]]; then | ||
echo -e "\nPridefetch installed successfully" | ||
echo -e "\n\nMake sure $installdir is in PATH\nTo add directory to path, add this to your shells rc file:" | ||
echo -e "\nexport PATH=\"$installdir:\$PATH\"" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't always needed, and almost certainly won't be needed with the default install directory of /usr/bin
; could we check if the install dir is already in path before telling the user to add it to their shell's .rc file?
install.sh
Outdated
|
||
if [[ -f "$installdir/pridefetch" ]]; then | ||
echo -e "\nPridefetch installed successfully" | ||
echo -e "\n\nMake sure $installdir is in PATH\nTo add directory to path, add this to your shells rc file:" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should probably be an apostrophe in shell's
install.sh
Outdated
zip -r ../pridefetch.zip * | ||
cd .. | ||
echo "#!/usr/bin/env python" | cat - pridefetch.zip > pridefetch | ||
cp pridefetch "$installdir/" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we check if pridefetch is already at this location & if so ask for confirmation? Blindly copying files as root seems unwise to me.
install.sh
Outdated
zip -r ../pridefetch.zip * | ||
cd .. | ||
echo "#!/usr/bin/env python" | cat - pridefetch.zip > pridefetch | ||
cp pridefetch "$installdir/" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This portion of the script leaves pridefetch and pridefetch.zip inside the root of the git repo; should we remove them or use a directory under /tmp?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think using /tmp
is better, instead of making changes in the git repo - sounds easier to manage in future, if changes have to be made, and can be done with shell scripts nicely. I've also seen ~.cache
be used as an alternative.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are some code suggestions which should fix all pending review comments; if you decide to use them please look them over and test on your machine
install.sh
Outdated
if [[ $installdir = "" ]]; then | ||
installdir=$defaultdir | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if [[ $installdir = "" ]]; then | |
installdir=$defaultdir | |
fi | |
[ -z "$installdir" ] && installdir=$defaultdir |
install.sh
Outdated
echo -e "\nPridefetch installed successfully" | ||
exit | ||
else | ||
echo -e "\nSomething went wrong" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
echo -e "\nSomething went wrong" | |
echo -e "\nSomething went wrong, and the installation of pridefetch was not completed." |
install.sh
Outdated
if [[ $(whoami) != "root" ]]; then | ||
echo "This file needs to be executed as root or with sudo." | ||
exit | ||
fi | ||
|
||
defaultdir="/usr/bin" | ||
|
||
echo "Directory to install to (default: $defaultdir)" | ||
read installdir | ||
|
||
if [[ $installdir = "" ]]; then | ||
installdir=$defaultdir | ||
fi | ||
|
||
if [[ ! -d $installdir ]]; then | ||
echo "This directory does not exist." | ||
exit | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if [[ $(whoami) != "root" ]]; then | |
echo "This file needs to be executed as root or with sudo." | |
exit | |
fi | |
defaultdir="/usr/bin" | |
echo "Directory to install to (default: $defaultdir)" | |
read installdir | |
if [[ $installdir = "" ]]; then | |
installdir=$defaultdir | |
fi | |
if [[ ! -d $installdir ]]; then | |
echo "This directory does not exist." | |
exit | |
fi | |
defaultdir="/usr/bin" | |
echo "Directory to install to (default: $defaultdir)" | |
read installdir | |
if [[ $installdir = "" ]]; then | |
installdir=$defaultdir | |
fi | |
if [[ ! -d $installdir ]]; then | |
echo "This directory does not exist." | |
exit 1 | |
fi | |
if [[ ! -r $installdir || ! -w $installdir ]]; then | |
echo "You can't read and write files in this directory; please try running with root access or change the installation directory." | |
exit 1 | |
fi | |
if [[ -e "$installdir/pridefetch" ]] ; then | |
if [[ ! -f "$installdir/pridefetch" ]]; then | |
echo "$installdir/pridefetch exists and is not a file, so cannot be overwritten. Please remove it and try again" | |
exit 1 | |
fi | |
if [[ ! -r "$installdir/pridefetch" || ! -w "$installdir/pridefetch" ]]; then | |
echo "You can't read and write over the existing pridefetch file; please try running with root access or change the installation directory." | |
exit 1 | |
fi | |
echo "The file $installdir/pridefetch already exists; do you want to overwrite it?" | |
read -p "Continue (y/n)?: " continue | |
if [ "$continue" != "y" ]; then | |
exit 1 | |
fi | |
fi |
install.sh
Outdated
zip -r ../pridefetch.zip * | ||
cd .. | ||
echo "#!/usr/bin/env python" | cat - pridefetch.zip > pridefetch | ||
cp pridefetch "$installdir/" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zip -r ../pridefetch.zip * | |
cd .. | |
echo "#!/usr/bin/env python" | cat - pridefetch.zip > pridefetch | |
cp pridefetch "$installdir/" | |
builddir=$(mktemp -d) | |
zip -r "$builddir/pridefetch.zip" * | |
cd .. | |
echo "#!/usr/bin/env python" | cat - "$builddir/pridefetch.zip" > "$builddir/pridefetch" | |
cp "$builddir/pridefetch" "$installdir/" |
No description provided.