Skip to content

Instantly share code, notes, and snippets.

@StanAngeloff
Created August 21, 2011 10:05
Show Gist options
  • Save StanAngeloff/1160421 to your computer and use it in GitHub Desktop.
Save StanAngeloff/1160421 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Copyright (C) 2011 Bumblebee Project
#
# This file is part of Bumblebee.
#
# Bumblebee is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Bumblebee is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Bumblebee. If not, see <http://www.gnu.org/licenses/>.
# The line below should never be removed and should match regex: *# *BEE..
# BEE_UNINSTALLER_NEW DO NOT REMOVE THIS LINE
# Exit codes:
# 0 - uninstall was succesful
# 1 - uninstallation could not be started (confirmation rejected, insufficient
# privileges)
# 2 - Uninstall failure - nothing was removed but services might be stopped
# 3 - Uninstall failure - unstable state (half-removed)
UNATTENDED=false
KEEP_CONFFILE=false
CONFDIR='/etc/bumblebee'
while [ $# -gt 0 ]; do
case "$1" in
--unattended)
UNATTENDED=true
;;
--upgrade)
KEEP_CONFFILE=true
;;
--)
shift
break
;;
--help)
echo "Usage: $0 [options]"
echo
echo " --unattended"
echo " Do not confirm, proceed with uninstallation"
echo
echo " --upgrade"
echo " Upgrade mode, do not remove configuration files"
exit 0
;;
*)
# remember our policy on GH-14: ignore unrecognized options
echo "Ignored unrecognized option: '$1'"
;;
esac
shift
done
if (( EUID != 0 )); then
echo "You do not have sufficient privileges to uninstall Bumblebee"
echo
if which sudo &>/dev/null; then
echo "Please run: sudo $0"
else
echo "Please run this script as root"
fi
echo
exit 1
fi
if ! $UNATTENDED; then
echo "You are about to uninstall Bumblebee."
read -p "Continue [y/N]? " yn
if [[ $yn != [Yy]* ]]; then
echo "Aborted."
exit 1
fi
fi
echo "Stopping services..."
/etc/init.d/bumblebee stop
echo "Removing services..."
update-rc.d -f bumblebee remove
uninstall() {
local file="$1"
if $KEEP_CONFFILE && [[ $file == "$CONFDIR/"* ]]; then
echo "Not removing $file"
return
fi
rm -vf "$1"
}
uninstall_dir() {
local dir="$1"
rmdir -v "$1"
}
# Begin uninstallation of files
uninstall '/etc/bash_completion.d/optirun'
uninstall '/etc/init.d/bumblebee'
uninstall '/usr/local/bin/bumblebee-bugreport'
uninstall '/usr/local/bin/optirun'
uninstall '/usr/local/sbin/bumblebee'
uninstall '/usr/local/lib/bumblebee/drivers/nvidia.options'
uninstall '/usr/local/lib/bumblebee/common-functions'
uninstall '/usr/local/lib/bumblebee/common-paths'
uninstall '/etc/bumblebee/xorg.conf.nvidia'
uninstall '/etc/bumblebee/bumblebee.conf'
uninstall_dir '/usr/local/lib/bumblebee/drivers'
uninstall_dir '/usr/local/lib/bumblebee'
uninstall_dir '/etc/bumblebee'
# XXX: check if I am allowed to be removed
# remove myself. Note: do not source this fill, or /bin/bash will be removed!
rm -f "$0"
echo "Bumblebee has been uninstalled."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment