summaryrefslogtreecommitdiffstats
path: root/update
blob: c38db826fa14b56d1467fe41556be1d8240a4ede (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#! /bin/bash
RESET="\033[0m"
RED="\033[0;31m"
CYAN="\033[0;36m"

ssh-add -l | grep -q 'no identities' && ssh-add $(ls ~/.ssh/*.pub | sed 's/\.pub.*//g' | tr '\n' ' ')

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() {
    # cd .gem/ruby/X.Y.0/specifications/ && ls -1 *.gemspec | 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"
    if [ $(hostname) = "HMSA0065N" -a $(ls -l $GEM_HOME/cache/*.gem 2>/dev/null | wc -l) -gt 0 ]
    then
        for gem in $GEM_HOME/cache/*.gem; do gem inabox $gem ; done
        rm $GEM_HOME/cache/*.gem 2>/dev/null
    fi
}

function update_pkgs() {
    sudo_run "pacman -Scc --noconfirm"
    sudo_run "pacman -Syu" || return
    sudo_run "rm /var/cache/pacman/pkg/*"
    run "find .cache/aurman/ -type d -delete"
    run "aurman -Sc --noconfirm"
    run "aurman -Syu"
}

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

function info() {
    echo
    uname -a
    dmesg --level=err,warn -T
    echo
}

function synk() {
    [ -f ~/.unison/asynk.prf ] && echo -e "$RED ** unison asynk $RESET" && unison asynk.prf
}

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

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

sudo -K