Skip to content

Commit

Permalink
Fixed issue #6
Browse files Browse the repository at this point in the history
  • Loading branch information
matteoacrossi committed Mar 16, 2016
1 parent d2becb1 commit 2bb247e
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,11 @@ loginhook="nobootsound_loginhook"
logouthook="nobootsound_logouthook"
logoutvolume="nobootsound_logoutvol"

#-- Find 'echo' program in PATH or use Mac Ports default location
ECHO="$( which echo )"
ECHO="${ECHO:-/opt/local/libexec/gnubin/echo}"

#-- Directory containing this installer and the scripts to install.
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

if [ "$(id -u)" != "0" ]; then
${ECHO} "You need administrative privileges to install this script.\nPlease run: sudo ./install.sh"
printf "You need administrative privileges to install this script.\nPlease run: sudo ./install.sh\n"
exit 1
fi

Expand All @@ -30,43 +26,43 @@ while getopts ":u" opt; do
uninstallmode=true
;;
\?)
${ECHO} "Invalid option: -$OPTARG" >&2
printf "Invalid option: -$OPTARG\n" >&2
;;
esac
done


if [ "$uninstallmode" = true ]; then
${ECHO} "Removing hooks..."
printf "Removing hooks...\n"
defaults delete com.apple.loginwindow LoginHook
defaults delete com.apple.loginwindow LogoutHook

${ECHO} "Removing files..."
printf "Removing files...\n"
rm "$installation_folder$loginhook"
rm "$installation_folder$logouthook"
rm "$installation_folder$logoutvolume"

${ECHO} "Done!"
printf "Done!\n"

else
${ECHO} "Copying files..."
printf "Copying files...\n"

# Create installation folder if it doesn't already exists.
mkdir -p "$installation_folder"

# Create file where the mute state is stored
sudo ${ECHO} "false" > "$installation_folder$logoutvolume"
sudo printf "false" > "$installation_folder$logoutvolume"

# Copy login and logout scripts and make them executable
sudo cp "${DIR}/$loginhook" "$installation_folder"
sudo cp "${DIR}/$logouthook" "$installation_folder"
sudo chmod +x "$installation_folder$loginhook"
sudo chmod +x "$installation_folder$logouthook"

${ECHO} "Registering hooks..."
printf "Registering hooks...\n"
# Register the scripts as login and logout hooks
defaults write com.apple.loginwindow LoginHook "$installation_folder$loginhook"
defaults write com.apple.loginwindow LogoutHook "$installation_folder$logouthook"

${ECHO} "Done!"
printf "Done!\n"
fi

0 comments on commit 2bb247e

Please sign in to comment.