201 lines
6.5 KiB
Python
Executable File
201 lines
6.5 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
|
|
###########
|
|
# IMPORTS #
|
|
###########
|
|
from os import path as ospath;
|
|
from os import system as ossystem;
|
|
import sys;
|
|
|
|
|
|
# get absolute path
|
|
path = ospath.dirname(ospath.realpath(__file__));
|
|
|
|
# [1] Help function
|
|
#========================================================#
|
|
def showhelp():
|
|
print "\033[1mNAME\033[0m"
|
|
print "\tapt-plus 1.0.0 (amd64)";
|
|
print;
|
|
print "\033[1mSYNOPSIS\033[0m"
|
|
print "\tapt-plus <command> <packages>";
|
|
print "\tapt-plus -g <group> <command> <packages>";
|
|
print "\tapt-plus --gropu <group> <command> <packages>";
|
|
print;
|
|
print "\t-g, --group <group>";
|
|
print "\t\tProccess actions within a specific group (applies to: install, purge, remove, list, deb install).";
|
|
print;
|
|
print "\033[1mDESCRIPTION\033[0m"
|
|
print ""
|
|
print "\tapt-plus is top-level wrapper of apt-get and dpkg, also";
|
|
print "\tit logs every package you have installed, removed, purged.";
|
|
print "\tThese logs are stored in the manifest file (default is ~/.x-migration).";
|
|
print;
|
|
print "\033[1mOPTIONS\033[0m"
|
|
print "\t-l, --list";
|
|
print "\t\tList all the packages stored in the manifest.";
|
|
print;
|
|
print "\t-d, --deb <deb_file>";
|
|
print "\t\tInstalls a package from a .deb file and notice it in the manifest.";
|
|
print;
|
|
print "\t-i, --install <packages>";
|
|
print "\t\tInstalls one or more packages and notice it in the manifest, note that";
|
|
print "\t\tthe <packages> argument is a list of packages' names separated by spaces.";
|
|
print;
|
|
print "\t-f, --fetch";
|
|
print "\t\tFetches packages from remote to local.";
|
|
print;
|
|
print "\t-m --manifest <manifest_file>";
|
|
print "\t\tSet the global manifest file for registering packages\n";
|
|
print;
|
|
print "\t-p, --purge <packages>";
|
|
print "\t\tPurges one or more packages and notice it in the manifest, note that";
|
|
print "\t\tthe <packages> is a list of packages' names separated by spaces.";
|
|
print "\t\tThe packages configurations won't be kept, --remove will keep them.";
|
|
print;
|
|
print "\t-r, --remove <packages>";
|
|
print "\t\tRemoves one or more packages and notice it in the manifest, note that";
|
|
print "\t\tthe <packages> is a list of packages' names separated by spaces.";
|
|
print "\t\tThe packages configurations will be kept, --purge won't keep them.";
|
|
print;
|
|
print "\t-u, --update";
|
|
print "\t\tUpgrades packages and kernel and cleans after";
|
|
print;
|
|
print "\t-a, --add-ppa <ppa_link>";
|
|
print "\t\tAdds the <ppa_link> repository to dpkg then update it";
|
|
print;
|
|
|
|
|
|
# [2] Command dispatch (if at least 1 arg)
|
|
#========================================================#
|
|
if ( len(sys.argv) > 1 ):
|
|
|
|
# (1) Manage optional -g --group modifier
|
|
#--------------------------------------------------------#
|
|
OPTGROUP = None;
|
|
ARGS = sys.argv;
|
|
if( len(sys.argv) > 2 and sys.argv[1] == "-g" or sys.argv[1] == "--group" ):
|
|
OPTGROUP = sys.argv[2];
|
|
ARGS = ARGS[0:1] + ARGS[3:];
|
|
|
|
# (2) Normal arguments
|
|
#--------------------------------------------------------#
|
|
# (1) Get the command argument (first) #
|
|
command = ARGS[1];
|
|
|
|
# (1) --update, -u
|
|
#--------------------------------------------------------#
|
|
if ( command == "-u" or command == "--update" ):
|
|
|
|
ossystem("/usr/bin/env sh %s/command/update;" % path);
|
|
|
|
# (2) --fetch, -f
|
|
#--------------------------------------------------------#
|
|
elif ( command == "-f" or command == "--fetch" ):
|
|
|
|
ossystem("/usr/bin/env sh %s/command/fetch;" % path);
|
|
|
|
# (3) --deb-install, -d
|
|
#--------------------------------------------------------#
|
|
elif ( command == "-d" or command == "--deb" ):
|
|
|
|
# if package/s given
|
|
if ( len(ARGS) < 3 ):
|
|
sys.exit("\n(!) Missing argument <deb_file>");
|
|
|
|
if( OPTGROUP != None ):
|
|
ossystem("/usr/bin/env python %s/command/debinstall -g %s %s" % (path, OPTGROUP, ARGS[2]) );
|
|
else:
|
|
ossystem("/usr/bin/env python %s/command/debinstall %s" % (path, ARGS[2]) );
|
|
|
|
# (4) --install, -i
|
|
#--------------------------------------------------------#
|
|
elif ( command == "-i" or command == "--install" ):
|
|
|
|
# if package/s given
|
|
if ( len(ARGS) < 3 ):
|
|
sys.exit("\n(!) Missing argument <packages>");
|
|
|
|
packages = " ".join(ARGS[2:]);
|
|
|
|
if( OPTGROUP != None ):
|
|
ossystem("/usr/bin/env python %s/command/install -g %s %s" % (path, OPTGROUP, packages) );
|
|
else:
|
|
ossystem("/usr/bin/env python %s/command/install %s" % (path, packages) );
|
|
|
|
# (5) --remove, -r
|
|
#--------------------------------------------------------#
|
|
elif ( command == "-r" or command == "--remove" ):
|
|
|
|
# if package/s given
|
|
if ( len(ARGS) < 3 ):
|
|
sys.exit("\n(!) Missing argument <packages>");
|
|
|
|
packages = " ".join(ARGS[2:]);
|
|
|
|
if( OPTGROUP != None ):
|
|
ossystem("/usr/bin/env python %s/command/remove -g %s %s" % (path, OPTGROUP, packages) );
|
|
else:
|
|
ossystem("/usr/bin/env python %s/command/remove %s" % (path, packages) );
|
|
|
|
# (6) --purge, -p
|
|
#--------------------------------------------------------#
|
|
elif ( command == "-p" or command == "--purge" ):
|
|
# if package/s given
|
|
if ( len(ARGS) < 3 ):
|
|
sys.exit("\n(!) Missing argument <packages>");
|
|
|
|
packages = " ".join(ARGS[2:]);
|
|
if( OPTGROUP != None ):
|
|
ossystem("/usr/bin/env python %s/command/purge -g %s %s" % (path, OPTGROUP, packages) );
|
|
else:
|
|
ossystem("/usr/bin/env python %s/command/purge %s" % (path, packages) );
|
|
|
|
# (7) --manifest, -m
|
|
#--------------------------------------------------------#
|
|
elif ( command == "-m" or command == "--manifest" ):
|
|
|
|
# (1) If argument missing -> abort #
|
|
if ( len(ARGS) < 3 ):
|
|
sys.exit("\n(!) Missing argument <manifest_file>");
|
|
|
|
# (2) If argument is not a valid file -> abort #
|
|
elif ( not ospath.isfile(ARGS[2]) ):
|
|
sys.exit("Given path isn't a file");
|
|
|
|
# (3) Store absolute path in ./manifest file #
|
|
file = ospath.realpath(ARGS[2]);
|
|
with open( ("%s/manifest" % path), "w") as f:
|
|
f.write(file);
|
|
|
|
# (8) --list, -l
|
|
#--------------------------------------------------------#
|
|
elif ( command == "-l" or command == "--list" ):
|
|
|
|
if( OPTGROUP != None ):
|
|
ossystem("/usr/bin/env python %s/command/list -g %s" % (path, OPTGROUP) );
|
|
else:
|
|
ossystem("/usr/bin/env python %s/command/list" % path );
|
|
|
|
# (9) --add-ppa, -a
|
|
#--------------------------------------------------------#
|
|
elif ( command == "-a" or command == "--add-ppa" ):
|
|
|
|
# if ppa is given
|
|
if ( len(ARGS) < 3 ):
|
|
sys.exit("\n(!) Missing argument <ppa_link>");
|
|
|
|
ossystem("/usr/bin/env python %s/command/addppa %s" % (path, ARGS[2]) );
|
|
|
|
# (10) If no match -> show help message
|
|
#--------------------------------------------------------#
|
|
else:
|
|
showhelp();
|
|
|
|
|
|
# [3] If not enough arguments -> show help message
|
|
#========================================================#
|
|
else:
|
|
showhelp();
|