forked from ashish-k-s/NovelloShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
novelloshell-bashrc
46 lines (39 loc) · 1.16 KB
/
novelloshell-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
####### For NovelloShell #######
## source this file in /etc/bashrc file of the system hosting NovelloShell ##
function checkcmd
{
valid_cmds="ls ll cd ll vi cat mkdir cp mv echo "
valid_writing_cmds="vi mkdir cp mv "
if [[ $PWD != *"$VALIDDIR"* ]]
then
echo -e "Invalid directory usage, exiting..."
exit
fi
cmd=$(echo $BASH_COMMAND | cut -f 1 -d ' ')
arg=$(echo $BASH_COMMAND | cut -f 2- -d ' ')
if [[ "$BASH_COMMAND" != @(*"printf"*|*"PATH"*) ]]
then
if [[ $cmd != *"bash"* ]]
then
if [[ "$valid_cmds" != *"$cmd "* ]]
then
echo -e "Invalid command usage, exiting..."
exit
fi
if [[ "$valid_writing_cmds" == *"$cmd "* ]]
then
if [[ $arg == *".."* ]]
then
echo -e "You can not access parent directory with the command writing to disk, exiting..."
exit
fi
fi
fi
else
echo -e ""
fi
}
if [[ "$NOVELLO" == "yes" ]]
then
trap 'checkcmd $VALIDDIR' debug
fi