-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.bashrc
211 lines (172 loc) · 4.97 KB
/
.bashrc
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
199
200
201
202
203
204
205
206
207
208
209
210
211
source /usr/local/lib/config/Bash_Profile
update_dotfiles() {
local repo_dir="$HOME/.dotfiles"
local repo_url="https://github.com/Will-Hellinger/college-dotfiles.git"
local DOTFILES_VIMRC="$repo_dir/.vimrc"
local HOME_VIMRC="$HOME/.vimrc"
local DOTFILES_BASHRC="$repo_dir/.bashrc"
local HOME_BASHRC="$HOME/.bashrc"
if [ ! -d "$repo_dir" ]; then
git clone "$repo_url" "$repo_dir"
else
(cd "$repo_dir" && git pull origin main)
fi
if [ -f "$HOME_VIMRC" ] && [ ! -L "$HOME_VIMRC" ]; then
mv "$HOME_VIMRC" "$HOME_VIMRC.bak"
fi
if [ ! -L "$HOME_VIMRC" ]; then
if [ -f "$DOTFILES_VIMRC" ]; then
ln -s "$DOTFILES_VIMRC" "$HOME_VIMRC"
else
echo "dotfiles .vimrc not found. Symlink not created."
fi
fi
if [ ! -d $HOME/.vim ]; then
echo "vim plugin folder not located | Installing now..."
mkdir "$HOME/.vim"
mkdir "$HOME/.vim/autoload"
wget https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim "$HOME/.vim/autoload/plug.vim"
fi
if [ -f "$HOME_BASHRC" ] && [ ! -L "$HOME_BASHRC" ]; then
mv "$HOME_BASHRC" "${HOME_BASHRC}.bak"
fi
if [ ! -L "$HOME_BASHRC" ]; then
if [ -f "$DOTFILES_BASHRC" ]; then
ln -s "$DOTFILES_BASHRC" "$HOME_BASHRC"
else
echo "dotfiles .bashrc not found. Symlink not created."
fi
fi
}
get_tools() {
local fastfetch_url="https://github.com/fastfetch-cli/fastfetch/releases/download/2.6.0/fastfetch-2.6.0-Linux.zip"
local btop_url="https://github.com/aristocratos/btop/releases/download/v1.3.0/btop-x86_64-linux-musl.tbz"
local tools_dir="$HOME/.tools"
mkdir -p "$tools_dir"
if [ ! -f "$tools_dir/fastfetch" ]; then
echo "Downloading fastfetch..."
wget -O fastfetch.zip "$fastfetch_url" || curl -L "$fastfetch_url" -o fastfetch.zip
unzip fastfetch.zip
rm fastfetch.zip
mv "./fastfetch-2.6.0-Linux/usr/bin/fastfetch" "$tools_dir/fastfetch"
rm -rf "fastfetch-2.6.0-Linux"
echo "Done setting up fastfetch"
fi
if [ ! -f "$tools_dir/btop" ]; then
echo "Downloading btop..."
wget -O btop.tbz "$btop_url" || curl -L "$btop_url" -o btop.tbz
tar -xjf btop.tbz
rm btop.tbz
mv "./btop/bin/btop" "$tools_dir/btop"
rm -rf "btop"
echo "done setting up btop"
fi
export PATH="$tools_dir:$PATH"
}
userlist() {
local option=${1:-all}
local online_users=$(who | cut -d' ' -f1 | sort | uniq)
local all_users=$(awk -F':' '{print $1}' /etc/passwd)
case "$option" in
online)
echo -e "Online Users:"
for user in $online_users; do
echo -e "\e[32m$user\e[0m"
done
;;
offline)
echo -e "Offline Users:"
for user in $all_users; do
if ! [[ $online_users =~ $user ]]; then
echo -e "\e[31m$user\e[0m"
fi
done
;;
*)
echo -e "All Users:"
for user in $all_users; do
if [[ $online_users =~ $user ]]; then
echo -e "$user \e[32m(online)\e[0m"
else
echo -e "$user \e[31m(offline)\e[0m"
fi
done
;;
esac
}
getinfo() {
if [ -z "$1" ]; then
echo "Usage: getinfo username"
return 1
fi
local username="$1"
local uptime=$(last -F -n 1 "$username" | head -n 1 | awk '{print $6, $7, $8, $9, $10}')
uptime=${uptime:-"No recent sessions"}
echo -e "Information for user: \e[33m$username\e[0m"
echo -e "Uptime: \e[32m$uptime\e[0m"
echo -e "Processes running:"
ps -u "$username" -o pid=,cmd= | awk '{printf " %-8s %s\n", $1, $0}' | cut -d' ' -f1,3-
}
extract() {
if [ -z "$1" ]; then
echo "Usage: extract <path/filename>"
return 1
fi
if [ -f "$1" ]; then
case "$1" in
*.tar.bz2) tar xjf "$1" ;;
*.tar.gz) tar xzf "$1" ;;
*.bz2) bunzip2 "$1" ;;
*.rar) unrar x "$1" ;;
*.gz) gunzip "$1" ;;
*.tar) tar xf "$1" ;;
*.tbz2) tar xjf "$1" ;;
*.tgz) tar xzf "$1" ;;
*.zip) unzip "$1" ;;
*.Z) uncompress "$1";;
*.7z) 7z x "$1" ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
mkcd() {
mkdir -p "$1" && cd "$1"
}
backup() {
if [ -z "$1" ]; then
echo "Usage: backup <file>"
return 1
fi
cp "$1" "$1.bak"
}
server_info() {
local online_users=$(who | cut -d' ' -f1 | sort | uniq)
local online_user_count=$(echo "$online_users" | wc -l)
local current_user=$(whoami)
echo -e "Welcome to RIT Servers!"
echo -e "Current time is: $(date)"
if [ "$online_user_count" -eq 1 ] && [[ $online_users == *"$current_user"* ]]; then
echo -e "There is 1 user\e[32m online\e[0m - You!"
else
echo -e "There are $online_user_count user(s)\e[32m online\e[0m!"
fi
}
checkport() {
nc -zv "$1" "$2" && echo "Port $2 on $1 is open" || echo "Port $2 on $1 is closed"
}
netinfo() {
ip addr show
}
clean_clear() {
clear
fastfetch
server_info
}
leave() {
killall sshd
}
get_tools
update_dotfiles
clean_clear