forked from VPSDance/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbashrc.sh
71 lines (62 loc) · 1.71 KB
/
bashrc.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
#!/usr/bin/env bash
# Usage:
# bash <(curl -Lso- https://sh.vps.dance/bashrc.sh)
# Colors
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[0;33m'; BLUE="\033[34m"; PURPLE="\033[35m"; BOLD="\033[1m"; NC='\033[0m';
success() { printf "${GREEN}%s${NC} ${@:2}\n" "$1"; }
info() { printf "${BLUE}%s${NC} ${@:2}\n" "$1"; }
danger() { printf "${RED}[x] %s${NC}\n" "$@"; }
warn() { printf "${YELLOW}%s${NC}\n" "$@"; }
# allusers=$( cat /etc/passwd | grep -vE "(/bin/false|/sbin/nologin|/bin/sync|guest-)" | cut -d: -f1 )
# allusers=$(awk -F':' '$2 ~ "\\$" {print $1}' /etc/shadow)
apply_bashrc() {
for file in /root/.bashrc /home/*/.bashrc; do
# echo $file;
if [[ ! -f "$file" ]]; then continue; fi
# insert lines
printf "%s\n" "# => vps.dance" >>$file
printf "%s\n" "$(curl -Lso- https://sh.vps.dance/raw/VPSDance/scripts/main/files/bashrc)" >>$file
printf "%s\n" "# <= vps.dance" >>$file
done
}
restore_bashrc() {
for file in /root/.bashrc /home/*/.bashrc; do
# echo $file;
if [[ ! -f "$file" ]]; then continue; fi
# delete lines between two patterns
sed -i '/^# => vps.dance/,/^# <= vps.dance/d' $file
done
}
reload_bashrc() {
# source ~/.bashrc
# fix: source bashrc not working
exec bash
}
menu() {
# clear
info "shell 终端优化, 请选择: "
local AR=(
[1]='应用'
[2]='还原'
)
for i in "${!AR[@]}"; do
success "$i." "${AR[i]}"
done
while :; do
read -p "输入数字以选择: " num
[[ -n "${AR[num]}" ]] || {
danger "invalid number"
continue
}
break
done
if [[ "$num" == "1" ]]; then
restore_bashrc
apply_bashrc
reload_bashrc
elif [[ "$num" == "2" ]]; then
restore_bashrc
reload_bashrc
fi
}
menu