bkp
is a simple python script that let’s you, backup all your installed
packages by creating a shellscript, json or yaml file.
Note
|
PyYaml is only needed if you plan on using the yaml output format.
|
-
python 3.X.X
-
PyYaml (optional)
Note
|
This script is meant to be modified and tweacked by the user. For this reason the only installation method is and will be manual. |
mkdir -p ~/.local/bin
curl https://raw.githubusercontent.com/saccarosium/bkp/main/bkp -o ~/.local/bin/bkp
chmod +x ~/.local/bin/bkp
I wanted to make my enviroment more easy to reproduce on other machine, mainly packages. So I’ve tryed a lot of the solutions I found online:
But none of them seemed to be a right fit to my very simple needs. I wanted something that: periodically backed up all my packages from all my available package managers and put it in something I could run everywhere without needing to install anything. Bkp does exactly this: it generetes a POSIX shellscript with all the packages installed by each individual package manager.
Note
|
You can use bkp also to automatically backup your backages to your
Ansible playbook if you use the yaml output.
|
I’ve installed the following packages with: pip, brew and gem
pip install ansible brew install neovim gh fzf gem install asciidoctor
The resulting script that bkp will generate will look something like this:
#!/bin/sh
pip install \
ansible
brew install \
neovim \
git \ # (1)
gh \
fzf
gem install \
asciidoctor
-
Will include everything that will be listed in the
Source List Command
In the script the is a global dictionary called SOURCES
and in there you can
find all the package managers:
SOURCES = {
"brew": {
"install": ["brew", "install"],
"list": ["brew", "leaves", "--installed-on-request"],
"singleCmd": True
},
"cask": {
"install": ["brew", "install", "--cask"],
"list": ["brew", "list", "--cask"],
"singleCmd": True
},
"pipx": {
"install": ["pipx", "install"],
"list": ["pipx", "list", "--short"],
"filter": lambda x: [v for i, v in enumerate(x) if i % 2 == 0],
"singleCmd": False
},
"pip": {
"install": ["pip", "install", "-u"],
"list": ["pip", "list", "--not-required", "--format", "freeze"],
"singleCmd": True
},
"gem": {
"install": ["gem", "install"],
"list": ["gem", "list", "--no-verbose", "--no-versions"],
"singleCmd": True
}
}
This dictionary follows the following schema:
"name": { # (1)
"install": [], # (2)
"list": [], # (3)
"filter": "lambda", # (4)
"singleCmd": "bool", # (5)
}
-
name of used in the dictionary doesn’t really matter
-
how you want that this package manager install software
-
command used to gather a list of installed packages. Note that this will be turned into a list with the method
.split()
. -
lambda function that is given the list of packages generated by the list cmd.
-
does the package manager support passing multiple packages in a single command call