-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcmd_template.sh
More file actions
115 lines (113 loc) · 2.54 KB
/
cmd_template.sh
File metadata and controls
115 lines (113 loc) · 2.54 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
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
#========================================
# Linux Distribution: Manjaro/Debian 8+/
# Author: 6donote4 <mailto:[email protected]>
# Dscription:
# Version: 0.0.1
# Blog: https://www.donote.ml https://6donote4.github.io
#========================================
#
VERSION=0.0.1
PROGNAME="$(basename $0)"
export LC_ALL=C
SCRIPT_UMASK=0122
umask $SCRIPT_UMASK
args=($(getopt -o stvh -l help,version -- "$@"))
set -- "$args";
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
plain='\033[0m'
usage() {
cat << EOF
$PROGNAME $VERSION
Usage:
./$PROGNAME [option]
Options
-s
--
-t
-v --version Show version
-h --help Show this usage
EOF
}
if [[ "$1" == "" ]];then
usage
exit 0
fi
read_fun() {
read -p "$1" RESPON
echo $RESPON
}
print_fun() {
echo -e "${yellow}You inputed :${plain}"
echo $1 >&1
echo -e "${green}print done${plain}"
}
test_fun() {
print_fun ${ARG=$(read_fun "read_print_test:" )}
echo -e "${green}test done${plain}"
}
check_sys(){
if [[ -f /etc/redhat-release ]]; then
release="centos"
elif cat /etc/issue | grep -q -E -i "debian"; then
release="debian"
elif cat /etc/issue | grep -q -E -i "ubuntu"; then
release="ubuntu"
elif cat /etc/issue | grep -q -E -i "centos|red hat|redhat"; then
release="centos"
elif cat /proc/version | grep -q -E -i "debian"; then
release="debian"
elif cat /proc/version | grep -q -E -i "ubuntu"; then
release="ubuntu"
elif cat /proc/version | grep -q -E -i "centos|red hat|redhat"; then
release="centos"
fi
<<EOF
usage:
if [[ ${release} == "centos" ]]; then
yum install -y debootstrap schroot
elif [[ ${release} == "debian" ]];then
apt-get install -y debootstrap schroot
else
pacman -S debootstrap schroot
fi
EOF
bit=`uname -m`
}
check_root(){
[[ $EUID != 0 ]] && echo -e " ${red}当前账号非ROOT(或没有ROOT权限),无法继续操作,请使用sudo su 来获取临时ROOT权限(执行后会提示输入当前账号的密码)。${plain}" && exit 1
}
main(){
usage
}
while [ -n "$1" ]
do
case "$1" in
-s)
exit 0
;;
-t)
exit 0
;;
-h|--help)
usage
exit 0
;;
-v|--version)
echo $VERSION
exit 0
;;
--)
main
;;
*)
echo -e "${red}Invalid parameter $1 ${plain}" 1>&2
break
;;
esac
shift
done