-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell-compiler.sh
220 lines (193 loc) Β· 8.37 KB
/
shell-compiler.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
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
212
213
214
215
216
217
218
219
220
#!/bin/bash
export NODE_OPTIONS=--openssl-legacy-provider
MODE_ENC=("aes-128-cbc" "aes-192-cbc" "aes-256-cbc" "aes-128-cbc_base64" "aes-192-cbc_base64" \
"aes-256-cbc_base64" "aes-128-cbc_zlib" "aes-192-cbc_zlib" "aes-256-cbc_zlib" "aria-128-cbc" \
"aria-192-cbc" "aria-256-cbc" "base64" "camellia-128-cbc" "camellia-192-cbc" "camellia-256-cbc" \
"ccrypt" "des" "des-cbc" "des-ede" "des-ede-cbc" "des-ede3" "des-ede3-cbc" "des3" "desx" "desx-cbc" \
"gcrypt" "sm4" "sm4-cbc" "zlib")
VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo null)
# The [[ -t 1 ]] check only works when the function is not called from
# a subshell (like in `$(...)` or `(...)`, so this hack redefines the
# function at the top level to always return false when stdout is not
# a tty.
if [[ -t 1 ]]; then
is_tty() {
true
}
else
is_tty() {
false
}
fi
setup_color() {
# Only use colors if connected to a terminal
if ! is_tty; then
BLACK=""
RED=""
GREEN=""
YELLOW=""
BLUE=""
MAGENTA=""
CYAN=""
WHITE=""
BOLD=""
ITALIC=""
UNDERLINE=""
RESET=""
return
fi
BLACK=$(printf '\033[90m')
RED=$(printf '\033[91m')
GREEN=$(printf '\033[92m')
YELLOW=$(printf '\033[93m')
BLUE=$(printf '\033[94m')
MAGENTA=$(printf '\033[95m')
CYAN=$(printf '\033[96m')
WHITE=$(printf '\033[97m')
BOLD=$(printf '\033[1m')
ITALIC=$(printf '\033[3m')
UNDERLINE=$(printf '\033[4m')
RESET=$(printf '\033[0m')
}
info() {
echo "${RESET}${BOLD}${GREEN}Info:${WHITE} $@${RESET}"
}
error() {
echo "${RESET}${BOLD}${RED}Error: $@${RESET}"
}
command_exists() {
command -v "$@" >/dev/null 2>&1
}
banner() {
echo "${RESET}${BOLD}${RED}βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β${YELLOW} ββββ» β»βββΈβ» β» βββΈβββββ³βββββ»β» βββΈβββ ${RED}β
β${YELLOW} ββββ£ββ«β£βΈ β β βΊββΈβ β βββββ£ββββ β£βΈ β£β³β ${RED}β
β${YELLOW} ββββΉ βΉβββΈβββΈβββΈ βββΈββββΉ βΉβΉ βΉβββΈβββΈβΉββΈ ${RED}β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
${CYAN} Author : ${WHITE}Barudak Rosul
${CYAN} Version: ${WHITE}$VERSION
${CYAN} GitHub : ${WHITE}${UNDERLINE}https://github.com/BarudakRosul${RESET}"
}
main_menu_type_shell() {
trap "echo; error 'Program cancelled!'; exit 127;" INT TERM ERR
clear
banner
echo "${RESET}${BOLD}${RED}βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β${YELLOW} Choose your type shell for encrypted ${RED}β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
${GREEN} 1. ${WHITE}bash (Bourne Again Shell)
${GREEN} 2. ${WHITE}sh (Bourne Shell)
${GREEN} 3. ${WHITE}zsh (Z Shell)
${GREEN} 4. ${WHITE}ksh (Korn Shell)
${GREEN} 5. ${WHITE}mksh (MirBSD Korn Shell)
${RED} 0. Exit
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
read -p "${RESET}${BOLD}${WHITE}Choose ${GREEN}>>${RESET} " response
case $response in
0 | 00) info "The program exited by user!"; exit 0;;
1 | 01) TYPE_SHELL="bash";;
2 | 02) TYPE_SHELL="sh";;
3 | 03) TYPE_SHELL="zsh";;
4 | 04) TYPE_SHELL="ksh";;
5 | 05) TYPE_SHELL="mksh";;
"" | " ") error "Please select a menus!"; exit 1;;
*) error "Wrong input! Please try again!"; exit 1;;
esac
trap - INT TERM ERR
}
main_menu_mode() {
trap "echo; error 'Program cancelled!'; exit 127;" INT TERM ERR
local response
local number
local space
clear
banner
echo "${RESET}${BOLD}${RED}βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β${YELLOW} Choose your mode for encrypted ${RED}β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${RESET}"
for ((i=0;i<${#MODE_ENC[@]};i++)); do
number=$((i + 1))
space=""
if (( 1 == ${#number} )); then
space=" "
fi
mode=$(printf "${MODE_ENC[i]}" | sed 's/_zlib/ (zlib)/' | sed 's/_base64/ (base64)/')
echo "${RESET}${BOLD}${GREEN} ${space}$((number)). ${WHITE}$mode${RESET}"
done
echo "${RESET}${BOLD}${RED} 0. Exit
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${RESET}"
read -p "${RESET}${BOLD}${WHITE}Choose ${GREEN}>>${RESET} " response
if (( ${#response} == 2 )); then
response=${response##0}
fi
if (( $response > ${#MODE_ENC[@]} )); then
error "Wrong input! Please try again!"
exit 1
fi
case $response in
0 | 00) info "The program exited by user!"; exit 0;;
[0-9] | [0-9][0-9]) MODE=${MODE_ENC[response - 1]};;
"" | " ") error "Please select a menus!"; exit 1;;
*) error "Wrong input! Please try again!"; exit 1;;
esac
trap - INT TERM ERR
}
main_menu_input_file() {
trap "echo; error 'Program cancelled!'; exit 127;" INT TERM ERR
clear
banner
mode=$(printf "$MODE" | sed 's/_zlib/ (zlib)/' | sed 's/_base64/ (base64)/')
echo "${RESET}${BOLD}${RED}βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β${YELLOW} Input your file in \"file\" folder for encrypt ${RED}β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
${WHITE} File type : ${GREEN}${UNDERLINE}$TYPE_SHELL${RESET}${BOLD}
${WHITE} Encrypt mode: ${GREEN}${UNDERLINE}$mode${RESET}${BOLD}
${RED}βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${RESET}"
read -p "${RESET}${BOLD}${WHITE}Script ${GREEN}>>${RESET} " input
if [[ $input == "" || $input == " " ]]; then
error "Please input your file name!"
exit 1
elif ! [[ -f file/$input || -r file/$input ]]; then
error "No such file \"$input\" in directory \"file\""
exit 1
elif [[ -f out/$input || -r out/$input ]]; then
error "The file \"$input\" is already compressed!"
exit 1
fi
INPUT=$input
trap - INT TERM ERR
}
main() {
setup_color
main_menu_type_shell
main_menu_mode
main_menu_input_file
bash lib/${MODE}.sh -t ${TYPE_SHELL} -i file/${INPUT} -o out/${INPUT}
}
setup_color
for ((i=0;i<${#MODE_ENC[@]};i++)); do
test -f lib/${MODE_ENC[i]}.sh && test -r lib/${MODE_ENC[i]}.sh || {
error "Some files are missing!"
info "Please install the script from github <https://github.com/BarudakRosul/shell-compiler>"
exit 1
}
done
command_exists ncssl || {
error "The program \`ncssl' is not installed."
info "Please installed the program and try again."
exit 127
}
command_exists ccrypt || {
error "The program \`ccrypt' is not installed."
info "Please installed the program and try again."
exit 127
}
command_exists gcrypt || {
error "The program \`gcrypt' is not installed."
info "Please installed the program and try again."
exit 127
}
main