summaryrefslogtreecommitdiffstats
path: root/update
blob: 6b0ceaec1a2728dbd83fca9c1944c8a0b4f0362c (plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#! /bin/bash
RESET="\033[0m"
RED="\033[0;31m"
CYAN="\033[0;36m"

if [ $# -lt 1 ]; then
    echo "missing passwd" && exit 1
fi
sudo -K
echo "$1" | sudo -S true &>/dev/null
if [ $? -ne 0 ]; then
    echo "wrong sudo passwd" && exit 1
fi
PASSWD=$1
shift

function run() {
    echo -e "$CYAN $1 $RESET" && $1
}

function sudo_run() {
    echo -e "$RED sudo$CYAN $1 $RESET" && sudo $1
}

function update_gem() {
    # ls -1 .gem/ruby/2.2.0/specifications/ | sed 's/-\([0-9]\+\.\)\+gemspec//' | while read gem; do gem install $gem; done
    sudo_run "rm -fr /usr/lib/ruby/gems/*"
    run "/usr/bin/gem update --no-document"
    run "/usr/bin/gem clean"
}

function update_pkgs() {
    sudo_run "pacman -Syu" || return
    sudo_run "pacman -Scc --noconfirm"
    sudo_run "rm /var/cache/pacman/pkg/*"
    run "aurget -Syu"
}

function check_etc() {
    sudo_run "find /etc -name *.pacnew"
    [ -e /etc/.git ] || return
    run "cd /etc"
    sudo_run "git status"
}

function synk() {
    [ -f ~/etc/liferea/liferea.db-* ] && rm ~/etc/liferea/liferea.db-*
    [ -f ~/.googleearth/myplaces.kml ] && cp ~/.googleearth/myplaces.kml ~/etc/googleearth
    [ -f ~/.unison/asynk.prf ] && echo -e "$RED ** unison asynk $RESET" && unison asynk.prf
}

function git_pull() {
    pushd $1 >/dev/null || return
    run "git pull --rebase" || echo -e "$RED FAILED in : $(pwd) $RESET"
    pushd
}

synk
git_pull ~/usr/git/bin
git_pull ~/usr/git/vim
update_pkgs
update_gem
check_etc

sudo -K