Skip to content

Commit

Permalink
Merge pull request #9 from Serede/master
Browse files Browse the repository at this point in the history
Refactored and simplified for consistency
  • Loading branch information
DerekTBrown committed Mar 12, 2018
2 parents bcd85b0 + 6f7372d commit 7e8bc82
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 175 deletions.
26 changes: 12 additions & 14 deletions .SRCINFO
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
pkgbase = pacmanity
pkgdesc = Saves the list of packages installed via pacman and yaourt to your Github gist
pkgver = 0.1
pkgrel = 1
url = https://github.com/DerekTBrown/pacmanity
arch = x86_64
arch = i686
license = GPL
makedepends = git
depends = pacman>=5.0
depends = gist-git>=4.5.0
source = pacmanity::git+https://github.com/DerekTBrown/pacmanity.git
md5sums = SKIP

pkgname = pacmanity

pkgdesc = Keeps a list of installed packages in a Gist at your GitHub account
pkgver = 3.0
pkgrel = 1
url = https://github.com/DerekTBrown/pacmanity
arch = x86_64
arch = i686
license = GPL
makedepends = git
depends = pacman>=5.0
depends = gist>=4.5.0
source = pacmanity::git+https://github.com/DerekTBrown/pacmanity.git
md5sums = SKIP
23 changes: 10 additions & 13 deletions PKGBUILD
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
pkgname=pacmanity
pkgver=0.1
pkgver=3.0
pkgrel=1
pkgdesc="Saves the list of packages installed via pacman and yaourt to your Github gist"
url="https://github.com/DerekTBrown/pacmanity"
pkgdesc="Keeps a list of installed packages in a Gist at your GitHub account"
url="https://github.com/DerekTBrown/$pkgname"
arch=('x86_64' 'i686')
license=('GPL')
depends=('pacman>=5.0' 'gist-git>=4.5.0')
makedepends=('git')
source=("$pkgname::git+https://github.com/DerekTBrown/pacmanity.git")
depends=('pacman>=5.0' 'gist>=4.5.0')
source=("$pkgname::git+https://github.com/DerekTBrown/$pkgname.git")
md5sums=('SKIP')

package() {

# Install and save file
mkdir -p $pkgdir/etc/
touch $pkgdir/etc/pacmanity
touch $pkgdir/etc/pacmanity_aur

# Install script
mkdir -p $pkgdir/usr/lib/pacmanity
cp $srcdir/pacmanity/src/pacmanity.sh $pkgdir/usr/lib/pacmanity/pacmanity.sh
cp $srcdir/pacmanity.sh $pkgdir/usr/lib/pacmanity/pacmanity.sh
chmod +x $pkgdir/usr/lib/pacmanity/pacmanity.sh
cp $srcdir/pacmanity/src/pacmanity_aur.sh $pkgdir/usr/lib/pacmanity/pacmanity_aur.sh
chmod +x $pkgdir/usr/lib/pacmanity/pacmanity_aur.sh

# Install Hook
mkdir -p $pkgdir/usr/share/libalpm/hooks
cp $srcdir/pacmanity/src/pacmanity.hook $pkgdir/usr/share/libalpm/hooks/pacmanity.hook
cp $srcdir/pacmanity/src/pacmanity_aur.hook $pkgdir/usr/share/libalpm/hooks/pacmanity_aur.hook
cp $srcdir/pacmanity.hook $pkgdir/usr/share/libalpm/hooks/zzz-pacmanity.hook

source $pkgdir/usr/lib/pacmanity/pacmanity.sh; pacmanity_install;
source $pkgdir/usr/lib/pacmanity/pacmanity_aur.sh; pacmanity_aur_install;
source $pkgdir/usr/lib/pacmanity/pacmanity.sh
pacmanity_install

}
79 changes: 43 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,68 +1,75 @@
# Pacmanity
List of packages installed via pacman and yaourt on your Arch machine automatically saved to GitHub.
Keeps a list of installed packages in a Gist at your GitHub account.

## Installation

**1) Downloading and installing:**
**1. Download and install:**

- using yaourt [Aur](https://aur.archlinux.org/packages/pacmanity/)
```
$ yaourt pacmanity
```
- using makepkg
- From [AUR](https://aur.archlinux.org/packages/pacmanity/) using an AUR helper:
```bash
$ <aur_helper> -S pacmanity
```
Some popular AUR helpers are [`yaourt`](https://github.com/archlinuxfr/yaourt), [`trizen`](https://github.com/trizen/trizen) and [`yay`](https://github.com/Jguer/yay).

- From [AUR](https://aur.archlinux.org/packages/pacmanity/) using `makepkg`:
```bash
$ wget https://github.com/derektbrown/pacmanity/tarball/master -O - | tar xz
$ cd DerekTBrown-pacmanity-*/
$ makepkg -si
```

navigate to the downloaded directory (derektbrown-pacmanity-xxxxxx):
**2. Setup:**

```
$ makepkg
$ sudo pacman -U
```

**2) Setup stage:**
On the installation stage you will be prompted to fill in GitHub credentials two times;
1) first time it is needed to create gist for pacman-installed packages on GItHub;
2) second time gist with AUR-installed packages should be set up, that is why the login details should be filled in once again
During the installation of the package you will be prompted to log in to your GitHub account.


## Usage

Every time you install or remove a package using [official Arch repository](https://www.archlinux.org/packages/) or unofficial [AUR](https://aur.archlinux.org/) all the changes will be saved privately to your GitHub account.
You have nothing to do, just install the pacmanity, and that's all.
Two hooks will be created and run everytime the pacman command is used.
Once installed, Pacmanity automatically maintains a list of your installed packages in a private Gist at your GitHub account.

The list gets updated every time you install, update or remove packages, keeping track of the current explicitly installed packages from both Arch [official repos](https://www.archlinux.org/packages/) and [AUR](https://aur.archlinux.org/). They are listed in the Gist in that particular order (official, then AUR), separated by a blank line.

### recovery
No hassle: just install Pacmanity, follow the prompts and you are done.
A pacman hook will be installed and conveniently run when needed to.

By cloning the gist files to your fresh installed machine you can import them into pacman rather easy;
## Recovery

By cloning the Gist file to your fresh Arch installation you can easily bulk-install them:

![gist-clone](https://image.prntscr.com/image/ObTqDXicRk6a9h7alSIVMw.png)

* pacman package list:
```bash
$ git clone [email protected]:<gist_repo>.git
$ cd <gist_repo>
```

- Using `pacman` to install only official packages:

```bash
$ git clone [email protected]:#############.git
$ cd #############
$ sudo pacman -S - < $(hostname).pacman
$ sed -e '/^$/q' $(hostname).pacmanity | sudo pacman -S -
```

* AUR package list:
- Using an AUR helper to install all packages:

```bash
$ git clone [email protected]:#############.git
$ cd #############
$ xargs <$(hostname).yaourt pacaur -S --noedit
$ <aur_helper> -S $(tr '\n' ' ' < $(hostname).pacmanity)
```

**Screenshots:**
Navigate to your Gist GitHub account here and you will see:
- list of packages installed with 'pacman -S' command:
- Using an AUR helper to install only AUR packages:

```bash
$ <aur_helper> -S $(sed -e '/^$/d' $(hostname).pacmanity | tr '\n' ' ')
```

## Screenshots

Navigate to your [Gist](https://gist.github.com) in GitHub and you will find:
- List of currently installed packages from official repos:
![pacman](http:https://image.prntscr.com/image/cf15521e7b794acdb37b2a8bc5e4455c.png)
- list of packages installed from AUR with yaourt:
- List of currently installed packages from AUR:
![AUR](http:https://image.prntscr.com/image/d5bb89e7020d4b18a236d94adf3eb32f.png)
- every installation will be automatically added to the gist:
- Every package installation will be automatically added to the Gist:
![after_installation](http:https://image.prntscr.com/image/65eeb152529e4b1dbab78de777074679.png)
- every removal also will be mentioned on the list:
- Every package removal will also be reported in the Gist:
![after_removal](http:https://image.prntscr.com/image/3d945ff4d17e460a99dd1382cfb8689d.png)

1 change: 0 additions & 1 deletion src/pacmanity
Submodule pacmanity deleted from 8d6b5a
5 changes: 3 additions & 2 deletions src/pacmanity.hook
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Pacmanity
# Saves a copy of package list to gist after each update.
# Keeps a list of installed packages in a Gist at your GitHub account.

[Trigger]
Operation = Install
Expand All @@ -9,6 +9,7 @@ Type = Package
Target = *

[Action]
Description = plist-gist
Description = Running Pacmanity hook...
Depends = coreutils
When = PostTransaction
Exec = /usr/lib/pacmanity/pacmanity.sh
85 changes: 43 additions & 42 deletions src/pacmanity.sh
Original file line number Diff line number Diff line change
@@ -1,51 +1,52 @@
#!/bin/bash
#
# pacmanity generates a list of packages installed via pacman GitHub
# Pacmanity
# Keeps a list of installed packages in a Gist at your GitHub account.

pacmanity(){
# Add Ruby to PATH
PATH="$(ruby -e 'print Gem.user_dir')/bin:$PATH"

# Load Config
[[ -r '/etc/pacmanity' ]] && source $pkgdir/etc/pacmanity
pacmanity_install(){
echo "A list of installed packages will be automatically maintained"
echo "by Pacmanity in a private Gist at your GitHub account."

echo -e "\n- Step 1: Log in to Gist using your GitHub account:"
[[ -f ~/.gist ]] || gist --login
mkdir -p $pkgdir/root
cp -v ~/.gist $pkgdir/root/.gist

echo -e "\n- Step 2: Save list of currently installed packages to Gist:"
GIST_URL=$(
(
pacman -Qqen
echo
pacman -Qqem
) | gist -p -f $HOSTNAME.pacmanity -d "$HOSTNAME: List of installed packages"
)

echo "GIST_ID=$GIST_URL" | sed 's/https:\/\/gist.github.com\///g' >> $pkgdir/etc/pacmanity

echo "An automatically mantained list of installed packages"
echo "has been successfully created in your GitHub Gist."
echo "Visit https://gist.github.com or the direct link below:"
echo "$GIST_URL"
}

# Determine if Fresh Install is Needed
if [ -z "$GIST_ID" ]; then
echo -e "\nInfo: Gist backup for pacman-installed apps not setup."
echo -e "\nYou need to use your GitHub credentials to log into GitHub Gist."
pacmanity_update(){
if (pacman -Qqen; echo; pacman -Qqem) | gist -u "$GIST_ID" -f $HOSTNAME.pacmanity; then
echo "Pacmanity: Gist successfully updated."
else
pacmanity_update;
echo "Pacmanity: ERROR! Try running"
echo "sudo gist --login"
fi
}

pacmanity_install(){
echo -e "\nApps installed via 'pacman -S' command will be"
echo -e "saved to the first package list privately to your GitHub Account.";

echo -e "\nStep 1: Login to Gist GitHub";
gist --login;
mkdir -p $pkgdir/root;
cp ~/.gist $pkgdir/root/.gist;
# Add Ruby to PATH
PATH="$(ruby -e 'print Gem.user_dir')/bin:$PATH"

echo -e "\nStep 2: Creating list with pacman-installed apps";
GIST_URL=$(pacman -Qqen | gist -p -f $HOSTNAME.pacman -d "$HOSTNAME: Packages installed via pacman")

echo "GIST_ID=$GIST_URL" | sed 's/https:\/\/gist.github.com\///g' >> $pkgdir/etc/pacmanity;

echo -e "\nYour package list is safely backed up, and will be updated"
echo -e "automatically every time you install/remove a package using the pacman."
echo -e "You can view your backup lists at https://gist.github.com/user"
echo -e "or directly at the link below:\n";
echo "$GIST_URL";
}

pacmanity_update(){
echo -e "\nUpdating package list backup on GitHub...";
if pacman -Qqen | gist -u "$GIST_ID" -f $HOSTNAME.pacman; then
echo -e "Success!\n";
else
echo -e "An error has occured.\nTry running sudo gist --login";
fi
}
# Load config
[[ -r '/etc/pacmanity' ]] && source $pkgdir/etc/pacmanity

pacmanity
# Determine if fresh install is needed
if [ -z "$GIST_ID" ]; then
echo "Info: Gist is not set up for Pacmanity."
echo "Reinstalling Pacmanity can solve this issue."
else
pacmanity_update
fi
14 changes: 0 additions & 14 deletions src/pacmanity_aur.hook

This file was deleted.

53 changes: 0 additions & 53 deletions src/pacmanity_aur.sh

This file was deleted.

0 comments on commit 7e8bc82

Please sign in to comment.