.deb file install management + remove + purge + cleaned and evolved `help` message + -- and - arguments
This commit is contained in:
parent
de37686a7b
commit
0eda775e09
|
@ -0,0 +1,81 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import re;
|
||||
from os import system as ossystem;
|
||||
from os import path as ospath;
|
||||
from sys import argv as sysargv;
|
||||
|
||||
# [1] get absolute path
|
||||
#========================================================#
|
||||
path = ospath.dirname(ospath.dirname(ospath.realpath(__file__)));
|
||||
|
||||
|
||||
# [2] get @deb_file argument
|
||||
#========================================================#
|
||||
deb_file = sysargv[1];
|
||||
|
||||
|
||||
# [3] search for manifest file
|
||||
#========================================================#
|
||||
manifest="";
|
||||
with open( "%s/manifest" % path, 'r' ) as f:
|
||||
manifest=f.readline();
|
||||
|
||||
|
||||
|
||||
# [4] search for already installed entries in manifest
|
||||
#========================================================#
|
||||
alrdy = [];
|
||||
findPkg = re.compile("^\s*\[[\. x]\]\s([a-zA-Z0-9_ \[\]-]+)$", 0);
|
||||
with open(manifest, 'r+') as f:
|
||||
for line in f:
|
||||
m = findPkg.search(line);
|
||||
if ( m != None ):
|
||||
alrdy.append( m.group(1) ) ;
|
||||
|
||||
|
||||
# [5] Install the deb_file
|
||||
#========================================================#
|
||||
pkgName = "";
|
||||
|
||||
# (1) Try to install #
|
||||
print "\033[38;5;208m[deb-install] %s\033[0m" % (deb_file);
|
||||
exitcode = ossystem("sudo dpkg -i %s > %s/stdout" % (deb_file, path));
|
||||
|
||||
# (2) Read local stdout copy of stdout #
|
||||
findName = re.compile("^Unpacking ([a-zA-Z0-9_-]+)", re.MULTILINE)
|
||||
with open( "%s/stdout" % path, 'r' ) as f:
|
||||
line = f.read();
|
||||
print line;
|
||||
m = findName.search(line);
|
||||
|
||||
if ( m != None ):
|
||||
pkgName = "%s [deb]" % m.group(1);
|
||||
|
||||
|
||||
# (3) On success and notice user #
|
||||
if ( exitcode == 0 and len(pkgName) > 0 ):
|
||||
print "\033[38;5;78msuccess\033[0m";
|
||||
|
||||
# (4) On failure notice user -> abort #
|
||||
else:
|
||||
print "\033[38;5;161merror\033[0m";
|
||||
exit(1);
|
||||
|
||||
|
||||
|
||||
|
||||
# [6] Update manifest
|
||||
#========================================================#
|
||||
print "\033[38;5;39m[notifying] %s\033[0m" % (pkgName);
|
||||
|
||||
# if new package
|
||||
if( not pkgName in alrdy ):
|
||||
with open(manifest, "a") as f:
|
||||
f.write(" [x] %s\n" % pkgName);
|
||||
else:
|
||||
with open(manifest, 'r') as reader:
|
||||
replaced = reader.read().replace("[ ] %s" % pkgName, "[x] %s" % pkgName).replace("[.] %s" % pkgName, "[x] %s" % pkgName);
|
||||
|
||||
with open(manifest, 'w') as writer:
|
||||
writer.write( replaced );
|
|
@ -0,0 +1,14 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
success_f(){
|
||||
echo "\033[38;5;78mSUCCESS\033[31;0m";
|
||||
}
|
||||
|
||||
abort_f(){
|
||||
echo "\033[38;5;161mABORTING\033[31;0m";
|
||||
exit;
|
||||
}
|
||||
|
||||
# Fetching sources list
|
||||
echo "\033[38;5;208m[1/1] FETCHING PACKAGES\033[31;0m";
|
||||
sudo apt-get update && success_f || abort_f;
|
|
@ -1,4 +1,4 @@
|
|||
#!/bin/py
|
||||
#!/usr/bin/env python
|
||||
|
||||
import re;
|
||||
from os import system as ossystem;
|
||||
|
@ -6,7 +6,7 @@ from os import path as ospath;
|
|||
from sys import argv as sysargv;
|
||||
|
||||
# [1] get absolute path
|
||||
path = ospath.dirname(ospath.realpath(__file__));
|
||||
path = ospath.dirname(ospath.dirname(ospath.realpath(__file__)));
|
||||
|
||||
# [2] get packages
|
||||
packages = sysargv[1:];
|
||||
|
@ -18,19 +18,19 @@ with open( "%s/manifest" % path, 'r' ) as f:
|
|||
|
||||
# [4] search for non-installed entries in manifest
|
||||
alrdy = [];
|
||||
findAlrdy = re.compile("^\s*\[[\. x]\]\s([a-zA-Z0-9_ \[\]-]+)$", 0);
|
||||
with open(manifest, 'r+') as f:
|
||||
for line in f:
|
||||
m = re.search(r"\s*\[[\. ]\] ([a-zA-Z0-9_-]+)", line);
|
||||
m = findAlrdy.search(line);
|
||||
if ( m != None ):
|
||||
alrdy.append( m.group(1) ) ;
|
||||
|
||||
# [5] Install packages
|
||||
installed = [];
|
||||
|
||||
for pkg in packages:
|
||||
print "\033[38;5;208m[install](%d/%d) %s\033[0m" % (packages.index(pkg)+1, len(packages), pkg);
|
||||
exitcode = ossystem("sudo apt-get install %s" % pkg);
|
||||
|
||||
|
||||
# if all ran successfully
|
||||
if ( exitcode == 0 ):
|
||||
print "\033[38;5;78msuccess\033[0m";
|
|
@ -1,4 +1,4 @@
|
|||
#!/bin/py
|
||||
#!/usr/bin/env python
|
||||
|
||||
import re;
|
||||
from os import system as ossystem;
|
||||
|
@ -6,7 +6,7 @@ from os import path as ospath;
|
|||
from sys import argv as sysargv;
|
||||
|
||||
# [1] get absolute path
|
||||
path = ospath.dirname(ospath.realpath(__file__));
|
||||
path = ospath.dirname(ospath.dirname(ospath.realpath(__file__)));
|
||||
|
||||
# [2] get packages
|
||||
packages = sysargv[1:];
|
||||
|
@ -18,9 +18,10 @@ with open( "%s/manifest" % path, 'r' ) as f:
|
|||
|
||||
# [4] search for installed entries in manifest
|
||||
alrdy = [];
|
||||
findAlrdy = re.compile("^\s*\[x\]\s(?:([a-zA-Z0-9_-]+)(?: \[deb\])?)$", 0);
|
||||
with open(manifest, 'r+') as f:
|
||||
for line in f:
|
||||
m = re.search(r"\s*\[x\] ([a-zA-Z0-9_-]+)", line);
|
||||
m = findAlrdy.search(line);
|
||||
if ( m != None ):
|
||||
alrdy.append( m.group(1) ) ;
|
||||
|
||||
|
@ -30,7 +31,7 @@ purged = [];
|
|||
for pkg in packages:
|
||||
print "\033[38;5;208m[purge](%d/%d) %s\033[0m" % (packages.index(pkg)+1, len(packages), pkg);
|
||||
exitcode = ossystem("sudo apt-get purge %s" % pkg);
|
||||
|
||||
|
||||
# if all ran successfully
|
||||
if ( exitcode == 0 ):
|
||||
print "\033[38;5;78msuccess\033[0m";
|
||||
|
@ -49,7 +50,7 @@ for pkg in purged:
|
|||
f.write(" [ ] %s\n" % pkg);
|
||||
else:
|
||||
with open(manifest, 'r') as reader:
|
||||
replaced = reader.read().replace("[x] %s" % pkg, "[ ] %s" % pkg);
|
||||
replaced = reader.read().replace("[x] %s" % pkg, "[ ] %s" % pkg).replace("[x] %s [deb]" % pkg, "[ ] %s [deb]" % pkg);
|
||||
|
||||
with open(manifest, 'w') as writer:
|
||||
writer.write( replaced );
|
|
@ -1,4 +1,4 @@
|
|||
#!/bin/py
|
||||
#!/usr/bin/env python
|
||||
|
||||
import re;
|
||||
from os import system as ossystem;
|
||||
|
@ -6,7 +6,7 @@ from os import path as ospath;
|
|||
from sys import argv as sysargv;
|
||||
|
||||
# [1] get absolute path
|
||||
path = ospath.dirname(ospath.realpath(__file__));
|
||||
path = ospath.dirname(ospath.dirname(ospath.realpath(__file__)));
|
||||
|
||||
# [2] get packages
|
||||
packages = sysargv[1:];
|
||||
|
@ -18,9 +18,10 @@ with open( "%s/manifest" % path, 'r' ) as f:
|
|||
|
||||
# [4] search for installed entries in manifest
|
||||
alrdy = [];
|
||||
findAlrdy = re.compile("^\s*\[x\]\s(?:([a-zA-Z0-9_-]+)(?: \[deb\])?)$", 0);
|
||||
with open(manifest, 'r+') as f:
|
||||
for line in f:
|
||||
m = re.search(r"\s*\[x\] ([a-zA-Z0-9_-]+)", line);
|
||||
m = findAlrdy.search(line);
|
||||
if ( m != None ):
|
||||
alrdy.append( m.group(1) ) ;
|
||||
|
||||
|
@ -30,7 +31,7 @@ removed = [];
|
|||
for pkg in packages:
|
||||
print "\033[38;5;208m[remove](%d/%d) %s\033[0m" % (packages.index(pkg)+1, len(packages), pkg);
|
||||
exitcode = ossystem("sudo apt-get remove %s" % pkg);
|
||||
|
||||
|
||||
# if all ran successfully
|
||||
if ( exitcode == 0 ):
|
||||
print "\033[38;5;78msuccess\033[0m";
|
||||
|
@ -49,7 +50,7 @@ for pkg in removed:
|
|||
f.write(" [.] %s\n" % pkg);
|
||||
else:
|
||||
with open(manifest, 'r') as reader:
|
||||
replaced = reader.read().replace("[x] %s" % pkg, "[.] %s" % pkg);
|
||||
replaced = reader.read().replace("[x] %s" % pkg, "[.] %s" % pkg).replace("[x] %s [deb]" % pkg, "[.] %s [deb]" % pkg);
|
||||
|
||||
with open(manifest, 'w') as writer:
|
||||
writer.write( replaced );
|
|
@ -1,4 +1,4 @@
|
|||
#!/bin/sh
|
||||
#!/usr/bin/env sh
|
||||
|
||||
success_f(){
|
||||
echo "\033[38;5;78mSUCCESS\033[31;0m";
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
sudo ln -fs $( dirname $(readlink -f $0) )/main /usr/bin/apt-plus;
|
|
@ -1,4 +1,4 @@
|
|||
#!/bin/py
|
||||
#!/usr/bin/env python
|
||||
|
||||
|
||||
###########
|
||||
|
@ -12,70 +12,136 @@ import sys;
|
|||
# get absolute path
|
||||
path = ospath.dirname(ospath.realpath(__file__));
|
||||
|
||||
# help function
|
||||
# [1] Help function
|
||||
#========================================================#
|
||||
def showhelp():
|
||||
print "apt-plus 1.0.0 (amd64)";
|
||||
print "Usage: apt-plus command arguments";
|
||||
print "Usage: apt-plus install|remove|purge pkg1 [pkg2 ...]";
|
||||
print "Usage: apt-plus manifest /path/to/manifest.txt";
|
||||
print "\033[1mNAME\033[0m"
|
||||
print "\tapt-plus 1.0.0 (amd64)";
|
||||
print;
|
||||
print "apt-plus is a set of shell aliases using apt-get";
|
||||
print "in order to automate basic routines";
|
||||
print "installed packages are notices in the manifest file";
|
||||
print "(default is ~/.x-migration)";
|
||||
print "\033[1mSYNOPSIS\033[0m"
|
||||
print "\tapt-plus <command> <packages>";
|
||||
print;
|
||||
print "List of commands:";
|
||||
print " update - Upgrades packages and kernel and cleans after";
|
||||
print " install - Installs packages and notice it in the manifest";
|
||||
print " remove - Removes packages and notice it in the manifest";
|
||||
print " purge - Purges packages and notice it in the manifest";
|
||||
print " manifest - To set the manifest file";
|
||||
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-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;
|
||||
|
||||
|
||||
# If at least 1 arg given
|
||||
# [2] Command dispatch (if at least 1 arg)
|
||||
#========================================================#
|
||||
if ( len(sys.argv) > 1 ):
|
||||
|
||||
command=sys.argv[1];
|
||||
# (1) Get the command argument (first) #
|
||||
command = sys.argv[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 "updated"
|
||||
if ( command == "update" ):
|
||||
ossystem("sh %s/update;" % path);
|
||||
elif ( command == "install" ):
|
||||
# if package/s given
|
||||
if ( len(sys.argv) < 3 ):
|
||||
sys.exit("Missing argument : package names");
|
||||
|
||||
sys.exit("\n(!) Missing argument <deb_file>");
|
||||
|
||||
ossystem("/usr/bin/env python %s/command/debinstall %s" % (path, sys.argv[2]) );
|
||||
|
||||
# (4) --install, -i
|
||||
#--------------------------------------------------------#
|
||||
elif ( command == "-i" or command == "--install" ):
|
||||
|
||||
# if package/s given
|
||||
if ( len(sys.argv) < 3 ):
|
||||
sys.exit("\n(!) Missing argument <packages>");
|
||||
|
||||
packages = " ".join(sys.argv[2:]);
|
||||
|
||||
ossystem( "python %s/install %s" % (path, packages) );
|
||||
elif ( command == "remove" ):
|
||||
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(sys.argv) < 3 ):
|
||||
sys.exit("Missing argument : package names");
|
||||
|
||||
sys.exit("\n(!) Missing argument <packages>");
|
||||
|
||||
packages = " ".join(sys.argv[2:]);
|
||||
ossystem( "python %s/remove %s" % (path, packages) );
|
||||
elif ( command == "purge" ):
|
||||
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(sys.argv) < 3 ):
|
||||
sys.exit("Missing argument : package names");
|
||||
|
||||
sys.exit("\n(!) Missing argument <packages>");
|
||||
|
||||
packages = " ".join(sys.argv[2:]);
|
||||
ossystem( "python %s/purge %s" % (path, packages) );
|
||||
|
||||
elif ( command == "manifest" ):
|
||||
# if package/s given
|
||||
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(sys.argv) < 3 ):
|
||||
sys.exit("Missing argument : manifest file");
|
||||
sys.exit("\n(!) Missing argument <manifest_file>");
|
||||
|
||||
# (2) If argument is not a valid file -> abort #
|
||||
elif ( not ospath.isfile(sys.argv[2]) ):
|
||||
sys.exit("Given path isn't a file");
|
||||
|
||||
# (3) Store absolute path in ./manifest file #
|
||||
file = ospath.realpath(sys.argv[2]);
|
||||
with open( ("%s/manifest" % path), "w") as f:
|
||||
f.write(file);
|
||||
|
||||
# (8) If no match -> show help message
|
||||
#--------------------------------------------------------#
|
||||
else:
|
||||
showhelp();
|
||||
# if missing 1 arg
|
||||
|
||||
|
||||
# [3] If not enough arguments -> show help message
|
||||
#========================================================#
|
||||
else:
|
||||
showhelp();
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
Selecting previously unselected package gitkraken.
|
||||
(Reading database ... 323395 files and directories currently installed.)
|
||||
Preparing to unpack gitkraken-amd64.deb ...
|
||||
Unpacking gitkraken (2.5.0) ...
|
||||
Setting up gitkraken (2.5.0) ...
|
||||
Processing triggers for desktop-file-utils (0.22-1ubuntu5.1) ...
|
||||
Processing triggers for bamfdaemon (0.5.3~bzr0+16.04.20160824-0ubuntu1) ...
|
||||
Rebuilding /usr/share/applications/bamf-2.index...
|
||||
Processing triggers for gnome-menus (3.13.3-6ubuntu3.1) ...
|
||||
Processing triggers for mime-support (3.59ubuntu1) ...
|
Loading…
Reference in New Issue