-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·198 lines (182 loc) · 4.24 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·198 lines (182 loc) · 4.24 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/usr/bin/env bash
Color_off='\033[0m'
Cyan='\033[0;36m'
Blue='\033[0;34m'
Red='\033[0;31m'
PRE=.orig
GITUSER='hcaijin'
LOCKFILE=$PWD/dotfiles.lock
[ $EUID != 0 ] && SUDO=sudo
if type apt >/dev/null 2>&1; then
installpkg(){ ${SUDO} apt-get install -y "$@" >/dev/null 2>&1; }
elif type pkg >/dev/null 2>&1; then
installpkg(){ ${SUDO} pkg install -y "$@" >/dev/null 2>&1; }
elif type yum >/dev/null 2>&1; then
installpkg(){ ${SUDO} yum install -y "$@" >/dev/null 2>&1; }
else
installpkg(){ ${SUDO} pacman --noconfirm --needed -S "$@" >/dev/null 2>&1 ;}
fi
USAGE () {
echo "Usage:"
echo " bash install.sh [options...] <arg>"
echo "Options:"
echo " -g Get the public key from GitHub, the arguments is the GitHub ID, default my github id (hcaijin)"
echo " -p Change sshd listen port"
echo " -P The sshd key password, default null"
echo " -f Force links installed file"
echo " -d Uninstall and Delete links"
echo " -h Show usage"
}
delink () {
FILE=$HOME/.$1
OLDLINK=$FILE$PRE
if [ -e "$FILE" ]
then
if file $FILE | grep $PWD &> /dev/null;then
rm -r "$FILE"
# mv $FILE $OLDLINK
printf "Removed File $Blue$FILE${Color_off}\n"
if [ -e "$OLDLINK" ]; then
printf "Restore $Cyan$OLDLINK${Color_off} -> $Blue$FILE${Color_off}\n"
mv $OLDLINK $FILE
fi
else
printf "Skipping $Red$FILE${Color_off}\n"
fi
else
printf "None File $Red$FILE${Color_off}\n"
fi
}
doUninstall() {
if [ ! -e "$LOCKFILE" ]
then
echo "Nothing to do!! Please check you lock exit!"
exit
fi
for file in `cat $LOCKFILE | sort -n | uniq`;
do
delink $file
done
rm $LOCKFILE
}
# Symlinks the configs
symlink () {
grep "$1" $LOCKFILE 2>/dev/null
if [ $? != 0 ]
then
echo $1 >> $LOCKFILE
fi
TARGET=$PWD/$2$1
FILE=$HOME/.$1
if [ -e "$FILE" ]
then
if file $FILE | grep $PWD &> /dev/null;then
printf "Installed $Red$FILE${Color_off}\n"
else
if [[ $FORCE -eq 1 ]]; then
mv -f "$FILE" "$FILE$PRE"
ln -sf "$TARGET" "$FILE"
printf "Linking $Cyan$FILE${Color_off} -> $Blue$TARGET${Color_off}\n"
else
printf "Skipping $Red$FILE${Color_off}\n"
fi
fi
else
printf "Linking $Cyan$FILE${Color_off} -> $Blue$TARGET${Color_off}\n"
ln -s "$TARGET" "$FILE"
fi
}
linkHiddenFile() {
for file in `ls hiddenrc`;
do
symlink $file hiddenrc/
done
}
linkFolder() {
for file in `ls $1 | egrep -v '^(etc)'`;
do
symlink $1/$file
done
}
doLink() {
# mkdir
if [ ! -d "$HOME/.config" ];then
mkdir ~/.config
fi
if [ ! -d "$HOME/.local/bin" ];then
mkdir -p ~/.local/bin
fi
# mail
if [ ! -f ~/.msmtprc ];
then
#cp msmtprc ~/.msmtprc
printf "copy ${red}msmtprc to ~/.msmtprc ${color_off}\n"
printf "you need to run chmod 0600 ~/.msmtprc after edit password\n"
fi
# Install folder to config or local
linkFolder config
linkFolder local/bin
linkFolder local/share
# Install hidden file to ~
linkHiddenFile
}
domain() {
echo "do install depandens pkg"
installpkg wget curl vim zsh keychain
doLink
# Pull github ssh pub key
[ -z ${PASSWD} ] || PASSWD_STR=" -P $PASSWD"
[ -z ${PORT} ] || PORT_STR=" -p $PORT"
[ -f "$HOME/.ssh/id_ecdsa" ] || sh <(curl -Ls https://raw.githubusercontent.com/hcaijin/SSH_Key_Installer/master/ikey.sh)${PASSWD_STR}${PORT_STR} -g $GITUSER -d
[ -z "`echo $SHELL | grep 'zsh'`" ] && chsh -s `which zsh`
}
doEditSystem() {
# https://wiki.archlinux.org/index.php/Security
sudo sed -i 's/# deny.*/deny = 50/g' /etc/security/faillock.conf
# https://wiki.archlinux.org/index.php/Systemd/Journal#Clean_journal_files_manually
sudo sed -i 's/#SystemMaxUse=.*/SystemMaxUse=200M/g' /etc/systemd/journald.conf
}
doHasopt() {
while getopts "P:p:g:hfd" OPT; do
case $OPT in
P)
PASSWD=$OPTARG
;;
p)
PORT=$OPTARG
;;
g)
GITUSER=$OPTARG
;;
f)
FORCE=1
;;
d)
doUninstall
exit
;;
h)
USAGE
exit -1
;;
?)
USAGE
exit -1
;;
:)
USAGE
exit -1
;;
esac
done
}
main() {
[ $# -lt 1 ] && {
domain
exit 0
}
doHasopt $*
domain
doEditSystem
}
main $*