mirror of
https://github.com/wting/autojump
synced 2024-10-27 20:34:07 +00:00
update install, add uninstall
This commit is contained in:
parent
a59d671fb0
commit
661f17791c
34
install.py
34
install.py
@ -29,9 +29,12 @@ def mkdir(path, dryrun=False):
|
|||||||
|
|
||||||
|
|
||||||
def parse_arguments():
|
def parse_arguments():
|
||||||
default_destdir = os.path.join(os.path.expanduser("~"), '.autojump')
|
default_user_destdir = os.path.join(os.path.expanduser("~"), '.autojump')
|
||||||
default_prefix = ''
|
default_user_prefix = ''
|
||||||
default_zshshare = 'functions'
|
default_user_zshshare = 'functions'
|
||||||
|
default_system_destdir = '/'
|
||||||
|
default_system_prefix = '/usr/local'
|
||||||
|
default_system_zshshare = '/usr/share/zsh/site-functions'
|
||||||
|
|
||||||
parser = ArgumentParser(
|
parser = ArgumentParser(
|
||||||
description='Installs autojump globally for root users, otherwise \
|
description='Installs autojump globally for root users, otherwise \
|
||||||
@ -40,13 +43,13 @@ def parse_arguments():
|
|||||||
'-n', '--dryrun', action="store_true", default=False,
|
'-n', '--dryrun', action="store_true", default=False,
|
||||||
help='simulate installation')
|
help='simulate installation')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-d', '--destdir', metavar='DIR', default=default_destdir,
|
'-d', '--destdir', metavar='DIR', default=default_user_destdir,
|
||||||
help='set destination to DIR')
|
help='set destination to DIR')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-p', '--prefix', metavar='DIR', default=default_prefix,
|
'-p', '--prefix', metavar='DIR', default=default_user_prefix,
|
||||||
help='set prefix to DIR')
|
help='set prefix to DIR')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-z', '--zshshare', metavar='DIR', default=default_zshshare,
|
'-z', '--zshshare', metavar='DIR', default=default_user_zshshare,
|
||||||
help='set zsh share destination to DIR')
|
help='set zsh share destination to DIR')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-s', '--system', action="store_true", default=False,
|
'-s', '--system', action="store_true", default=False,
|
||||||
@ -64,14 +67,15 @@ def parse_arguments():
|
|||||||
|
|
||||||
if args.system:
|
if args.system:
|
||||||
if os.geteuid() != 0:
|
if os.geteuid() != 0:
|
||||||
print("Please rerun as root for system-wide installation.", file=sys.stderr)
|
print("Please rerun as root for system-wide installation.",
|
||||||
|
file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if args.destdir == default_destdir:
|
if args.destdir == default_user_destdir:
|
||||||
args.destdir = '/'
|
args.destdir = default_system_destdir
|
||||||
if args.prefix == default_prefix:
|
if args.prefix == default_user_prefix:
|
||||||
args.prefix = '/usr/local'
|
args.prefix = default_system_prefix
|
||||||
if args.zshshare == default_zshshare:
|
if args.zshshare == default_user_zshshare:
|
||||||
args.zshshare = '/usr/share/zsh/site-functions'
|
args.zshshare = default_system_zshshare
|
||||||
|
|
||||||
return args
|
return args
|
||||||
|
|
||||||
@ -103,8 +107,8 @@ def main(args):
|
|||||||
mkdir(zshshare_dir, args.dryrun)
|
mkdir(zshshare_dir, args.dryrun)
|
||||||
|
|
||||||
cp('./bin/autojump', bin_dir, args.dryrun)
|
cp('./bin/autojump', bin_dir, args.dryrun)
|
||||||
cp('./bin/data.py', bin_dir, args.dryrun)
|
cp('./bin/autojump_data.py', bin_dir, args.dryrun)
|
||||||
cp('./bin/utils.py', bin_dir, args.dryrun)
|
cp('./bin/autojump_utils.py', bin_dir, args.dryrun)
|
||||||
cp('./bin/autojump.sh', etc_dir, args.dryrun)
|
cp('./bin/autojump.sh', etc_dir, args.dryrun)
|
||||||
cp('./bin/autojump.bash', etc_dir, args.dryrun)
|
cp('./bin/autojump.bash', etc_dir, args.dryrun)
|
||||||
cp('./bin/autojump.fish', etc_dir, args.dryrun)
|
cp('./bin/autojump.fish', etc_dir, args.dryrun)
|
||||||
|
79
uninstall.py
79
uninstall.py
@ -5,30 +5,59 @@ from __future__ import print_function
|
|||||||
|
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
import os
|
import os
|
||||||
|
import platform
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
def parse_arguments():
|
def parse_arguments():
|
||||||
parser = ArgumentParser(
|
parser = ArgumentParser(
|
||||||
description='Installs autojump globally for root users, otherwise \
|
description='Uninstalls autojump.')
|
||||||
installs in current user\'s home directory.')
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-n', '--dryrun', action="store_true", default=False,
|
'-n', '--dryrun', action="store_true", default=False,
|
||||||
help='simulate installation')
|
help='simulate installation')
|
||||||
|
parser.add_argument(
|
||||||
|
'-u', '--userdata', action="store_true", default=False,
|
||||||
|
help='`delete user data')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-d', '--destdir', metavar='DIR',
|
'-d', '--destdir', metavar='DIR',
|
||||||
help='set destination to DIR')
|
help='set destination to DIR')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-p', '--prefix', metavar='DIR',
|
'-p', '--prefix', metavar='DIR', default='',
|
||||||
help='set prefix to DIR')
|
help='set prefix to DIR')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-z', '--zshshare', metavar='DIR',
|
'-z', '--zshshare', metavar='DIR', default='functions',
|
||||||
help='set zsh share destination to DIR')
|
help='set zsh share destination to DIR')
|
||||||
|
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
def remove_custom_installation(args, dryrun=False):
|
||||||
|
if not args.destdir:
|
||||||
|
return
|
||||||
|
|
||||||
|
bin_dir = os.path.join(args.destdir, args.prefix, 'bin')
|
||||||
|
etc_dir = os.path.join(args.destdir, 'etc/profile.d')
|
||||||
|
doc_dir = os.path.join(args.destdir, args.prefix, 'share/man/man1')
|
||||||
|
icon_dir = os.path.join(args.destdir, args.prefix, 'share/autojump')
|
||||||
|
zshshare_dir = os.path.join(args.destdir, args.zshshare)
|
||||||
|
|
||||||
|
if not os.path.exists(icon_dir):
|
||||||
|
return
|
||||||
|
|
||||||
|
print("\nFound custom installation...")
|
||||||
|
rm(os.path.join(bin_dir, 'autojump'), dryrun)
|
||||||
|
rm(os.path.join(bin_dir, 'autojump_data.py'), dryrun)
|
||||||
|
rm(os.path.join(bin_dir, 'autojump_utils.py'), dryrun)
|
||||||
|
rm(os.path.join(etc_dir, 'autojump.sh'), dryrun)
|
||||||
|
rm(os.path.join(etc_dir, 'autojump.bash'), dryrun)
|
||||||
|
rm(os.path.join(etc_dir, 'autojump.fish'), dryrun)
|
||||||
|
rm(os.path.join(etc_dir, 'autojump.zsh'), dryrun)
|
||||||
|
rm(os.path.join(zshshare_dir, '_j'), dryrun)
|
||||||
|
rmdir(icon_dir, dryrun)
|
||||||
|
rm(os.path.join(doc_dir, 'autojump.1'), dryrun)
|
||||||
|
|
||||||
|
|
||||||
def remove_system_installation(dryrun=False):
|
def remove_system_installation(dryrun=False):
|
||||||
default_destdir = '/'
|
default_destdir = '/'
|
||||||
default_prefix = '/usr/local'
|
default_prefix = '/usr/local'
|
||||||
@ -40,14 +69,19 @@ def remove_system_installation(dryrun=False):
|
|||||||
icon_dir = os.path.join(default_destdir, default_prefix, 'share/autojump')
|
icon_dir = os.path.join(default_destdir, default_prefix, 'share/autojump')
|
||||||
zshshare_dir = os.path.join(default_destdir, default_zshshare)
|
zshshare_dir = os.path.join(default_destdir, default_zshshare)
|
||||||
|
|
||||||
if os.path.exists(os.path.join(bin_dir, 'autojump')):
|
if not os.path.exists(icon_dir):
|
||||||
print("Found system installation.")
|
return
|
||||||
else:
|
|
||||||
|
print("\nFound system installation...")
|
||||||
|
|
||||||
|
if os.geteuid() != 0:
|
||||||
|
print("Please rerun as root for system-wide uninstall, skipping...",
|
||||||
|
file=sys.stderr)
|
||||||
return
|
return
|
||||||
|
|
||||||
rm(os.path.join(bin_dir, 'autojump'), dryrun)
|
rm(os.path.join(bin_dir, 'autojump'), dryrun)
|
||||||
rm(os.path.join(bin_dir, 'data.py'), dryrun)
|
rm(os.path.join(bin_dir, 'autojump_data.py'), dryrun)
|
||||||
rm(os.path.join(bin_dir, 'utils.py'), dryrun)
|
rm(os.path.join(bin_dir, 'autojump_utils.py'), dryrun)
|
||||||
rm(os.path.join(etc_dir, 'autojump.sh'), dryrun)
|
rm(os.path.join(etc_dir, 'autojump.sh'), dryrun)
|
||||||
rm(os.path.join(etc_dir, 'autojump.bash'), dryrun)
|
rm(os.path.join(etc_dir, 'autojump.bash'), dryrun)
|
||||||
rm(os.path.join(etc_dir, 'autojump.fish'), dryrun)
|
rm(os.path.join(etc_dir, 'autojump.fish'), dryrun)
|
||||||
@ -57,10 +91,30 @@ def remove_system_installation(dryrun=False):
|
|||||||
rm(os.path.join(doc_dir, 'autojump.1'), dryrun)
|
rm(os.path.join(doc_dir, 'autojump.1'), dryrun)
|
||||||
|
|
||||||
|
|
||||||
|
def remove_user_data(dryrun=False):
|
||||||
|
if platform.system() == 'Darwin':
|
||||||
|
data_home = os.path.join(
|
||||||
|
os.path.expanduser('~'),
|
||||||
|
'Library',
|
||||||
|
'autojump')
|
||||||
|
else:
|
||||||
|
data_home = os.getenv(
|
||||||
|
'XDG_DATA_HOME',
|
||||||
|
os.path.join(
|
||||||
|
os.path.expanduser('~'),
|
||||||
|
'.local',
|
||||||
|
'share',
|
||||||
|
'autojump'))
|
||||||
|
|
||||||
|
if os.path.exists(data_home):
|
||||||
|
print("\nFound user data...")
|
||||||
|
rmdir(data_home, dryrun)
|
||||||
|
|
||||||
|
|
||||||
def remove_user_installation(dryrun=False):
|
def remove_user_installation(dryrun=False):
|
||||||
default_destdir = os.path.join(os.path.expanduser("~"), '.autojump')
|
default_destdir = os.path.join(os.path.expanduser("~"), '.autojump')
|
||||||
if os.path.exists(default_destdir):
|
if os.path.exists(default_destdir):
|
||||||
print("Found user installation.")
|
print("\nFound user installation...")
|
||||||
rmdir(default_destdir, dryrun)
|
rmdir(default_destdir, dryrun)
|
||||||
|
|
||||||
|
|
||||||
@ -68,7 +122,7 @@ def rm(path, dryrun):
|
|||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
print("deleting file:", path)
|
print("deleting file:", path)
|
||||||
if not dryrun:
|
if not dryrun:
|
||||||
shutil.rmtree(path)
|
os.remove(path)
|
||||||
|
|
||||||
|
|
||||||
def rmdir(path, dryrun):
|
def rmdir(path, dryrun):
|
||||||
@ -86,6 +140,9 @@ def main(args):
|
|||||||
|
|
||||||
remove_user_installation(args.dryrun)
|
remove_user_installation(args.dryrun)
|
||||||
remove_system_installation(args.dryrun)
|
remove_system_installation(args.dryrun)
|
||||||
|
remove_custom_installation(args, args.dryrun)
|
||||||
|
if args.userdata:
|
||||||
|
remove_user_data(args.dryrun)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
Reference in New Issue
Block a user