forked from arttaylor/archlinux-homepc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup.sh
executable file
·48 lines (43 loc) · 1.43 KB
/
backup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
GIT_LOCATION=$HOME/git/archlinux-homepc
GITHUB_USR=interskh
# backup packages
# @see https://wiki.archlinux.org/index.php/Pacman_Tips#Backing_up_and_retrieving_a_list_of_installed_packages
# @param GITHUB_USR optional, the user name of github.com. If empty, only local backup
function backup_archlinux_packages_list() {
mkdir -p $GIT_LOCATION
comm -23 <(pacman -Qeq|sort) <(pacman -Qmq|sort) > $GIT_LOCATION/pkglist.txt
if [ ! -e $GIT_LOCATION/README.org ]; then
echo "* My ArchLinux packages list " > $GIT_LOCATION/README.org
fi
local GIT=`/usr/bin/which git`
if [ "${GIT}x" = "x" ]; then
echo Git not found! You need to install git first.
return 0
fi
cd $GIT_LOCATION
if [ ! -d $GIT_LOCATION/.git ]; then
#first import
$GIT init
$GIT add $GIT_LOCATION/pkglist.txt $GIT_LOCATION/README*
$GIT commit -m 'first import'
if [ ! "${GITHUB_USR}x" = "x" ]; then
$GIT remote add origin "[email protected]:${GITHUB_USR}/archlinux-${HOSTNAME}.git"
$GIT push -u origin master
fi
else
# normal commit
local gd=`${GIT} diff .`
if [ ! "${gd}x" == "x" ]; then
# only add files already under track
$GIT add -u .
$GIT commit -m `date +%H%M%S-%Y-%m-%d`
if [ "${GITHUB_USR}" != "" ]; then
$GIT push origin master
fi
fi
fi
cd $HOME
return 0
}
backup_archlinux_packages_list