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

Add install script #15

Closed
wants to merge 0 commits into from
Closed

Add install script #15

wants to merge 0 commits into from

Conversation

R0dn3yS
Copy link
Collaborator

@R0dn3yS R0dn3yS commented May 30, 2022

No description provided.

@SpyHoodle SpyHoodle added the packaging This is to do with packaging label May 30, 2022
@SpyHoodle SpyHoodle requested a review from Minion3665 May 30, 2022 11:33
install.sh Outdated Show resolved Hide resolved
Copy link
Owner

@SpyHoodle SpyHoodle left a 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 Show resolved Hide resolved
install.sh Outdated
echo "Directory to install to (default: $defaultdir)"
read installdir

if [[ $installdir = "" ]]; then
Copy link
Owner

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"
Copy link
Owner

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."
Copy link
Owner

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."

Copy link
Collaborator

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?

@Minion3665
Copy link
Collaborator

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.

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.

@SpyHoodle
Copy link
Owner

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.

Copy link
Collaborator

@Minion3665 Minion3665 left a 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 Show resolved Hide resolved
install.sh Outdated
#!/bin/bash

if [[ $(whoami) != "root" ]]; then
echo "This file needs to be executed as root or with sudo."
Copy link
Collaborator

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\""
Copy link
Collaborator

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:"
Copy link
Collaborator

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/"
Copy link
Collaborator

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/"
Copy link
Collaborator

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?

Copy link
Owner

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.

Copy link
Collaborator

@Minion3665 Minion3665 left a 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 Show resolved Hide resolved
install.sh Outdated
Comment on lines 13 to 15
if [[ $installdir = "" ]]; then
installdir=$defaultdir
fi
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo -e "\nSomething went wrong"
echo -e "\nSomething went wrong, and the installation of pridefetch was not completed."

install.sh Outdated
Comment on lines 3 to 20
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 Show resolved Hide resolved
install.sh Outdated
Comment on lines 23 to 26
zip -r ../pridefetch.zip *
cd ..
echo "#!/usr/bin/env python" | cat - pridefetch.zip > pridefetch
cp pridefetch "$installdir/"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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/"

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

Successfully merging this pull request may close these issues.

Give instructions on packaging to a single file for adding to path
3 participants