Last active
January 4, 2018 03:43
-
-
Save gnilchee/cd442678172b17b5a8a283ce1f3c4f40 to your computer and use it in GitHub Desktop.
simple invoke script to clean and update apt-get
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from invoke import task | |
@task | |
def clean(ctx): | |
print("Cleaning!") | |
ctx.run("sudo apt-get clean all") | |
print("Cleaning Done.") | |
@task | |
def update(ctx): | |
print("Starting Update") | |
ctx.run("sudo apt-get update") | |
print("Update Complete.") | |
@task(pre=[clean, update], post=[clean]) | |
def upgrade(ctx): | |
print("Starting Upgrade!") | |
ctx.run("sudo apt-get dist-upgrade -y") | |
print("Upgrade Complete.") |
Example output:
root@ubuntu-xenial:~# inv -r /opt/invoke --no-dedupe upgrade
Cleaning!
Cleaning Done.
Starting Update
Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
Hit:2 http://archive.ubuntu.com/ubuntu xenial InRelease
Get:3 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
Get:4 http://archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]
Fetched 306 kB in 1s (174 kB/s)
Reading package lists...
Update Complete.
Starting Upgrade!
Reading package lists...
Building dependency tree...
Reading state information...
Calculating upgrade...
The following NEW packages will be installed:
libdrm-common linux-headers-4.4.0-104 linux-headers-4.4.0-104-generic
linux-image-4.4.0-104-generic
The following packages will be upgraded:
libdrm2 linux-headers-generic linux-headers-virtual linux-image-virtual
linux-virtual
5 upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
Need to get 32.7 MB of archives.
After this operation, 145 MB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libdrm-common all 2.4.83-1~16.04.1 [4,870 B]
Get:2 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libdrm2 amd64 2.4.83-1~16.04.1 [30.4 kB]
Get:3 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 linux-headers-4.4.0-104 all 4.4.0-104.127 [9,927 kB]
Get:4 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 linux-headers-4.4.0-104-generic amd64 4.4.0-104.127 [786 kB]
Get:5 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 linux-image-4.4.0-104-generic amd64 4.4.0-104.127 [21.9 MB]
Get:6 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 linux-virtual amd64 4.4.0.104.109 [1,786 B]
Get:7 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 linux-image-virtual amd64 4.4.0.104.109 [2,292 B]
Get:8 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 linux-headers-virtual amd64 4.4.0.104.109 [1,760 B]
Get:9 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 linux-headers-generic amd64 4.4.0.104.109 [2,284 B]
Fetched 32.7 MB in 9s (3,567 kB/s)
Selecting previously unselected package libdrm-common.
(Reading database ... 59475 files and directories currently installed.)
Preparing to unpack .../libdrm-common_2.4.83-1~16.04.1_all.deb ...
Unpacking libdrm-common (2.4.83-1~16.04.1) ...
Preparing to unpack .../libdrm2_2.4.83-1~16.04.1_amd64.deb ...
Unpacking libdrm2:amd64 (2.4.83-1~16.04.1) over (2.4.76-1~ubuntu16.04.1) ...
Selecting previously unselected package linux-headers-4.4.0-104.
Preparing to unpack .../linux-headers-4.4.0-104_4.4.0-104.127_all.deb ...
Unpacking linux-headers-4.4.0-104 (4.4.0-104.127) ...
Selecting previously unselected package linux-headers-4.4.0-104-generic.
Preparing to unpack .../linux-headers-4.4.0-104-generic_4.4.0-104.127_amd64.deb ...
Unpacking linux-headers-4.4.0-104-generic (4.4.0-104.127) ...
Selecting previously unselected package linux-image-4.4.0-104-generic.
Preparing to unpack .../linux-image-4.4.0-104-generic_4.4.0-104.127_amd64.deb ...
Done.
Unpacking linux-image-4.4.0-104-generic (4.4.0-104.127) ...
Preparing to unpack .../linux-virtual_4.4.0.104.109_amd64.deb ...
Unpacking linux-virtual (4.4.0.104.109) over (4.4.0.97.102) ...
Preparing to unpack .../linux-image-virtual_4.4.0.104.109_amd64.deb ...
Unpacking linux-image-virtual (4.4.0.104.109) over (4.4.0.97.102) ...
Preparing to unpack .../linux-headers-virtual_4.4.0.104.109_amd64.deb ...
Unpacking linux-headers-virtual (4.4.0.104.109) over (4.4.0.97.102) ...
Preparing to unpack .../linux-headers-generic_4.4.0.104.109_amd64.deb ...
Unpacking linux-headers-generic (4.4.0.104.109) over (4.4.0.97.102) ...
Processing triggers for libc-bin (2.23-0ubuntu9) ...
Setting up libdrm-common (2.4.83-1~16.04.1) ...
Setting up libdrm2:amd64 (2.4.83-1~16.04.1) ...
Setting up linux-headers-4.4.0-104 (4.4.0-104.127) ...
Setting up linux-headers-4.4.0-104-generic (4.4.0-104.127) ...
Setting up linux-image-4.4.0-104-generic (4.4.0-104.127) ...
Running depmod.
update-initramfs: deferring update (hook will be called later)
Examining /etc/kernel/postinst.d.
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-104-generic /boot/vmlinuz-4.4.0-104-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-104-generic /boot/vmlinuz-4.4.0-104-generic
update-initramfs: Generating /boot/initrd.img-4.4.0-104-generic
W: mdadm: /etc/mdadm/mdadm.conf defines no arrays.
run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 4.4.0-104-generic /boot/vmlinuz-4.4.0-104-generic
run-parts: executing /etc/kernel/postinst.d/update-notifier 4.4.0-104-generic /boot/vmlinuz-4.4.0-104-generic
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 4.4.0-104-generic /boot/vmlinuz-4.4.0-104-generic
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.4.0-104-generic
Found initrd image: /boot/initrd.img-4.4.0-104-generic
Found linux image: /boot/vmlinuz-4.4.0-97-generic
Found initrd image: /boot/initrd.img-4.4.0-97-generic
done
Setting up linux-image-virtual (4.4.0.104.109) ...
Setting up linux-headers-generic (4.4.0.104.109) ...
Setting up linux-headers-virtual (4.4.0.104.109) ...
Setting up linux-virtual (4.4.0.104.109) ...
Processing triggers for libc-bin (2.23-0ubuntu9) ...
Upgrade Complete.
Cleaning!
Cleaning Done.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
execution outside of cwd for tasks.py