Skip to content

Instantly share code, notes, and snippets.

@ansemjo
Last active May 10, 2023 09:51
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ansemjo/89fbaf1e58f79673b45a488ca098d3ae to your computer and use it in GitHub Desktop.
Save ansemjo/89fbaf1e58f79673b45a488ca098d3ae to your computer and use it in GitHub Desktop.
Clean up unwanted packages on a fresh installation of Ubuntu 20.04 LTS
#!/usr/bin/env bash
set -eu
# mark a few packages as explicitly installed
mark-wanted() {
apt install -y \
bash git tmux vim htop \
unattended-upgrades \
software-properties-common;
}
# install ansemjo/dotfiles
install-dotfiles() {
dot=/usr/local/etc/dotfiles;
if [[ ! -d $dot ]]; then
git clone "https://github.com/ansemjo/dotfiles" "$dot";
bash "$dot/install.sh" -bgtv;
fi;
}
# remove unwanted packages and purge leftover configuration
purge-unwanted() {
apt autoremove --purge -y \
snapd lxd-agent-loader ufw command-not-found \
apport alsa-ucm-conf alsa-topology-conf byobu \
cloud-init cloud-guest-utils cloud-initramfs-copymods cloud-initramfs-dyn-netconf \
landscape-common motd-news-config pollinate popularity-contest ubuntu-advantage-tools \
open-iscsi multipath-tools accountsservice cryptsetup-initramfs open-vm-tools;
rm -rvf \
/root/snap \
/etc/pollinate \
/etc/cloud \
/var/lib/cloud \
/var/lib/command-not-found;
}
# install virtualization packages
install-virtualization() {
add-apt-repository -y ppa:jacob/virtualisation;
apt install -y qemu-kvm libvirt-daemon-system libvirt-clients virtinst;
}
# install firewalld
install-firewalld() {
apt install -y firewalld;
}
# ---------------
mark-wanted
purge-unwanted
#install-virtualization
install-firewalld
install-dotfiles
#!/usr/bin/env ansible-playbook
# setup a clean ubuntu machine
---
- hosts: localhost
gather_facts: false
become: false
vars:
dotfiles:
repo: https://github.com/ansemjo/dotfiles
dest: /usr/local/etc/dotfiles
packages:
wanted: [
bash, git, tmux, vim, htop, zstd, firewalld, rsync,
software-properties-common, unattended-upgrades,
]
additional: [
borgbackup, rclone, nginx, certbot,
]
purge: [
snapd, lxd-agent-loader, ufw, command-not-found,
apport, alsa-ucm-conf, alsa-topology-conf, byobu,
cloud-init, cloud-guest-utils, cloud-initramfs-copymods, cloud-initramfs-dyn-netconf,
landscape-common, motd-news-config, pollinate, popularity-contest, ubuntu-advantage-tools,
open-iscsi, multipath-tools, accountsservice,
]
leftovers: [
/root/snap, /etc/pollinate, /etc/cloud, /var/lib/cloud, /var/lib/command-not-found,
]
identity:
path: ~/.ssh/id_ed25519
type: ed25519
tasks:
- name: wanted packages are installed
apt:
state: present
update_cache: true
cache_valid_time: 3600
name: "{{ packages.wanted }}"
- name: additional packages are installed
apt:
state: present
name: "{{ packages.additional }}"
- name: unwanted packages are purged
apt:
state: absent
autoremove: true
purge: true
name: "{{ packages.purge }}"
- name: leftover directories are removed
file:
state: absent
path: "{{ item }}"
loop: "{{ packages.leftovers }}"
- name: all packages are updated
apt:
state: latest
name: "*"
- name: dotfiles are cloned
git:
repo: "{{ dotfiles.repo }}"
dest: "{{ dotfiles.dest }}"
update: true
force: true
- name: dotfiles are installed
shell: "bash '{{ dotfiles.dest }}/install.sh' -bgtv"
- name: ssh identity is created
shell:
cmd: "ssh-keygen -t {{ identity.type }} -f {{ identity.path | expanduser }} -N ''"
creates: "{{ identity.path | expanduser }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment