-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·99 lines (78 loc) · 2.18 KB
/
install.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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#! /bin/sh
#
# zshrc - personal implementation of zsh's run configuration file
#
# Copyright (c) 2018-2019 Filippo Ranza <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
REPO_PATH="$(pwd)/zshrc"
REPO_VERS=$(sha512sum "$REPO_PATH" | awk '{print $1}')
REPO_SIZE=$(stat -c '%s' "$REPO_PATH")
# get file onwer and group
get_owner(){
stat -c '%U:%G' $1
}
check_install(){
#if the files have different size they can't be equal
[[ "$REPO_SIZE" == $(stat -c '%s' "$1/.zshrc") ]] || return '1'
USER_VERS=$(sha512sum "$1/.zshrc" | awk '{print $1}')
if [[ "$REPO_VERS" == "$USER_VERS" ]]; then
OUT=0
echo "$(stat -c '%U' $1) already has installed the last version"
else
OUT=1
fi
return "$OUT"
}
install(){
check_install "$1" && return
if [[ $2 ]] ; then
ln -s "$REPO_PATH" "$1/.zshrc"
else
cp "$REPO_PATH" "$1/.zshrc"
fi
# reset .zshrc owner.
chown "$(get_owner $1)" "$1/.zshrc"
}
zsh_user(){
cat '/etc/passwd' |
perl -aln -F: -e 'print $F[5] if $F[6] =~ /zsh/'
}
# install .zshrc in every home directory
auto_install(){
for d in $(zsh_user); do
install "$d" "$1"
done
}
AUTO=''
SOFT=''
while [[ $1 ]]; do
# the values doesn't metter,
# the only important thing
# is that the variable is not
# empty
case $1 in
'auto') AUTO='auto'
;;
'soft') SOFT='soft'
;;
*) echo "unknown option $1"
esac
shift
done
if [[ "$AUTO" ]] ; then
auto_install "$SOFT"
else
install "$HOME" "$SOFT"
fi