├── doc
└── revisions.jpg
├── .gitignore
├── src
├── pug.hook
└── pug.sh
├── Makefile
└── README.md
/doc/revisions.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ventto/pug/HEAD/doc/revisions.jpg
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 |
3 | !.gitignore
4 | !Makefile
5 | !README.md
6 |
7 | !src
8 | src/*
9 | !src/pug.hook
10 | !src/pug.sh
11 |
12 | !doc/
13 | doc/*
14 | !doc/revisions.jpg
15 |
--------------------------------------------------------------------------------
/src/pug.hook:
--------------------------------------------------------------------------------
1 | [Trigger]
2 | Operation = Install
3 | Operation = Upgrade
4 | Operation = Remove
5 | Type = Package
6 | Target = *
7 |
8 | [Action]
9 | Depends = coreutils
10 | When = PostTransaction
11 | Exec = /opt/pug/pug.sh
12 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | CFGDIR = $(DESTDIR)/etc
2 | HOOKDIR = $(DESTDIR)/usr/share/libalpm/hooks
3 | BINDIR = $(DESTDIR)/opt/pug
4 |
5 | .PHONY: install
6 | install:
7 | @mkdir -p $(CFGDIR)
8 | @mkdir -p $(HOOKDIR)
9 | @mkdir -p $(BINDIR)
10 | @mkdir -p $(DESTDIR)/root
11 | @chmod 750 $(DESTDIR)/root
12 | @touch $(CFGDIR)/pug
13 | @if test -r /etc/pug.bkp; then cat /etc/pug.bkp > $(CFGDIR)/pug; fi
14 | @chmod 644 $(CFGDIR)/pug
15 | @cp src/pug.sh $(BINDIR)
16 | @chmod 755 $(BINDIR)/pug.sh
17 | @sh $(BINDIR)/pug.sh $(DESTDIR)
18 | @cp src/pug.hook $(HOOKDIR)
19 | @chmod 644 $(HOOKDIR)/pug.hook
20 |
21 | .PHONY: uninstall
22 | uninstall:
23 | $(RM) $(CFGDIR)/pug
24 | $(RM) $(HOOKDIR)/pug.hook
25 | $(RM) $(DESTDIR)/root/.gist
26 | $(RM) $(BINDIR)/pug.sh
27 |
28 | .PHONY: distclean
29 | distclean: uninstall
30 | $(RM) $(CFGDIR)/pug.bkp
31 | $(RM) $(DESTDIR)/root/.gist.bkp
32 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Pug
2 | ===
3 |
4 | [](https://github.com/Ventto/xpub/blob/master/LICENSE)
5 | [](https://github.com/defunkt/gist)
6 | [](https://aur.archlinux.org/packages/pug/)
7 |
8 | *"Pug is a ALPM-hook to automatically save installed Pacman & AUR package lists into Gist files."*
9 |
10 | Inspired by [*plist-gist*](https://github.com/DerekTBrown/plist-gist) and [*pacmanity*](https://github.com/alexchernokun/pacmanity).
11 |
12 | ## Perks
13 |
14 | * [x] **Painless**: Backup and easily restore package lists
15 | * [x] **Elegant**: Same text coloration than *pacman*
16 | * [x] **Smart**: Gist revision after each command if change
17 |
18 | 
19 |
20 | ## Requirements
21 |
22 | * *pacman* - A library-based package manager with dependency support
23 | * *gist* - Potentially the best command line gister
24 |
25 | # Installation
26 |
27 | The install process will ask your Github login to create Gist files and
28 | generate an OAuth2 access token.
29 | *pug* uses that token to update your Gists as needed.
30 |
31 | ### Stable release package (AUR)
32 |
33 | ```bash
34 | $ pacaur -S pug
35 | ```
36 |
37 | ### Git package (AUR)
38 |
39 | ```bash
40 | $ pacaur -S pug-hook-git
41 | ```
42 |
43 | ### Manually
44 |
45 | ```bash
46 | $ git clone https://github.com/Ventto/pug.git
47 | $ cd pug
48 | $ sudo make install (default: INSTALLGIST=1, gists creation)
49 | # Or Uninstall
50 | $ sudo make uninstall
51 | ```
52 |
53 | # Restore
54 |
55 | Quickly install the package lists from Gists.
56 |
57 | * Install Pacman package list:
58 |
59 | ```bash
60 | $ wget -O pacman-list.pkg [URL]
61 | $ pacman -S - < pacman-list.pkg
62 | ```
63 |
64 | * Install AUR packag list:
65 |
66 | ```bash
67 | $ wget -O aur-list.pkg [URL]
68 | $ xargs ${white} Authentification on Github..."
15 |
16 | ! gist --login && exit 1
17 |
18 | if ! cmp --silent ~/.gist "${pkgdir}/root/.gist"; then
19 | cp ~/.gist "${pkgdir}/root/.gist";
20 | fi
21 |
22 | echo "${bold}${green}==>${white} Saving installed package lists to gists..."
23 | echo "${bold}${cyan} ->${white} Creating packages lists..."
24 | echo "${bold}${cyan} ->${white} Generating gist links..."
25 |
26 | GIST_NAT=$(pacman -Qqen | gist -p -f "${PACMANFILE}" -d 'Pacman package list.')
27 | GIST_AUR=$(pacman -Qqem | gist -p -f "${AURFILE}" -d 'AUR package list.')
28 |
29 | echo "GIST_NAT=${GIST_NAT}" | \
30 | sed 's/https:\/\/gist.github.com\///g' > "${pkgdir}/etc/pug";
31 | echo "GIST_AUR=${GIST_AUR}" | \
32 | sed 's/https:\/\/gist.github.com\///g' >> "${pkgdir}/etc/pug";
33 |
34 | echo " [ ${cyan}${GIST_NAT}${white} ]"
35 | echo " [ ${cyan}${GIST_AUR}${white} ]"
36 | }
37 |
38 | pug_update() {
39 | echo "${bold}${cyan}::${white} Processing gists update...${normal}"
40 |
41 | # Force backup if updating pug
42 | if test -f /etc/pug; then
43 | cp /etc/pug /etc/pug.bkp
44 | else
45 | if test -f /etc/pug.bkp; then
46 | cp /etc/pug.bkp /etc/pug
47 | else
48 | echo "${bold}${red}::${white}/etc/pug: gist IDs file not found.${normal}"
49 | echo "${bold}${red}::${white}/etc/pug.bkp: backup file not found.${normal}"
50 | exit 1
51 | fi
52 | fi
53 | if test -f /root/.gist; then
54 | cp /root/.gist /root/.gist.bkp
55 | else
56 | if test -f /root/.gist.bkp; then
57 | cp /root/.gist.bkp /root/.gist
58 | else
59 | echo "${bold}${red}::${white}/root/.gist: token file not found.${normal}"
60 | echo "${bold}${red}::${white}/root/.gist.bkp: backup file not found.${normal}"
61 | exit 1
62 | fi
63 | fi
64 |
65 | if ! gist -r "${GIST_NAT}" > /tmp/pacman.gist; then
66 | echo "${bold}${red}::${white} Failed to read pacman gist.${normal}"
67 | exit 1
68 | fi
69 |
70 | pacman -Qqen > /tmp/pacman.list
71 | if ! diff /tmp/pacman.gist /tmp/pacman.list > /dev/null 2>&1; then
72 | if ! cat /tmp/pacman.list | gist -u "${GIST_NAT}" -f "${PACMANFILE}"; then
73 | echo "${bold}${red}::${white} Failed to update pacman gist.${normal}"
74 | exit 1
75 | fi
76 | fi
77 |
78 | if ! gist -r "${GIST_AUR}" > /tmp/aur.gist; then
79 | echo "${bold}${red}::${white} Failed to read AUR gist.${normal}"
80 | exit 1
81 | fi
82 |
83 | pacman -Qqem > /tmp/aur.list
84 | if ! diff /tmp/aur.gist /tmp/aur.list > /dev/null 2>&1; then
85 | if ! cat /tmp/aur.list | gist -u "${GIST_AUR}" -f "${AURFILE}"; then
86 | echo "${bold}${red}::${white} Failed to update AUR gist.${normal}"
87 | exit 1
88 | fi
89 | fi
90 | }
91 |
92 | pug() {
93 | PATH="$(ruby -e 'print Gem.user_dir')/bin:$PATH"
94 |
95 | if [ -n "${1}" ] && [ ! -d "${1}" ]; then
96 | echo "${bold}${red}:: ${white}${1}: package directory not found.${normal}"
97 | exit 1
98 | fi
99 |
100 | pkgdir="${1}"
101 |
102 | test -r ${pkgdir}/etc/pug && . ${pkgdir}/etc/pug
103 |
104 | # Determine if fresh install is needed
105 | if test -z "${GIST_NAT}" || test -z "${GIST_AUR}"; then
106 | echo "${bold}${cyan}::${white} Pug: fresh install is needed.${normal}"
107 | pug_install "${pkgdir}"
108 | else
109 | IS_FAKEROOT=false
110 | if echo "${LD_LIBRARY_PATH}" | grep libfakeroot > /dev/null; then
111 | IS_FAKEROOT=true
112 | fi
113 | if [ "$(id -u)" -eq 0 ] && ! ${IS_FAKEROOT}; then
114 | pug_update
115 | fi
116 | fi
117 | }
118 |
119 | pug "$@"
120 |
--------------------------------------------------------------------------------