Compare commits

...

260 commits
0.8.1 ... main

Author SHA1 Message Date
ak95
7208cd3f26 fixed README formatting 2024-09-03 17:02:23 -07:00
ak95
e54405822f fixed readme formatting 2024-09-03 17:01:48 -07:00
ak95
74a055dfe6 modified to use a single R/W snapshot 2024-09-03 17:00:45 -07:00
Wes Barnett, PhD
d58d047d2a
Merge pull request #47 from auipga/patch-1
Fix typo
2021-10-04 10:10:42 -04:00
Wes Barnett, PhD
959bf2b102
Merge pull request #48 from kidonng/patch-1
Fix link
2021-10-04 10:10:25 -04:00
Kid
c79d73fdc0
Fix link 2021-06-04 17:31:46 +08:00
Manuel Transfeld
6423f59848
Fix typo 2021-05-30 18:34:39 +02:00
Wes Barnett
6cfaa46fff
update for sphinx change 2021-05-16 19:31:49 -04:00
Wes Barnett
759a2cc84c
update ini file location 2021-05-16 19:20:53 -04:00
Wes Barnett
6dc564314c
install ini file directly 2021-05-16 19:17:00 -04:00
Wes Barnett
fad8cd676c
Merge remote-tracking branch 'origin/main' 2021-05-09 16:58:55 -04:00
Wes Barnett
6ae4bbb810
update Makefile for new version of sphinx 2021-05-09 16:58:25 -04:00
Wes Barnett, PhD
121f744ac6
Merge pull request #46 from dotiful/patch-1
Fix typo
2021-05-09 16:52:40 -04:00
Wes Barnett
f38f7aa9e6
rename hooks, update docs on backupboot example
Closes #45.
2021-05-09 16:51:57 -04:00
Dots Util
b6cb6c0ef7
Fix typo 2021-04-29 15:38:59 +03:00
Wes Barnett
2f39f46ac0
strip newline from return of cmd 2021-04-25 12:03:45 -04:00
Wes Barnett
08af0963d2
strip \n when reading in pre-number 2021-04-25 12:01:53 -04:00
Wes Barnett
d78781f771
debugging 2021-04-25 11:58:14 -04:00
Wes Barnett
1159296a8a
update docs 2021-04-25 11:50:15 -04:00
Wes Barnett
e913d70b95
Revert "rename hook"
This reverts commit 138717d269.
2021-04-15 20:31:56 -04:00
Wes Barnett
2ab106c200
Revert "make it a posttransaction hook"
This reverts commit 9b459dc49d.
2021-04-15 20:31:48 -04:00
Wes Barnett
f4f8fd8a7f
Revert "hook cant run if removed"
This reverts commit 4ebfa0eaa6.
2021-04-15 20:31:40 -04:00
Wes Barnett, PhD
95ad2669f6
Merge pull request #43 from wesbarnett/fix/firstsnap
Fix installation error
2021-04-15 20:28:37 -04:00
Wes Barnett
4ebfa0eaa6
hook cant run if removed 2021-04-15 20:26:10 -04:00
Wes Barnett
9b459dc49d
make it a posttransaction hook 2021-04-15 20:24:33 -04:00
Wes Barnett
138717d269
rename hook 2021-04-15 20:22:55 -04:00
Wes Barnett
abb1e2beb8
rename hook 2021-04-15 20:21:54 -04:00
Wes Barnett
5271109cc4
update logging 2021-04-15 20:20:48 -04:00
Wes Barnett
ecd19a6705
update test 2021-04-15 20:14:24 -04:00
Wes Barnett
e8a8c6c096
allow file to be missing 2021-04-15 20:13:04 -04:00
Wes Barnett
98d4286157
handle missing file 2021-04-15 20:11:42 -04:00
Wes Barnett, PhD
ef889e198e
Merge pull request #42 from wesbarnett/feature/man
Don't track changes in manpage since it is generated
2021-04-15 19:37:02 -04:00
Wes Barnett
3288517395
Don't track changes in manpage since it is generated 2021-04-04 18:11:12 -04:00
Wes Barnett
ea778aa380
update docs 2021-03-28 09:00:01 -04:00
Wes Barnett
3da59ac9d3
Update docs building 2021-03-28 08:56:33 -04:00
Wes Barnett
c01ba154d0
more refactoring 2021-03-27 20:25:45 -04:00
Wes Barnett
53b5a34c18
create Prefile class 2021-03-27 19:59:16 -04:00
Wes Barnett
22751b7d95
Revert "use nametuple"
This reverts commit d81f6f1f6f.
2021-03-27 19:20:21 -04:00
Wes Barnett
38c93b1ad5
Fix ConfigProcessor 2021-03-27 19:20:07 -04:00
Wes Barnett
d81f6f1f6f
use nametuple 2021-03-27 19:05:00 -04:00
Wes Barnett
7734706157
defaults for ConfigProcessor 2021-03-26 21:29:23 -04:00
Wes Barnett
73f683533f
Create CommandParser 2021-03-26 21:22:19 -04:00
Wes Barnett
559a8d7b54
refactor 2021-03-16 19:24:05 -04:00
Wes Barnett
a2704e5eda
fix syntax error 2021-03-16 19:13:31 -04:00
Wes Barnett
2aad72fb1a
save tmpdir in var 2021-03-15 20:33:38 -04:00
Wes Barnett
ec959799b8
update manpage; add docs to Makefile 2021-03-15 08:03:23 -04:00
Wes Barnett
b65cc3d261
Allow file paths to be passed to command line 2021-03-14 20:09:07 -04:00
Wes Barnett
a455240b60
Add command line options for ini and config files 2021-03-14 18:11:13 -04:00
Wes Barnett
573559e250
refactor 2021-03-14 18:04:38 -04:00
Wes Barnett
c0224aed25
update docs 2021-03-14 17:59:56 -04:00
Wes Barnett
0636c02438
add PR template 2021-03-14 10:44:48 -04:00
Wes Barnett
c382fbdbf8
add how to build docs 2021-03-14 10:36:00 -04:00
Wes Barnett
135e5a91d0
update documentation 2021-03-14 10:01:42 -04:00
Wes Barnett
0f86de6ade
Update example config file 2021-03-14 08:38:19 -04:00
Wes Barnett
b66665a35e
more links to docs 2021-03-13 20:17:16 -05:00
Wes Barnett
c7d6f9b88c
notes on tests 2021-03-13 20:13:50 -05:00
Wes Barnett
0c6f8f769e
fix test 2021-03-13 16:10:34 -05:00
Wes Barnett
cb47d1907d
update config file 2021-03-13 16:05:58 -05:00
Wes Barnett
2428ee46ca
fix default userdata 2021-03-13 16:00:34 -05:00
Wes Barnett
da67ac9ac9
add description 2021-03-13 15:37:54 -05:00
Wes Barnett, PhD
d8c8ae9b66
Merge pull request #41 from wesbarnett/feature/important
Add a few scenarios when userdata important=yes is used, update documentation
2021-03-13 14:02:16 -05:00
Wes Barnett
1ef50ddd42
add back manpage 2021-03-13 14:01:23 -05:00
Wes Barnett
292f1713ad
update docs 2021-03-13 13:59:36 -05:00
Wes Barnett
a78e7b6d71
update docs 2021-03-13 13:58:02 -05:00
Wes Barnett
bf541e667d
update docs 2021-03-13 13:45:15 -05:00
Wes Barnett
8ca92a0bb4
Update documentation 2021-03-13 13:33:32 -05:00
Wes Barnett
7eb7081012
Link to new documentation 2021-03-13 12:57:27 -05:00
Wes Barnett
733f915ac0
add list of options 2021-03-13 12:55:27 -05:00
Wes Barnett
9ab0a7833d
Add option to pass any userdata 2021-03-13 12:43:55 -05:00
Wes Barnett
8dfba55e07
Fix missing data in pytest fixture 2021-03-13 07:28:05 -05:00
Wes Barnett
e5ea12d060
fix syntax 2021-03-13 07:18:45 -05:00
Wes Barnett
fad08ebe29
rm print 2021-03-13 07:17:24 -05:00
Wes Barnett
d81070c898
add defaults for important commands and packages 2021-03-13 07:15:18 -05:00
Wes Barnett
287c1eacac
Add options for important=yes userdata
Check if user-specified packages and user-specified commands are in
important lists and if so add userdata important=yes

Fixes #38.
2021-03-13 07:08:40 -05:00
Wes Barnett
796b0f790d
ignore built docs 2021-03-13 05:23:08 -05:00
Wes Barnett
fdda143014
update tests workflow 2021-03-13 05:22:57 -05:00
Wes Barnett
1e6629aa08
add docs to main branch 2021-03-13 05:22:44 -05:00
Wes Barnett
95dce2a22d
add badge for docs 2021-03-11 20:08:05 -05:00
Wes Barnett
081a8bf1f2
Add test to Makefile 2021-03-11 19:41:15 -05:00
Wes Barnett
651ee7402a
update README 2021-02-28 09:24:19 -05:00
Wes Barnett
eeb376a54c
use pathlib 2021-02-27 21:10:22 -05:00
Wes Barnett
edd388092f
rm debug logs 2021-02-27 21:01:07 -05:00
Wes Barnett
5b5643001a
update 2021-02-27 21:00:43 -05:00
Wes Barnett
1716654236
simplify paths with Pathlib 2021-02-27 21:00:38 -05:00
Wes Barnett
de9ef06efa
rm prefile after closed 2021-02-27 20:50:53 -05:00
Wes Barnett
630354ac30
more descriptive vars; rm prefile when done; tests 2021-02-27 20:48:45 -05:00
Wes Barnett
ca9746fd6b
don't use reserved keyword 2021-02-27 20:31:22 -05:00
Wes Barnett
bd0527e003
better arg parsing; better env var parsing 2021-02-27 20:29:37 -05:00
Wes Barnett
830f0fb084
update tests to find script 2021-02-27 09:28:44 -05:00
Wes Barnett
abdecad935
don't print command 2021-02-27 09:24:37 -05:00
Wes Barnett
0a3d49a940
move tests 2021-02-27 09:24:18 -05:00
Wes Barnett, PhD
1ccdebdcb2
Merge pull request #40 from wesbarnett/feature/oop
Feature/oop
2021-02-15 20:37:10 -05:00
Wes Barnett
7e99ee19c3
update tests, linting 2021-02-15 20:34:58 -05:00
Wes Barnett
baf8fce9c6
more tests 2021-02-15 11:55:04 -05:00
Wes Barnett
18ec7c1232
More tests 2021-02-15 11:42:07 -05:00
Wes Barnett
47ca26cdeb
Update tests 2021-02-15 08:45:04 -05:00
Wes Barnett
6be6cab827
Create SnapperCmd class 2021-02-15 08:42:03 -05:00
Wes Barnett
b44d46d6bc
rename workflow 2021-02-14 18:08:19 -05:00
Wes Barnett
1f746a22d9
Update workflow for master branch and add badge 2021-02-14 18:06:55 -05:00
Wes Barnett
bd2f9bb6e1
Update readme about configuration file 2021-02-14 17:59:18 -05:00
Wes Barnett
e6724de4c8
add note that error can be ignored on install 2021-02-14 17:57:24 -05:00
Wes Barnett
da71fe8bb8
Update manpage and comment example configuration 2021-02-14 17:56:14 -05:00
Wes Barnett
57438e11c9
Clearer error 2021-02-14 17:28:35 -05:00
Wes Barnett
0dc86a06ac
Add FileNotFoundError if file containing pre number not found 2021-02-14 17:24:36 -05:00
Wes Barnett
8ceb5ef133
Make tests verbose 2021-02-14 16:50:35 -05:00
Wes Barnett
cfd636401e
add github workflow 2021-02-14 16:49:18 -05:00
Wes Barnett
e5121d4e28
Refactor for unit tests 2021-02-14 16:41:31 -05:00
Wes Barnett
481cb47bd0
Updates, refactoring, logging 2021-02-14 15:40:43 -05:00
Wes Barnett
0aff4920b4
Add SNAP_PAC_SKIP 2021-02-14 13:55:30 -05:00
Wes Barnett
61981ab4f9
Create python version 2021-02-14 13:17:31 -05:00
Wes Barnett
1ff1f66b8d
update copyright 2021-01-30 08:30:33 -05:00
Wes Barnett, PhD
82472f513a
Merge pull request #37 from NicoHood/patch-1
Fix readme name in makefile
2021-01-30 08:29:33 -05:00
NicoHood
6e4d05a4f4
Fix readme name in makefile
Version 2.3.2 did not built because of that name change
2021-01-30 09:40:15 +01:00
Wes Barnett, PhD
2bd088c576 Update issue templates 2021-01-29 22:16:50 -05:00
Wes Barnett, PhD
6e326592c3 Update issue templates 2021-01-29 22:16:03 -05:00
Wes Barnett
0bd23edb67
typo 2021-01-29 20:55:32 -05:00
Wes Barnett
8e0268a1b2
markdown 2021-01-29 20:55:02 -05:00
Wes Barnett
8af8c526bc
Update wording on snapper filters 2021-01-29 20:51:01 -05:00
Wes Barnett, PhD
189fb58044
Merge pull request #35 from GregoryHinton/issue-34 2021-01-23 17:12:52 -05:00
Gregory Hinton
e1a4b527bc Remove LINK_MODULES and KERNEL_PACKAGE declarations 2020-11-24 02:45:54 -08:00
Wes Barnett
a2ba2aa201
Fix bash test with double brackets 2019-03-09 13:25:55 -05:00
Wes Barnett
905ed72380
Detect if PPID is empty and then ignore
Fixes #25.
2019-03-08 14:14:16 -05:00
Wes Barnett
18a26d36e8
Detect if in chroot and disable dbus
Fixes #23.
2019-03-08 14:12:53 -05:00
Wes Barnett
6e6ea87c1b
update fingerprint 2019-03-08 07:37:30 -05:00
Wes Barnett
d97065a2e4
Document pacman hook that symlinks old kernel modules
Fixes #24.
2019-03-07 17:10:10 -05:00
Wes Barnett
5dac095982
Fix env var usage in manpage
See #26.
2019-02-28 15:30:17 -05:00
Wes Barnett
1dabe290b6
Don't symlink linux kernel modules.
Fixes #22, #21, and #19.
2018-08-16 07:17:24 -04:00
Wes Barnett
39dee2be1f
Remove old module symlinks on pre snapshot
Only do this if LINK_MODULES is set to yes. This prevents old symlinks
getting in the way of other packages.

Fixes #21.
2018-08-15 20:06:35 -04:00
James Barnett
42f12d216f
update manual 2018-02-28 15:43:01 -05:00
James Barnett
24891dfce3
don't print broken symlinks 2018-02-28 15:35:26 -05:00
James Barnett
9a796f490b
add new environment variable 2018-02-06 21:22:30 -05:00
James Barnett
561551ba53
use -v to test if var is set and printf 2018-02-06 21:19:14 -05:00
James Barnett
0fb43271be
Merge branch 'maximbaz-add-snap-pac-ignore' 2018-02-06 21:17:04 -05:00
Maxim Baz
4e671baf51
Use -n, rename variable, specify exit code 0 2018-02-04 13:59:08 +01:00
Maxim Baz
8edd181ab7
Allow to occasionally skip snap-pac run 2018-02-04 13:41:24 +01:00
James Barnett
ff3bdf1e2d
really add example configuration files 2018-02-03 07:32:50 -05:00
James Barnett
a868836031
update man page to reflect example configuration files 2018-02-03 07:23:59 -05:00
James Barnett
2112224e9d
add example configuration files 2018-02-03 07:16:37 -05:00
James Barnett
da977e108c
fix manpage 2018-02-02 21:24:20 -05:00
James Barnett
dee6ff6a08
change default desc limit to 72 chars 2018-02-02 21:12:31 -05:00
James Barnett
a0d0a823f1
change default description limit 2018-02-02 21:07:19 -05:00
James Barnett
8d11628592
fix homepage url 2018-02-02 21:06:58 -05:00
James Barnett
d9ce4c5d8e
update man page to reflect #17 2018-02-01 21:04:06 -05:00
James Barnett
ca7bfe6663
List packages in post description instead of pacman command
Fixes #17.
2018-02-01 15:57:01 -05:00
James Barnett
94a78681b7
fix link modules functionality 2018-01-22 12:12:14 -05:00
James Barnett
32cba7c5a3
Merge branch 'modules' 2018-01-20 11:05:28 -05:00
James Barnett
cf160c21f5
update docs 2018-01-19 11:09:04 -05:00
James Barnett
ff5554d304
add option to link kernel modules 2018-01-19 11:06:00 -05:00
James Barnett
7bff82da28
restored package_updated 2018-01-19 11:02:12 -05:00
James Barnett
a94895c9ee
typo, reword 2018-01-19 10:57:48 -05:00
James Barnett
2a33eafc7c
rm extra space 2018-01-18 19:09:42 -05:00
James Barnett
8b738b92f5
happy new year 2018-01-18 19:08:41 -05:00
James Barnett
5db7eb1468
some cleanup 2018-01-18 19:06:37 -05:00
James Barnett
8e1cde3f01
fix setting name 2018-01-18 13:49:35 -05:00
James Barnett
d4813a7fdc
create read_config function 2018-01-18 13:47:44 -05:00
James Barnett
65fdd716e0
change PRE_POST to SNAPSHOT 2018-01-17 21:21:07 -05:00
James Barnett
f9b2c62ab7
unset vars in loop; fix PRE_POST defaults 2018-01-17 21:14:23 -05:00
James Barnett
1d02860306
update manpage 2018-01-17 21:05:35 -05:00
James Barnett
4f5ce6554a
add option to link kernel modules 2018-01-17 20:58:33 -05:00
James Barnett
a60e16f8e1
Merge branch 'master' into modules 2018-01-17 20:57:26 -05:00
James Barnett
d8ef209911
update manpage 2018-01-17 20:49:35 -05:00
James Barnett
9530dd9a1b
Merge branch 'master' of github.com:wesbarnett/snap-pac 2018-01-17 20:33:51 -05:00
James “Wes” Barnett
41919ab4ad
Merge pull request #16 from jonasc/patch-1
Read configuration values from `/etc/snap-pac`
2018-01-18 01:26:48 +00:00
James Barnett
4ec3acfee5
Source settings from /etc/snap-pac and not snapper's files 2018-01-17 18:33:32 -05:00
jonasc
c0f92f1cfb
Read configuration values from /etc/snap-pac
Test whether `/etc/snap-pac` is a readable file and then source it.
Set `DESC_LIMIT` only to the default value of `48` if it was not specified in the sourced file.
2018-01-05 15:22:44 +01:00
James Barnett
f21b4998a4 typo
Signed-off-by: James Barnett <wes@wbarnett.us>
2017-12-17 21:12:30 -05:00
James Barnett
a6e0cd3287
error tracing 2017-05-31 12:59:48 -04:00
James Barnett
1135776e93
more verbose 2017-04-20 09:28:15 -05:00
James Barnett
3a904dac0e
fix typos 2017-04-20 09:22:30 -05:00
James Barnett
311e2d9a75
remove unneeded ETC_DIR 2017-04-20 08:45:42 -05:00
James Barnett
9ebba032da
delete old broken links 2017-04-20 08:45:25 -05:00
James Barnett
e6d48a89ad
remove unused variable 2017-04-20 08:36:29 -05:00
James Barnett
6ad1c1f571
rearrange how package update is detected 2017-04-20 08:36:06 -05:00
James Barnett
76c4151814
initial commit 2017-04-20 08:04:37 -05:00
James Barnett
38c0c29605
undo change 2017-04-18 21:00:52 -05:00
James Barnett
a368582080
notes on kernel branch 2017-04-18 20:49:51 -05:00
James Barnett
7b39fb5d1b
grub file +x 2017-04-18 20:43:54 -05:00
James Barnett
2f7c44ba21
can't link modules until after 2017-04-18 20:34:53 -05:00
James Barnett
edc4e89368
debugging 2017-04-18 20:32:22 -05:00
James Barnett
3bbd2a3152
debugging 2017-04-18 20:29:27 -05:00
James Barnett
9f8816b103
bug with creating directory 2017-04-18 20:28:48 -05:00
James Barnett
a238bd40f5
mark kernel snaps as important 2017-04-18 20:26:36 -05:00
James Barnett
ce7516c681
PACMAN_KEEP_OLD_KERNELS goes in root snapper config 2017-04-18 20:20:02 -05:00
James Barnett
67a89013cd
and 2017-04-18 20:18:26 -05:00
James Barnett
f67d8dab2c
debugging 2017-04-18 20:17:21 -05:00
James Barnett
9a8e7ac65f
debugging 2017-04-18 20:14:24 -05:00
James Barnett
d5d7fe5956
debugging 2017-04-18 20:11:53 -05:00
James Barnett
bc059a3f04
move everything to post snapshot 2017-04-18 20:07:53 -05:00
James Barnett
d3d4a40992
correct etc install directory 2017-04-18 20:02:57 -05:00
James Barnett
4151fcb35c
check if kernel is updated 2017-04-18 20:00:44 -05:00
James Barnett
d92c259b70
initial commit 2017-04-18 19:51:26 -05:00
James Barnett
a2048588af
rm old manpage info 2017-03-25 07:32:06 -05:00
James Barnett
05e10dcff3
split up snapper command to catch errors 2017-03-25 07:30:32 -05:00
James Barnett
335745bd8b
update manpage 2017-03-22 18:17:34 -05:00
James Barnett
325c8f45c3
udpate docs, rm unneeded checks 2017-03-22 18:11:27 -05:00
James Barnett
a54039effe
rm warning cmd (not used); update error fmt 2017-03-21 16:11:23 -05:00
James Barnett
c41c294dba
Get parent of script call (may not be pacman)
Check for pre or post args, since no longer checking command. Update manpage.
2017-03-20 07:54:21 -05:00
James Barnett
613a1a3552
move hook 2017-02-14 13:59:39 -06:00
James Barnett
59eb91c5f8
move warning to hook 2017-02-14 13:57:09 -06:00
James Barnett
1eebf453e0
Remove redundant checks
Just check to see if pacman is running
2017-02-14 13:51:00 -06:00
James Barnett
6efd9d6fc7
Remove check for root
Snapper may not actually require it depending on how the user set it up,
and if this is run from pacman (as it should be), it will always be run
as root
2017-02-14 13:22:18 -06:00
James Barnett
923d232f8e
create set_defaults 2017-02-14 13:22:00 -06:00
James Barnett
9a8c20ce1a
Revert "no need to check for root, since permissions will be checked."
This reverts commit 39bc6ea222.
2017-02-14 13:17:17 -06:00
James Barnett
39bc6ea222
no need to check for root, since permissions will be checked. 2017-02-14 13:16:09 -06:00
James Barnett
89db1fcfe7
sourcing already tests if file exists 2017-02-14 13:13:56 -06:00
James Barnett
29be92e46a
formatting 2017-02-14 13:11:47 -06:00
James Barnett
b14f923a09
Remove test if there are no snapper configs
this is tested at the end of the script already
2017-02-14 13:09:55 -06:00
James Barnett
b5220f2a5d
revert prev change on abort on fail 2017-02-14 12:00:14 -06:00
James Barnett
eabc759750
wording 2017-02-14 11:53:58 -06:00
James Barnett
c8d14e43d5
add back exit 0 2017-02-14 11:51:37 -06:00
James Barnett
267a497f4e
fix pacman abort on fail 2017-02-14 11:49:19 -06:00
James Barnett
123e33e162
update description; use bash for globbing 2017-02-14 11:36:33 -06:00
James Barnett
83e578369d
rm of prefile can be done directly in hook 2017-02-14 11:30:18 -06:00
James Barnett
02770cffc6
prefile not defined in correct location 2017-02-14 11:28:01 -06:00
James Barnett
505d62a80d
most likely is going to be set to no 2017-02-14 11:25:47 -06:00
James Barnett
e9a5cf31af
formatting 2017-02-14 11:21:00 -06:00
James Barnett
ea299e2b8a
more refactoring 2017-02-14 11:13:36 -06:00
James Barnett
1969e5bd15
output format 2017-02-14 11:03:06 -06:00
James Barnett
591a0730c6
some cleanup 2017-02-14 11:01:19 -06:00
James Barnett
e3537fab43
put rm file in correct spot 2017-02-14 09:45:31 -06:00
James Barnett
d162241a1b
set name variable 2017-02-14 09:39:57 -06:00
James Barnett
6105acf78b
why do we need a checkmark?
The number itself tells us it was completed
2017-02-14 09:39:48 -06:00
James Barnett
2edea865b0
removal should be checked first in loop 2017-02-14 09:05:04 -06:00
James Barnett
5011637263
add truncate_description 2017-02-14 09:01:46 -06:00
James Barnett
f7bf18e85c
Code refactoring 2017-02-14 08:42:43 -06:00
James Barnett
51cee6cf6c
Check for utf8 as well as UTF-8 in LANG 2017-02-13 06:17:20 -06:00
James Barnett
d99b2a759f
update README 2017-02-07 07:41:19 -06:00
James Barnett
eee3dec43e
manpage typ 2017-02-04 08:01:34 -06:00
James Barnett
9f8918a30e
fix makefile README 2017-02-04 07:59:31 -06:00
James Barnett
83509c2fe4
update manpage 2017-02-04 07:54:13 -06:00
James Barnett
ffca5484e9
code refactoring 2017-02-04 07:11:35 -06:00
James Barnett
59ea13fd11
update manpage 2017-02-03 20:56:18 -06:00
James Barnett
b6082ceaed
update manpage 2017-02-03 20:48:02 -06:00
James Barnett
2c62cce12c
update manpage 2017-02-03 20:23:23 -06:00
James Barnett
76eff16127
update README 2017-02-03 14:08:46 -06:00
James Barnett
039c0ae70d
update README 2017-02-03 14:07:36 -06:00
James Barnett
730abde329
update README 2017-02-03 14:06:29 -06:00
James Barnett
f2a7e7b189
update README 2017-02-03 13:58:29 -06:00
James Barnett
2478a189d8
add installation method 2017-02-03 13:56:08 -06:00
James Barnett
b97cf5bf04
add man page 2017-02-03 13:54:03 -06:00
James Barnett
03792597b0
update documentation 2017-02-03 11:49:32 -06:00
James Barnett
8f10395a88
no need to list configurations that aren't being snapshotted 2017-02-03 11:45:13 -06:00
James Barnett
e6ec6a7c8f
happy (late) new year 2017-02-03 11:41:10 -06:00
James Barnett
70859e84a2
rm duplicate 2017-02-03 11:04:52 -06:00
James Barnett
b737252a4e
limit description length 2017-02-03 11:04:09 -06:00
James Barnett
5afd92ddfb
info on new warning 2017-02-03 09:44:23 -06:00
James Barnett
42b8a93292
warn if pacman was not found to be running 2017-02-03 09:41:31 -06:00
James Barnett
54df716ec1
make if logic clearer 2017-02-03 09:36:57 -06:00
James Barnett
f0ddb4ee29
update documentation 2017-02-03 09:29:38 -06:00
James Barnett
7d981ff6fd
add removal to main script 2017-02-03 08:42:43 -06:00
James Barnett
439f925abf
warning message formatting
error messge formatting
2017-02-03 08:36:20 -06:00
James Barnett
8ef411732e
use trap for error 2017-02-03 07:54:24 -06:00
James Barnett
c5b822c2dd
add description if pacman was not found to be running 2017-02-03 07:46:58 -06:00
James Barnett
ac28d14ed8
add trap for SIGTERM and SIGINT 2017-02-03 07:46:37 -06:00
James Barnett
7f1e35b20a
use printf 2017-02-03 07:41:16 -06:00
James Barnett
04bf81ab05 update documention since now in community 2016-10-31 08:02:48 -05:00
James Barnett
6594945ecf ensure UTF font is used 2016-10-03 09:09:08 -05:00
James Barnett
01d4af9e3e update 2016-09-18 20:55:58 -05:00
James Barnett
509cfb0540 typo 2016-09-11 14:52:35 -05:00
James Barnett
33d2617bbb note on pacman database being locked 2016-09-11 14:46:49 -05:00
25 changed files with 987 additions and 479 deletions

24
.github/ISSUE_TEMPLATE/bug_report.md vendored Normal file
View file

@ -0,0 +1,24 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''
---
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
**Expected behavior**
A clear and concise description of what you expected to happen.
**Additional context**
Add any other context about the problem here.

View file

@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.

3
.github/PULL_REQUEST_TEMPLATE.md vendored Normal file
View file

@ -0,0 +1,3 @@
- [ ] Closes #xxxx
- [ ] Tests added / passed
- [ ] All linting tests pass

28
.github/workflows/docs.yml vendored Normal file
View file

@ -0,0 +1,28 @@
name: Docs
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Python
uses: actions/setup-python@v1
with:
python-version: 3.9
- name: Install dependencies
run: python -m pip install --upgrade pip sphinx
- name: Build docs
run: sphinx-build -a docs/source docs/build
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/build
publish_branch: gh-pages

24
.github/workflows/tests.yml vendored Normal file
View file

@ -0,0 +1,24 @@
name: Tests
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Python
uses: actions/setup-python@v1
with:
python-version: 3.9
- name: Install dependencies
run: python -m pip install --upgrade pip pytest flake8
- name: Run linter
run: flake8 --max-line-length=120 scripts/
- name: Run tests
run: python -m pytest -v

4
.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
__pycache__
venv
docs/build
man8

View file

@ -1,6 +1,6 @@
# snap-pac
# https://github.com/wesbarnett/snap-pac
# Copyright (C) 2016 James W. Barnett
# Copyright (C) 2016-2021 James W. Barnett
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -20,9 +20,23 @@ PREFIX ?= /usr
SHARE_DIR = $(DESTDIR)$(PREFIX)/share
.PHONY: install
.PHONY: install test docs
install:
@install -Dm755 scripts/* -t $(SHARE_DIR)/libalpm/scripts/
@install -Dm644 hooks/* -t $(SHARE_DIR)/libalpm/hooks/
@install -Dm644 LICENSE -t $(SHARE_DIR)/licenses/$(PKGNAME)
install: man
@install -Dm755 scripts/snap_pac.py $(SHARE_DIR)/libalpm/scripts/snap-pac
@install -Dm644 hooks/* -t $(SHARE_DIR)/libalpm/hooks/
@install -Dm644 LICENSE -t $(SHARE_DIR)/licenses/$(PKGNAME)/
@install -Dm644 man8/* -t $(SHARE_DIR)/man/man8/
@install -Dm644 README.md -t $(SHARE_DIR)/doc/$(PKGNAME)/
@install -Dm644 extra/snap-pac.ini $(DESTDIR)/etc/snap-pac.ini
test:
@python -m pytest -v .
man:
@cd docs && make man
@mkdir -p man8
@awk 'NR==33{print ".SH DESCRIPTION"}7' docs/build/man/snap-pac.8 > man8/snap-pac.8
docs: man
@sphinx-build -a docs/source docs/build

248
README.md
View file

@ -1,253 +1,25 @@
# snap-pac
[![AUR Version](https://img.shields.io/aur/version/snap-pac.svg)](https://aur.archlinux.org/packages/snap-pac/)
[![License](https://img.shields.io/aur/license/snap-pac.svg)](https://github.com/wesbarnett/snap-pac/blob/master/LICENSE)
[![AUR Votes](https://img.shields.io/aur/votes/snap-pac.svg)](https://aur.archlinux.org/packages/snap-pac/)
## Synopsis
This causes Arch Linux's pacman to use
[snapper](https://wiki.archlinux.org/index.php/Snapper) to automatically take a
pre and post snapshot before and after pacman transactions using pacman's hooks
feature, similar to how YaST does with OpenSuse. This provides a simple way to
undo changes to a system after a pacman transaction.
This is a set of [pacman](https://wiki.archlinux.org/index.php/Pacman) hooks and scripts that automatically cause [snapper](http://snapper.io/) to perform a snapshot before pacman transactions.
* [Installation](#installation)
* [Configuration](#configuration)
* [Usage](#usage)
* [Example](#example)
* [Troubleshooting](#troubleshooting)
* [License](#license)
* [FAQ](#faq)
* [See also](#see-also)
* [Did you like this project?](#did-you-like-this-project)
Forked from Wes Barnett's solution for my own personal needs. Takes a single screenshot vs. the original's pre/post pair.
## Installation
Install [the package from the
AUR](https://aur.archlinux.org/packages/snap-pac/).
### PGP Key
I have signed the release tarball with my PGP key. You must import my public key
to verify the signature if you are using the PKGBUILD in the AUR. This can be
done via:
$ gpg --keyserver hkp://pgp.mit.edu --recv-keys 0xE4B5E45AA3B8C5C3
The key's fingerprint is `8535CEF3F3C38EE69555BF67E4B5E45AA3B8C5C3`.
## [Installation](https://wesbarnett.github.io/snap-pac/installation.html)
## Configuration
Configuration is done via the snapper configuration files, with extra variables
specific to these pacman hooks. The defaults should be suitable for most users,
so you shouldn't need to change anything.
Most likely, configuration is not needed. By default, the snapper configuration named `root` will have snapshots taken before every pacman transaction.
The following are possible settings you can place in each snapper configuration
file (*e.g.*, `/etc/snapper/configs/root`, etc.):
For more information on configuring snap-pac, see [the documentation](https://wesbarnett.github.io/snap-pac/configuration.html).
* `PACMAN_PRE_POST` - perform pacman pre/post snapshots for this configuration.
Default is `"no"` for all configurations, except for the `root` configuration
which is `"yes"`.
* `PACMAN_CLEANUP_ALGORITHM` - snapper algorithm used in cleaning up the pacman pre/post
snapshots. Default is `"number"`.
* `PACMAN_PRE_DESCRIPTION` - snapper description used for the pacman pre snapshot.
Default is the pacman command that called the snapshot.
* `PACMAN_POST_DESCRIPTION` - snapper description used for the pacman post snapshot.
Default is the pacman command that called the snapshot.
## Documentation
The following setting can be changed in the snapper configuration file
`/etc/conf.d/snapper`:
* `PACMAN_ABORT_ON_FAIL` - By default this is set to `"no"`. When set to `"yes"`
this causes pacman to abort a transaction if the snap-pac pre hook fails. This
prevents an upgrade/installation/removal from occurring if a pre snapshot cannot be
performed.
## Usage
### Taking snapshots
**Use pacman—and AUR helpers—as normal and watch snapper do its thing.** No
bash scripts for you to call. No bash aliases to setup.
Because these are pacman hooks, it doesn't matter how you call pacman—whether
directly, through an AUR helper, or using an alias—snapper will create the
snapshots when pacman installs, upgrades, or removes a package. The
pacman command used is logged in the snapper description for the
snapshots. Additionally the snapshot numbers are output to the screen and to the
pacman log for each snapper configuration during the pacman transaction.
### Undoing a transaction
To undo changes from a pacman transaction, use `snapper undochange`. See the
snapper manpage and the following example.
If you have severe breakage—like snapper is gone for some reason and you can't
get it back—you'll have to resort to more extreme methods, such as taking a
snapshot of the pre snapshot and making it the default subvolume or mounting it
as `/`. Most likely you'll need to use a live USB to get into a chroot
environment to do any of these things. Snapper has a `snapper rollback` feature,
but your setup has to be properly configured to use it. The exact procedure
depends on your specific setup. Be careful.
## Example
Installing the `nano` package as normal:
# pacman -S nano
resolving dependencies...
looking for conflicting packages...
Packages (1) nano-2.5.3-1
Total Installed Size: 2.14 MiB
:: Proceed with installation? [Y/n] Y
(1/1) checking keys in keyring [######################################] 100%
(1/1) checking package integrity [######################################] 100%
(1/1) loading package files [######################################] 100%
(1/1) checking for file conflicts [######################################] 100%
(1/1) checking available disk space [######################################] 100%
:: Running pre-transaction hooks...
(1/1) Performing snapper pre snapshots...
home N/A
root 1033 ✓
:: Processing package changes...
(1/1) installing nano [######################################] 100%
:: Running post-transaction hooks...
(1/1) Performing snapper post snapshots...
home N/A
root 1034 ✓
The snapper snapshot number is given for each snapper configuration that is
used (tip: this is also logged in pacman's log). "N/A" means that configuration
is not set up for snap-pac (see above).
And here are the snapshots:
# snapper -c root list -t pre-post | tail -n 1
1033 | 1034 | Fri 22 Apr 2016 01:54:13 PM CDT | Fri 22 Apr 2016 01:54:14 PM CDT | pacman -S nano |
What changed?
# snapper -c root status 1033..1034
+..... /etc/nanorc
c..... /etc/snapper/.snap-pac-pre
+..... /usr/bin/nano
+..... /usr/bin/rnano
+..... /usr/share/doc/nano
+..... /usr/share/doc/nano/faq.html
+..... /usr/share/doc/nano/fr
+..... /usr/share/doc/nano/fr/nano.1.html
+..... /usr/share/doc/nano/fr/nanorc.5.html
+..... /usr/share/doc/nano/fr/rnano.1.html
I truncated the above output, but it continues. See the manpage for snapper to
see what each symbol means. You can also do `snapper diff` in the same
way—I'll spare you that one.
To undo the upgrade:
# snapper -c root undochange 1033..1034
create:0 modify:3 delete:100
And `nano` is now gone, along with all the files it changed:
$ pacman -Qi nano
error: package 'nano' was not found
See the [documentation here](https://wesbarnett.github.io/snap-pac/) or `man 8 snap-pac` after installation.
## Troubleshooting
**==> ERROR: One or more PGP signatures could not be verified!**
See [PGP Key](#pgp-key) on how to import my PGP key.
**ERROR: /etc/conf.d/snapper does not exist!**
*snap-pac* reads in the snapper configurations from `/etc/conf.d/snapper`. It
can't do that if the file doesn't exist. I'm not sure what you've done to not
have it exist in the default location.
**WARNING: No snapper configurations found, so not taking any snapshots!**
No snapper configurations were found in `/etc/conf.d/snapper`. This means you
haven't created any configurations yet using `snapper create-config`. See the
snapper manpage on how to do this.
**WARNING: No snapper configurations are set up for snapshots to be taken!**
Although you seem to have created at least one snapper configuration, none of
them are set up for *snap-pac*'s pacman hooks. By default *snap-pac* will take
snapshots for the `root` configuration and any other configuration which has
`PACMAN_PRE_POST` set to `yes` in its configuration file. This message means you
don't have a snapper configuration named `root` (or `PACMAN_PRE_POST` is set to
`no` for it) and no other configuration is set up for snapshots. See the
configuration section above.
**WARNING: *prefile* does not exist, so no post snapshot will be taken. If you are initially installing snap-pac, this is normal.**
*snap-pac* saves the pre snapshot's number in a temporary file. Somehow it got
removed before the post snapshot could be taken. When you initially install
*snap-pac* the post hook is run, but the pre hook never was, so this message
will show up then as well and is safe to ignore in that circumstance.
**ERROR: Unable to use snapper without dbus. Are you in a chroot environment?**
Snapper requires dbus. If you chroot into another environment, dbus will not be
available, so snapper can't take snapshots.
**"N/A" next to one of the snapper configurations in the hook's output**
*snap-pac* lists all snapper configurations it finds and tells you which ones it
took a snapshot of along with the snapshot number. "N/A" means the configuration
is not set up for snap-pac, so no snapshot was taken for that snapper
configuration. See [configuration](#configuration).
**Other problems**
If you have a problem not listed here, check the [open
issues](https://github.com/wesbarnett/snap-pac/issues) and file new issue if
your problem is not listed.
## FAQ
**Does snap-pac backup non-btrfs `/boot` partitions?**
Nope. See
[here](https://github.com/wesbarnett/snap-pac/issues/7#issuecomment-245593818)
for an example on how to set this up.
## License
snap-pac
Copyright (C) 2016 James W. Barnett
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
## See also
* [ArchWiki Btrfs article](https://wiki.archlinux.org/index.php/Btrfs)
* [ArchWiki Snapper article](https://wiki.archlinux.org/index.php/Snapper)
* [Btrfs homepage](https://wiki.archlinux.org/index.php/Btrfs)
* [snapper homepage](http://snapper.io/)
* `man alpm-hooks`
* `man btrfs`
* `man snapper`
## Did you like this project?
If you like this project, send me a Bitcoin tip: `1PZziQoUJfhMKZC8gXQZtS5ebHWMba3Geb`
After reviewing the documentation, [check the issues page] and file a new issue if your problem is not covered.
[check the issues page]: https://codeberg.org/ak95/snap-pac/issues

20
docs/Makefile Normal file
View file

@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

35
docs/make.bat Normal file
View file

@ -0,0 +1,35 @@
@ECHO OFF
pushd %~dp0
REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build
if "%1" == "" goto help
%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end
:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
:end
popd

65
docs/source/conf.py Normal file
View file

@ -0,0 +1,65 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
# -- Project information -----------------------------------------------------
project = 'snap-pac'
copyright = '2021, Wes Barnett, PhD'
author = 'Wes Barnett, PhD'
# -- General configuration ---------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
]
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []
# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_theme_options = {
'badge_branch': 'main',
'description': 'pacman hooks that use snapper to create pre/post btrfs snapshots',
'fixed_sidebar': True,
'github_banner': True,
'github_user': 'wesbarnett',
'github_repo': 'snap-pac',
'github_type': 'star'
}
man_pages = [("index", "snap-pac", "Pacman hooks that use snapper to create pre/post btrfs snapshots like openSUSE's YaST", "Wes Barnett", "8")]
manpages_url = 'https://man.archlinux.org/man/{page}.{section}'

View file

@ -0,0 +1,99 @@
Configuration
=============
.. toctree::
:maxdepth: 2
Configuration is done via Python ini configuration files. The defaults
should be suitable for most users, so you may not need to do any configuration at all.
By default only the ``root`` snapper configuration is snapshotted.
A commented example configuration files is located at ``/etc/snap-pac.ini``.
Edit with your favorite editor. The file is commented and should be
self-explanatory.
Each section corresponds with a snapper configuration. Add additional sections to add
other snapper configurations to be snapshotted. By default, only the root configuration
is snapshotted. Additionally you can add a section named ``DEFAULT`` with options that
apply to all snapper configurations unless overridden in a later section.
Each section can have the following entries:
* ``desc_limit`` - integer; maximum length of description string before being truncated.
Default: 72
* ``important_packages`` - list of strings; names of packages that if involved in a pacman
transaction will add ``important=yes`` to the snapper userdata for the pair of
snapshots. Default: []
* ``important_commands`` - list of strings; parent commands that will add
``important=yes`` to the snapper userdata for the pair of snapshots. Default: []
* ``pre_description`` - string; description for the pre snapshot. Default: the parent
command that called the pacman hook.
* ``post_description`` - string; description for the post snapshot. Default: space
separated list of packages that were installed, upgraded, or removed.
* ``snapshot`` - boolean; whether or not to snapshot the configuration. Default: True for
``root`` configuration; False otherwise.
* ``userdata`` - list of strings; key-value pairs that will be added to the userdata for
the pair of snapshots. Default: []
Examples
--------
Turn off snapshots for ``root`` configuration and turn on for ``home`` configuration:
.. code-block:: ini
[root]
snapshot = False
[home]
snapshot = True
Set the snapper to add the userdata ``important=yes`` for every snapshot in the ``root``
configuration when a system upgrade is performed:
.. code-block:: ini
[root]
important_commands = ["pacman -Syu"]
Set the snapper to add the userdata ``important=yes`` for every snapshot in the ``root``
configuration when a pacman transaction handles the packages ``linux`` and ``linux-lts``:
.. code-block:: ini
[root]
important_packages = ["linux", "linux-lts"]
Here's a fuller example, with several options set for different configurations. In this
case the ``root`` configuration snapshot will have ``important=yes`` when ``linux`` and
``linux-lts`` packages are part of the transaction. Additionally when full system
upgrades are performed ``root`` snapshots will be marked ``important=yes``. Note that
you don't have to add ``snapshot = True`` for the ``root`` configuration since that is
the default.
This file also turns one snapshots for the ``home`` snapper configuration and adds the
userdata ``requestid=42,user=arthur`` to all snapshots for that configuration.
Additionally the post snapshot description is overridden.
.. code-block:: ini
[root]
important_packages = ["linux", "linux-lts"]
important_commands = ["pacman -Syu"]
[home]
snapshot = True
userdata = ["requestid=42", "user=arthur"]
post_description = "pacman transaction post snapshot"
Environment Variables
=====================
To temporarily prevent snapshots from being performed for a single pacman
command, set the environment variable ``SNAP_PAC_SKIP``. For example:
.. code-block:: bash
sudo SNAP_PAC_SKIP=y pacman -Syu

91
docs/source/examples.rst Normal file
View file

@ -0,0 +1,91 @@
Example
=======
.. toctree::
:maxdepth: 2
Here is an example of how the snapshots are created and how to rollback and pacman
transaction. Here the nano package is installed:
.. code-block:: bash
pacman -S nano
.. code-block:: none
resolving dependencies...
looking for conflicting packages...
Packages (1) nano-2.5.3-1
Total Installed Size: 2.14 MiB
:: Proceed with installation? [Y/n] Y
(1/1) checking keys in keyring [######################################] 100%
(1/1) checking package integrity [######################################] 100%
(1/1) loading package files [######################################] 100%
(1/1) checking for file conflicts [######################################] 100%
(1/1) checking available disk space [######################################] 100%
:: Running pre-transaction hooks...
(1/1) Performing snapper pre snapshots for the following configurations...
=> root: 1033
:: Processing package changes...
(1/1) installing nano [######################################] 100%
:: Running post-transaction hooks...
(1/1) Performing snapper post snapshots for the following configurations...
=> root: 1034
The snapper snapshot number is given for each snapper configuration that is used. This
is also logged in pacman's log.
Here are the snapshots created before and after the pacman transaction:
.. code-block:: bash
snapper -c root list -t pre-post | tail -n 1
.. code-block:: none
1033 | 1034 | Fri 22 Apr 2016 01:54:13 PM CDT | Fri 22 Apr 2016 01:54:14 PM CDT | pacman -S nano |
Here is what changed during the transaction:
.. code-block:: bash
snapper -c root status 1033..1034
.. code-block:: none
+..... /etc/nanorc
c..... /etc/snapper/.snap-pac-pre
+..... /usr/bin/nano
+..... /usr/bin/rnano
+..... /usr/share/doc/nano
+..... /usr/share/doc/nano/faq.html
+..... /usr/share/doc/nano/fr
+..... /usr/share/doc/nano/fr/nano.1.html
+..... /usr/share/doc/nano/fr/nanorc.5.html
+..... /usr/share/doc/nano/fr/rnano.1.html
The above output is truncated, but it continues. See :manpage:`snapper(8)` to for what each
symbol means. You can also do ``snapper diff`` in the same way.
Then, to undo the pacman transaction:
.. code-block:: bash
snapper -c root undochange 1033..1034
.. code-block:: none
create:0 modify:3 delete:100
Now nano is no longer installed, along with all the files it changed:
.. code-block:: bash
pacman -Qi nano
.. code-block:: none
error: package 'nano' was not found

47
docs/source/faq.rst Normal file
View file

@ -0,0 +1,47 @@
FAQ
===
.. toctree::
:maxdepth: 2
**Does snap-pac backup non-btrfs /boot partitions?**
No, but you can add a hook that does it for you. It would be something like the following:
.. code-block:: none
[Trigger]
Operation = Upgrade
Operation = Install
Operation = Remove
Type = Package
Target = linux
[Action]
Description = Backing up /boot...
When = PreTransaction
Exec = /usr/bin/rsync -avzq --delete /boot /.bootbackup
Note that you will probably want to name the file with a numbered prefix less than
``05`` so that it is run before the snap-pac pre snapshot takes place. That will ensure
that the snapshot taken will have the boot partition back-up corresponding with the
state of the system. For example, you could name it ``04-backupboot.hook``.
**How do I link old kernel modules automatically when the kernel is upgraded?**
This behavior is no longer a part of this package. Use a pacman hook like the following:
.. code-block:: none
[Trigger]
Operation = Upgrade
Operation = Install
Operation = Remove
Type = Package
Target = linux
[Action]
Description = Symlinking old kernel modules...
When = PostTransaction
Exec = /usr/bin/bash -c "find /usr/lib/modules -xtype l -delete; ln -sv /.snapshots/$(snapper -c root list | awk 'END{print $1}')/snapshot/usr/lib/modules/$(uname -r) /usr/lib/modules/"

79
docs/source/index.rst Normal file
View file

@ -0,0 +1,79 @@
.. snap-pac documentation master file, created by
sphinx-quickstart on Thu Mar 11 19:49:12 2021.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
snap-pac
========
This is a set of `pacman <https://archlinux.org/pacman/>`_ hooks and script that causes
`snapper <http://snapper.io/>`_ to automatically take a pre and post snapshot before and
after pacman transactions, similar to how `YaST <https://yast.opensuse.org/>`_ does with
OpenSuse. This provides a simple way to undo changes to a system after a pacman
transaction.
Because these are pacman hooks, it doesn't matter how you call pacman—whether
directly, through an AUR helper, or using an alias—snapper will create the snapshots
when pacman installs, upgrades, or removes a package. The pacman command used is
logged in the snapper description for the snapshots. Additionally the snapshot numbers
are output to the screen and to the pacman log for each snapper configuration during the
pacman transaction, so that the user can easily find which changes he or she may want to
revert.
.. code-block:: none
:caption: When you run pacman, the snapper pre/post snapshots are created automatically. For a fuller example see :doc:`examples`.
:emphasize-lines: 17,18,25,26
$ sudo pacman -S vim
resolving dependencies...
looking for conflicting packages...
Packages (1) vim-8.2.2489-1
Total Installed Size: 3.79 MiB
Net Upgrade Size: 0.00 MiB
:: Proceed with installation? [Y/n]
(1/1) checking keys in keyring [############] 100%
(1/1) checking package integrity [############] 100%
(1/1) loading package files [############] 100%
(1/1) checking for file conflicts [############] 100%
(1/1) checking available disk space [############] 100%
:: Running pre-transaction hooks...
(1/1) Performing snapper pre snapshots for the following configurations...
==> root: 7394
:: Processing package changes...
(1/1) installing vim [############] 100%
:: Running post-transaction hooks...
(1/4) Arming ConditionNeedsUpdate...
(2/4) Updating icon theme caches...
(3/4) Updating the desktop file MIME type cache...
(4/4) Performing snapper post snapshots for the following configurations...
==> root: 7395
To undo changes from a pacman transaction, use ``snapper undochange``. See the :manpage:`snapper(8)`
for more details as well as examples.
If you have severe breakage—like snapper is gone for some reason and you can't get it
back—you'll have to resort to more extreme methods, such as taking a snapshot of the pre
snapshot and making it the default subvolume or mounting it as /. Most likely you'll
need to use a live USB to get into a chroot environment to do any of these things.
Snapper has a ``snapper rollback`` feature, but your setup has to be properly configured to
use it. The exact procedure depends on your specific setup. Be careful.
Note that the pre transaction hooks occur before the pacman transaction but after the
pacman database is synced, if applicable. In other words, if you run `pacman -Syu` and
roll back the upgrade according to the above instructions, you will not have rolled back
the pacman database to the previous state. Thus, if, after upgrading and rolling back
the upgrade, you then install a package, it will possibly be a partial upgrade, which is
unsupported.
.. toctree::
:maxdepth: 1
installation
configuration
examples
troubleshooting
faq

View file

@ -0,0 +1,66 @@
Installation
============
Install the ``snap-pac`` package using pacman:
.. code-block:: bash
pacman -S snap-pac
Alternatively download the `latest release and signature
<https://github.com/wesbarnett/snap-pac/releases>`_. Then, verify the download:
.. code-block:: bash
gpg --verify snap-pac-<version>.tar.gz.sig
where ``<version>`` is the version number you downloaded.
Finally, run:
.. code-block:: bash
make install
I have signed the release tarball and commits with my PGP key. Starting with release
2.2, the tarballs are signed with my key with fingerprint
``F7B28C61944FE30DABEEB0B01070BCC98C18BD66``.
For previous releases, the key's fingerprint was
``8535CEF3F3C38EE69555BF67E4B5E45AA3B8C5C3``.
Dependencies
------------
``python``, ``pacman``, and ``snapper`` are all required.
Testing
-------
For testing, ``pytest`` is required. To run the tests do:
.. code-block:: bash
make test
Documentation
-------------
Typically, you will not need to build the documentation on your own and can simply
access it by visiting the `online documentation
<https://wesbarnett.github.io/snap-pac/>`_ or by accessing the manpage:
.. code-block:: bash
man 8 snap-pac
To build the documentation, ``sphinx`` is required. To build the documentation you can
do:
.. code-block:: bash
make docs
The resulting html documentation will then be located at ``docs/build/index.html``.
Additionally, this generates the manpage which will be located under ``man8``.

View file

@ -0,0 +1,23 @@
Troubleshooting
===============
.. toctree::
:maxdepth: 2
**snap-pac is only taking snapshots of the root configuration.**
That's the default behavior. See :doc:`configuration`.
**No snapshots are being taken when I run pacman.**
No snapper configurations are set up for snap-pac's pacman hooks. By default snap-pac
will take snapshots for the root configuration and any other configuration which has
SNAPSHOT set to yes in its configuration file. See :doc:`configuration`.
**After restoring snapshot from snap-pac, the pacman database is locked.**
The pre/post snaphots are taken while pacman is running, so this is expected. Follow
the instructions pacman gives you (*e.g.*, removing the lock file). You can add the
database lock file to a snapper filter so that snapper won't consider it when
performing snapper diff, snapper status, snapper undochange, etc. See the Filters
section in :manpage:`snapper(8)` for more information.

38
extra/snap-pac.ini Normal file
View file

@ -0,0 +1,38 @@
# snap-pac example configuration file
# see snap-pac(8) for more details
# Each section corresponds with a snapper configuration. Add additional sections to add
# other configurations to be snapshotted. By default, only the root configuration is snapshotted.
# Create a section named [DEFAULT] to have a setting apply for all snapper configurations
## Uncomment to set parameters for snapper configuration named root
#[root]
## How many characters to limit the description for snapper.
## Default is 72
#desc_limit = 72
## Whether or not to take snapshots of this snapper configuration
## Default is True for root configuration and False for all other configurations
#snapshot = True
## What snapper cleanup algorithm to use
## Default is number
#cleanup_algorithm = number
## Uncomment to add "important=yes" to userdata for snapshots referring to these packages
## Default is []
#important_packages = ["linux", "linux-lts"]
## Uncomment to add "important=yes" to userdata for snapshots that were created with the following commands
## Default is []
#important_commands = ["pacman -Syu"]
## Add custom userdata. Each key-value pair should be an item in the list
## Default is []
#userdata = ["key=value","foo=bar"]
## Example for another snapper configuration named "home"
# [home]
## Default is False
# snapshot = True

View file

@ -1,6 +1,6 @@
# snap-pac
# https://github.com/wesbarnett/snap-pac
# Copyright (C) 2016 James W. Barnett
# Copyright (C) 2016, 2017, 2018 James W. Barnett
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -24,8 +24,9 @@ Type = Package
Target = *
[Action]
Description = Performing snapper pre snapshots...
Description = Taking snapper snapshot before installing...
Depends = snap-pac
When = PreTransaction
Exec = /usr/share/libalpm/scripts/snap-pac pre
AbortOnFail
Exec = /usr/share/libalpm/scripts/snap-pac
NeedsTargets
AbortOnFail

View file

@ -1,6 +1,6 @@
# snap-pac
# https://github.com/wesbarnett/snap-pac
# Copyright (C) 2016 James W. Barnett
# Copyright (C) 2016, 2017, 2018 James W. Barnett
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -22,7 +22,7 @@ Type = Package
Target = snap-pac
[Action]
Description = NOTE: You are removing snap-pac. No post transaction snapshots will be taken.
Description = You are removing snap-pac. No post transaction snapshots will be taken.
Depends = snap-pac
When = PreTransaction
Exec = /usr/share/libalpm/scripts/snap-pac-remove
Exec = /usr/bin/bash -c "rm -f /tmp/snap-pac-pre_*"

View file

@ -1,30 +0,0 @@
# snap-pac
# https://github.com/wesbarnett/snap-pac
# Copyright (C) 2016 James W. Barnett
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
[Trigger]
Operation = Upgrade
Operation = Install
Operation = Remove
Type = Package
Target = *
[Action]
Description = Performing snapper post snapshots...
Depends = snap-pac
When = PostTransaction
Exec = /usr/share/libalpm/scripts/snap-pac post

View file

@ -1,149 +0,0 @@
#!/bin/bash
# snap-pac
# https://github.com/wesbarnett/snap-pac
# Copyright (C) 2016 James W. Barnett
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# Main script.
set -e
SNAPPER_CONFIG_FILE=/etc/conf.d/snapper
ERRORMSG=" \033[00;31mERROR:\033[00m"
WARNINGMSG=" \033[00;33mWARNING:\033[00m"
PACMAN_ABORT_ON_FAIL="no"
# Virtual console fonts don't have the unicode checkmark
if [[ "$TERM" == "linux" ]]; then
checkmark="done"
else
checkmark="✓"
fi
if [[ -f "$SNAPPER_CONFIG_FILE" ]]; then
source "$SNAPPER_CONFIG_FILE"
else
echo -e "$ERRORMSG $SNAPPER_CONFIG_FILE does not exist!"
exit 1
fi
if [[ $EUID -ne 0 ]]; then
echo -e "$ERRORMSG Script must be run as root."
if [[ $PACMAN_ABORT_ON_FAIL == "yes" ]]; then
exit 1
else
exit 0
fi
fi
if [[ ! -d /var/run/dbus ]]; then
echo -e "$ERRORMSG Unable to use snapper without dbus. Are you in a chroot environment?"
if [[ $PACMAN_ABORT_ON_FAIL == "yes" ]]; then
exit 1
else
exit 0
fi
fi
if [[ $# -ne 1 ]]; then
echo -e "$ERRORMSG Only one argument should be passed to this script."
if [[ $PACMAN_ABORT_ON_FAIL == "yes" ]]; then
exit 1
else
exit 0
fi
fi
if [[ $1 != "pre" ]] && [[ $1 != "post" ]]; then
echo -e "$ERRORMSG First argument should either be 'pre' or 'post'."
if [[ $PACMAN_ABORT_ON_FAIL == "yes" ]]; then
exit 1
else
exit 0
fi
fi
if [[ -z "$SNAPPER_CONFIGS" ]]; then
echo -e "$ERRORMSG No snapper configurations found, so not taking any snapshots!"
if [[ $PACMAN_ABORT_ON_FAIL == "yes" ]]; then
exit 1
else
exit 0
fi
fi
declare -r pre_or_post=$1
declare pacman_cmd
pacman_cmd="$(sed 's./usr/bin/pacman.pacman.g' <(ps -C pacman -o args=))"
declare -i x=0
for CONFIG in $SNAPPER_CONFIGS; do
# Set defaults
PACMAN_PRE_POST="no"
if [[ $CONFIG == "root" ]]; then
PACMAN_PRE_POST="yes"
fi
PACMAN_PRE_DESCRIPTION="$pacman_cmd"
PACMAN_POST_DESCRIPTION="$pacman_cmd"
PACMAN_CLEANUP_ALGORITHM="number"
# Source snapper configuration to override defaults
source /etc/snapper/configs/"$CONFIG"
echo -n " $CONFIG "
if [[ $PACMAN_PRE_POST == "yes" ]]; then
prefile="/tmp/snap-pac-pre_$CONFIG"
snapper_cmd="snapper --config $CONFIG create --type $pre_or_post --cleanup-algorithm $PACMAN_CLEANUP_ALGORITHM"
x=$((x+1))
if [[ "$pre_or_post" == "pre" ]]; then
$snapper_cmd --description "$PACMAN_PRE_DESCRIPTION" --print-number > "$prefile"
echo -n "$(< "$prefile") "
echo "$checkmark"
elif [[ -f $prefile ]]; then
postnum=$($snapper_cmd --description "$PACMAN_POST_DESCRIPTION" --print-number --pre-number "$(< "$prefile")")
echo -n "$postnum "
echo "$checkmark"
rm "$prefile"
else
echo -e "$WARNINGMSG $prefile does not exist, so no post snapshot will be taken. If you are initially installing snap-pac, this is normal."
fi
else
echo "N/A"
fi
done
if [[ $x -eq 0 ]]; then
echo -e "$ERRORMSG No snapper configurations are set up for snapshots to be taken!"
if [[ $PACMAN_ABORT_ON_FAIL == "yes" ]]; then
exit 1
else
exit 0
fi
fi
exit 0

View file

@ -1,49 +0,0 @@
#!/bin/bash
# snap-pac
# https://github.com/wesbarnett/snap-pac
# Copyright (C) 2016 James W. Barnett
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# Removes file that stores pre number when snap-pac is removed.
set -e
SNAPPER_CONFIG_FILE=/etc/conf.d/snapper
ERRORMSG="\033[00;31mERROR:\033[00m"
if [[ $EUID -ne 0 ]]; then
echo -e "$ERRORMSG Script must be run as root."
exit 1
fi
if [[ -f "$SNAPPER_CONFIG_FILE" ]]; then
source "$SNAPPER_CONFIG_FILE"
else
exit 1
fi
for CONFIG in $SNAPPER_CONFIGS; do
prefile="/tmp/snap-pac-pre_$CONFIG"
if [[ -f "$prefile" ]]; then
rm "$prefile"
fi
done
exit 0

161
scripts/snap_pac.py Executable file
View file

@ -0,0 +1,161 @@
#!/usr/bin/env python
# Copyright (C) 2021 Wes Barnett
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
"""Script for taking snapshots; run from pacman hooks."""
from argparse import ArgumentParser
from configparser import ConfigParser
import json
import logging
from pathlib import Path
import os
import sys
import tempfile
logging.basicConfig(format="%(message)s", level=logging.INFO)
class SnapperCmd:
def __init__(self, config, cleanup_algorithm, description="", nodbus=False, userdata=""):
self.cmd = ["snapper"]
if nodbus:
self.cmd.append("--no-dbus")
self.cmd.extend([
f"--config {config} create",
f"--cleanup-algorithm {cleanup_algorithm}",
"--print-number"
])
self.cmd.append("--read-write")
if description:
self.cmd.append(f"--description \"{description}\"")
if userdata:
self.cmd.append(f"--userdata \"{userdata}\"")
def __call__(self):
return os.popen(self.__str__()).read().rstrip("\n")
def __str__(self):
return " ".join(self.cmd)
class ConfigProcessor:
def __init__(self, ini_file, parent_cmd=None, packages=None):
"""Set up defaults for snap-pac configuration."""
if parent_cmd is None:
self.parent_cmd = os.popen(f"ps -p {os.getppid()} -o args=").read().strip()
else:
self.parent_cmd = parent_cmd
if packages is None:
self.packages = [line.rstrip("\n") for line in sys.stdin]
else:
self.packages = packages
self.config = ConfigParser()
self.config["DEFAULT"] = {
"snapshot": False,
"cleanup_algorithm": "number",
"description": self.parent_cmd,
"desc_limit": 72,
"important_packages": [],
"important_commands": [],
"userdata": []
}
self.config["root"] = {
"snapshot": True
}
self.config.read(ini_file)
def get_cleanup_algorithm(self, section):
return self.config.get(section, "cleanup_algorithm")
def get_description(self, section):
desc_limit = self.config.getint(section, "desc_limit")
return self.config.get(section, "description")[:desc_limit]
def check_important_commands(self, section):
return self.parent_cmd in json.loads(self.config.get(section, "important_commands"))
def check_important_packages(self, section):
important_packages = json.loads(self.config.get(section, "important_packages"))
return any(x in important_packages for x in self.packages)
def check_important(self, section):
return (self.check_important_commands(section) or
self.check_important_packages(section))
def get_userdata(self, section):
userdata = set(json.loads(self.config.get(section, "userdata")))
if self.check_important(section):
userdata.add("important=yes")
return ",".join(sorted(list(userdata)))
def __call__(self, section):
if section not in self.config:
self.config.add_section(section)
return {
"description": self.get_description(section),
"cleanup_algorithm": self.get_cleanup_algorithm(section),
"userdata": self.get_userdata(section),
"snapshot": self.config.getboolean(section, "snapshot")
}
def get_snapper_configs(conf_file):
"""Get the snapper configurations."""
for line in conf_file.read_text().split("\n"):
if line.startswith("SNAPPER_CONFIGS"):
line = line.rstrip("\n").rstrip("\"").split("=")
return line[1].lstrip("\"").split()
def check_skip():
return os.getenv("SNAP_PAC_SKIP", "n").lower() in ["y", "yes", "true", "1"]
def parse_args():
parser = ArgumentParser(description="Script for taking snapper snapshots. Used with pacman hooks.")
parser.add_argument(
"--ini", dest="snap_pac_ini", type=Path,
default=Path("/etc/snap-pac.ini"), help="snap-pac ini file path"
)
parser.add_argument(
"--conf", dest="snapper_conf_file", type=Path,
default=Path("/etc/conf.d/snapper"), help="snapper configuration file path"
)
return parser.parse_args()
if __name__ == "__main__":
if check_skip():
logging.warning("snapper snapshots skipped")
quit()
args = parse_args()
config_processor = ConfigProcessor(args.snap_pac_ini)
chroot = os.stat("/") != os.stat("/proc/1/root/.")
for snapper_config in get_snapper_configs(args.snapper_conf_file):
data = config_processor(snapper_config)
if data["snapshot"]:
num = SnapperCmd(snapper_config, data["cleanup_algorithm"], data["description"], chroot, data["userdata"])()
logging.info(f"==> {snapper_config}: {num}")

122
tests/test_script.py Normal file
View file

@ -0,0 +1,122 @@
import tempfile
from pathlib import Path
import os
import pytest
from scripts.snap_pac import check_skip, ConfigProcessor, get_snapper_configs, Prefile, SnapperCmd
@pytest.mark.parametrize("snapper_cmd, actual_cmd", [
(
SnapperCmd("root", "pre", "number", "foo"),
"snapper --config root create --cleanup-algorithm number --print-number --description \"foo\" --type pre"
),
(
SnapperCmd("root", "post", "number", "bar", False, 1234),
"snapper --config root create --cleanup-algorithm number --print-number"
" --description \"bar\" --pre-number 1234 --type post"
),
(
SnapperCmd("root", "post", "number", "bar", True, 1234),
"snapper --no-dbus --config root create --cleanup-algorithm number --print-number"
" --description \"bar\" --pre-number 1234 --type post"
),
(
SnapperCmd("root", "post", "number", "bar", False, 1234, "important=yes"),
"snapper --config root create --cleanup-algorithm number --print-number"
" --description \"bar\" --userdata \"important=yes\" --pre-number 1234 --type post"
),
(
SnapperCmd("root", "post", "number", "bar", False, 1234, "foo=bar,important=yes"),
"snapper --config root create --cleanup-algorithm number --print-number"
" --description \"bar\" --userdata \"foo=bar,important=yes\" --pre-number 1234 --type post"
),
(
SnapperCmd("root", "post", "number", "bar", False, None, "foo=bar,important=yes"),
"snapper --config root create --cleanup-algorithm number --print-number"
" --description \"bar\" --userdata \"foo=bar,important=yes\" --type single"
)
])
def test_snapper_cmd(snapper_cmd, actual_cmd):
assert str(snapper_cmd) == actual_cmd
def test_get_snapper_configs():
with tempfile.NamedTemporaryFile("w", delete=False) as f:
f.write("## Path: System/Snapper\n")
f.write("\n")
f.write("## Type: string\n")
f.write("## Default: \"\"\n")
f.write("# List of snapper configurations.\n")
f.write("SNAPPER_CONFIGS=\"home root foo bar\"\n")
name = f.name
assert get_snapper_configs(Path(name)) == ["home", "root", "foo", "bar"]
def test_skip_snap_pac():
os.environ["SNAP_PAC_SKIP"] = "y"
assert check_skip() is True
@pytest.mark.parametrize("section, command, packages, snapshot_type, result", [
(
"root", "foo", ["bar"], "pre",
{"description": "foo", "cleanup_algorithm": "number", "userdata": "", "snapshot": True}
),
(
"root", "pacman -Syu", [], "pre",
{"description": "pacman -Syu", "cleanup_algorithm": "number", "userdata": "important=yes", "snapshot": True}
),
(
"mail", "pacman -Syu", [], "pre",
{"description": "pacman -Syu", "cleanup_algorithm": "number", "userdata": "", "snapshot": False}
),
(
"home", "pacman -Syu", [], "pre",
{"description": "pac", "cleanup_algorithm": "number", "userdata": "foo=bar,requestid=42", "snapshot": True}
),
(
"home", "pacman -Syu", [], "post",
{"description": "a r", "cleanup_algorithm": "number", "userdata": "foo=bar,requestid=42", "snapshot": True}
),
(
"myconfig", "pacman -S linux", ["linux"], "post",
{"description": "linux", "cleanup_algorithm": "timeline",
"userdata": "foo=bar,important=yes,requestid=42", "snapshot": True}
),
])
def test_config_processor(section, command, packages, snapshot_type, result):
with tempfile.NamedTemporaryFile("w", delete=False) as f:
f.write("[root]\n")
f.write("important_commands = [\"pacman -Syu\"]\n\n")
f.write("[home]\n")
f.write("snapshot = True\n")
f.write("desc_limit = 3\n")
f.write("post_description = a really long description\n")
f.write("userdata = [\"foo=bar\", \"requestid=42\"]\n\n")
f.write("[myconfig]\n")
f.write("snapshot = True\n")
f.write("cleanup_algorithm = timeline\n")
f.write("important_packages = [\"linux\", \"linux-lts\"]\n")
f.write("userdata = [\"foo=bar\", \"requestid=42\"]\n")
name = f.name
config_processor = ConfigProcessor(name, snapshot_type, command, packages)
assert config_processor(section) == result
def test_prefile_read_none():
prefile = Prefile("root", "pre")
assert prefile.read() is None
def test_prefile_read():
prefile = Prefile("root", "pre")
prefile.write("1234")
prefile = Prefile("root", "post")
assert prefile.read() == "1234"
def test_no_prefile():
prefile = Prefile("foo-pre-file-not-found", "post")
assert prefile.read() is None