apt-get top-level
This commit is contained in:
commit
de37686a7b
|
@ -0,0 +1,55 @@
|
|||
#!/bin/py
|
||||
|
||||
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.realpath(__file__));
|
||||
|
||||
# [2] get packages
|
||||
packages = sysargv[1:];
|
||||
|
||||
# [3] search for manifest file
|
||||
manifest="";
|
||||
with open( "%s/manifest" % path, 'r' ) as f:
|
||||
manifest=f.readline();
|
||||
|
||||
# [4] search for non-installed entries in manifest
|
||||
alrdy = [];
|
||||
with open(manifest, 'r+') as f:
|
||||
for line in f:
|
||||
m = re.search(r"\s*\[[\. ]\] ([a-zA-Z0-9_-]+)", 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";
|
||||
installed.append( pkg );
|
||||
else:
|
||||
print "\033[38;5;161merror\033[0m";
|
||||
|
||||
|
||||
# [6] update manifest
|
||||
for pkg in installed:
|
||||
print "\033[38;5;39m[notifying](%d/%d) %s\033[0m" % (installed.index(pkg)+1, len(installed), pkg);
|
||||
|
||||
# if new package
|
||||
if( not pkg in alrdy ):
|
||||
with open(manifest, "a") as f:
|
||||
f.write(" [x] %s\n" % pkg);
|
||||
else:
|
||||
with open(manifest, 'r') as reader:
|
||||
replaced = reader.read().replace("[ ] %s" % pkg, "[x] %s" % pkg).replace("[.] %s" % pkg, "[x] %s" % pkg);
|
||||
|
||||
with open(manifest, 'w') as writer:
|
||||
writer.write( replaced );
|
|
@ -0,0 +1,81 @@
|
|||
#!/bin/py
|
||||
|
||||
|
||||
###########
|
||||
# IMPORTS #
|
||||
###########
|
||||
from os import path as ospath;
|
||||
from os import system as ossystem;
|
||||
import sys;
|
||||
|
||||
|
||||
# get absolute path
|
||||
path = ospath.dirname(ospath.realpath(__file__));
|
||||
|
||||
# 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;
|
||||
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;
|
||||
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;
|
||||
|
||||
|
||||
# If at least 1 arg given
|
||||
if ( len(sys.argv) > 1 ):
|
||||
|
||||
command=sys.argv[1];
|
||||
|
||||
# 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");
|
||||
|
||||
packages = " ".join(sys.argv[2:]);
|
||||
|
||||
ossystem( "python %s/install %s" % (path, packages) );
|
||||
elif ( command == "remove" ):
|
||||
# if package/s given
|
||||
if ( len(sys.argv) < 3 ):
|
||||
sys.exit("Missing argument : package names");
|
||||
|
||||
packages = " ".join(sys.argv[2:]);
|
||||
ossystem( "python %s/remove %s" % (path, packages) );
|
||||
elif ( command == "purge" ):
|
||||
# if package/s given
|
||||
if ( len(sys.argv) < 3 ):
|
||||
sys.exit("Missing argument : package names");
|
||||
|
||||
packages = " ".join(sys.argv[2:]);
|
||||
ossystem( "python %s/purge %s" % (path, packages) );
|
||||
|
||||
elif ( command == "manifest" ):
|
||||
# if package/s given
|
||||
if ( len(sys.argv) < 3 ):
|
||||
sys.exit("Missing argument : manifest file");
|
||||
elif ( not ospath.isfile(sys.argv[2]) ):
|
||||
sys.exit("Given path isn't a file");
|
||||
|
||||
file = ospath.realpath(sys.argv[2]);
|
||||
with open( ("%s/manifest" % path), "w") as f:
|
||||
f.write(file);
|
||||
else:
|
||||
showhelp();
|
||||
# if missing 1 arg
|
||||
else:
|
||||
showhelp();
|
|
@ -0,0 +1,55 @@
|
|||
#!/bin/py
|
||||
|
||||
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.realpath(__file__));
|
||||
|
||||
# [2] get packages
|
||||
packages = sysargv[1:];
|
||||
|
||||
# [3] search for manifest file
|
||||
manifest="";
|
||||
with open( "%s/manifest" % path, 'r' ) as f:
|
||||
manifest=f.readline();
|
||||
|
||||
# [4] search for installed entries in manifest
|
||||
alrdy = [];
|
||||
with open(manifest, 'r+') as f:
|
||||
for line in f:
|
||||
m = re.search(r"\s*\[x\] ([a-zA-Z0-9_-]+)", line);
|
||||
if ( m != None ):
|
||||
alrdy.append( m.group(1) ) ;
|
||||
|
||||
# [5] Purge packages
|
||||
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";
|
||||
purged.append( pkg );
|
||||
else:
|
||||
print "\033[38;5;161merror\033[0m";
|
||||
|
||||
|
||||
# [6] update manifest
|
||||
for pkg in purged:
|
||||
print "\033[38;5;39m[notifying](%d/%d) %s\033[0m" % (purged.index(pkg)+1, len(purged), pkg);
|
||||
|
||||
# if new package
|
||||
if( not pkg in alrdy ):
|
||||
with open(manifest, "a") as f:
|
||||
f.write(" [ ] %s\n" % pkg);
|
||||
else:
|
||||
with open(manifest, 'r') as reader:
|
||||
replaced = reader.read().replace("[x] %s" % pkg, "[ ] %s" % pkg);
|
||||
|
||||
with open(manifest, 'w') as writer:
|
||||
writer.write( replaced );
|
|
@ -0,0 +1,55 @@
|
|||
#!/bin/py
|
||||
|
||||
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.realpath(__file__));
|
||||
|
||||
# [2] get packages
|
||||
packages = sysargv[1:];
|
||||
|
||||
# [3] search for manifest file
|
||||
manifest="";
|
||||
with open( "%s/manifest" % path, 'r' ) as f:
|
||||
manifest=f.readline();
|
||||
|
||||
# [4] search for installed entries in manifest
|
||||
alrdy = [];
|
||||
with open(manifest, 'r+') as f:
|
||||
for line in f:
|
||||
m = re.search(r"\s*\[x\] ([a-zA-Z0-9_-]+)", line);
|
||||
if ( m != None ):
|
||||
alrdy.append( m.group(1) ) ;
|
||||
|
||||
# [5] Remove packages
|
||||
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";
|
||||
removed.append( pkg );
|
||||
else:
|
||||
print "\033[38;5;161merror\033[0m";
|
||||
|
||||
|
||||
# [6] update manifest
|
||||
for pkg in removed:
|
||||
print "\033[38;5;39m[notifying](%d/%d) %s\033[0m" % (removed.index(pkg)+1, len(removed), pkg);
|
||||
|
||||
# if new package
|
||||
if( not pkg in alrdy ):
|
||||
with open(manifest, "a") as f:
|
||||
f.write(" [.] %s\n" % pkg);
|
||||
else:
|
||||
with open(manifest, 'r') as reader:
|
||||
replaced = reader.read().replace("[x] %s" % pkg, "[.] %s" % pkg);
|
||||
|
||||
with open(manifest, 'w') as writer:
|
||||
writer.write( replaced );
|
|
@ -0,0 +1,28 @@
|
|||
#!/bin/sh
|
||||
|
||||
success_f(){
|
||||
echo "\033[38;5;78mSUCCESS\033[31;0m";
|
||||
}
|
||||
|
||||
abort_f(){
|
||||
echo "\033[38;5;161mABORTING\033[31;0m";
|
||||
exit;
|
||||
}
|
||||
|
||||
# Update sources list
|
||||
echo "\033[38;5;208m[1/4] UPDATING THE LIST OF PACKAGES\033[31;0m";
|
||||
sudo apt-get update && success_f || abort_f;
|
||||
|
||||
# Upgrade found packages
|
||||
echo "\033[38;5;208m[2/4] UPGRADING PACKAGES\033[31;0m";
|
||||
sudo apt-get upgrade && success_f || abort_f;
|
||||
|
||||
# Upgrade kernel
|
||||
echo "\033[38;5;208m[3/4] UPGRADING KERNEL\033[31;0m";
|
||||
sudo apt-get dist-upgrade && success_f || abort_f;
|
||||
|
||||
# Remove unused dependencies
|
||||
echo "\033[38;5;208m[4/4] CLEANING\033[31;0m";
|
||||
sudo apt-get autoremove;
|
||||
sudo apt-get autoclean;
|
||||
success_f;
|
Loading…
Reference in New Issue