forked from superhj1987/awesome-scripts
-
Notifications
You must be signed in to change notification settings - Fork 25
/
opscripts-common.sh
56 lines (49 loc) · 1.27 KB
/
opscripts-common.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
#!/bin/bash
print_column (){
echo -e $1 |awk -F'\t' '{printf "%-15s%s\n",$1,$2}'
}
print_title (){
length=`echo "$1" |wc -c`
prefix_count=$(((30-length)/2))
for i in `seq 0 $prefix_count` ;do
echo -n '='
done
echo -n " $1 "
postfix_count=$((length % 2 != 0 ? prefix_count+1: prefix_count))
for i in `seq 0 $postfix_count` ;do
echo -n '='
done
printf '\r\n'
}
find_command(){
commands=`ls -l $1/bin |grep -v '^d' |awk '{print $9}'`
if [ "$commands" = "" ]; then
return
fi
for file in $commands ;do
desp=`grep '^## ' $1/bin/$file | cut -c 3-`
if [ "$desp" != "" ]; then
print_column "$file\t:$desp"
echo "$file" >> $HOME/.opscripts/cmds.cache
fi
done
echo ''
}
list_command() {
rm -f $HOME/.opscripts/cmds.cache 2>/dev/null
mkdir $HOME/.opscripts 2>/dev/null
echo 'Available commands:'
print_title bin
find_command $OPSCRIPTS_DIR
print_title java/bin
find_command $OPSCRIPTS_DIR/java
exit 0;
}
uninstall() {
echo -n "Uninstall opscripts,(y)es or (n)o?"
read choice < /dev/tty
if [ "$choice" = "y" ] && [ "$OPSCRIPTS_DIR" != "/" ];then
cd $OPSCRIPTS_DIR && make uninstall && rm -rf $OPSCRIPTS_DIR && echo "opscripts uninstall finished. Bye~"
fi
exit 0
}