Last active
February 3, 2016 00:34
-
-
Save dccampbell/e090e5544333b43c2f91 to your computer and use it in GitHub Desktop.
Install Magerun, restrict to one user, and create alias.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Install Magerun, restrict to one user, and create alias. | |
# Usage: installMagerun.sh [user] [path] | |
# [user] defaults to current user | |
# [path] defaults to current ./n98-magerun.phar | |
# Vars | |
mrUser="${1:-$(whoami)}" | |
mrPath="${2:-./}" | |
# Prepare Path | |
[[ "$mrPath" == *'/' || -d "$mrPath" ]] && mrPath="${mrPath%/}/n98-magerun.phar" | |
mrPath=$(readlink -f $mrPath) | |
mkdir -p "$(dirname $mrPath)" | |
rm -f "$mrPath" | |
# Download and Set Permissions | |
echo "Installing Magerun to $mrPath for $mrUser..." | |
curl -L "http://files.magerun.net/n98-magerun-latest.phar" -o "$mrPath" || exit 1 | |
chown "$mrUser" "$mrPath" && chmod 500 "$mrPath" || exit 1 | |
# Alias | |
if [[ $(id -u) != "0" ]]; then | |
aliasFile="$HOME/.bashrc" | |
[[ $(whoami) != "$mrUser" ]] && sudoStr="sudo -u $mrUser " | |
[[ -f "$aliasFile" ]] && sed -i '/#n98-magerun/d' "$aliasFile" | |
echo "alias magerun='$sudoStr$mrPath' #n98-magerun" >> "$aliasFile" \ | |
&& echo "Magerun alias installed to $aliasFile" | |
else | |
aliasFile="/etc/profile.d/magerun.sh" | |
echo "alias magerun='sudo -u $mrUser $mrPath'" > "$aliasFile" \ | |
&& echo "Magerun alias installed to $aliasFile" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bash <(curl -s https://gist.githubusercontent.com/dccampbell/e090e5544333b43c2f91/raw/installMagerun.sh)
or
bash <(wget -qO- https://gist.githubusercontent.com/dccampbell/e090e5544333b43c2f91/raw/installMagerun.sh)