- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_script.sh
More file actions
Latest commit
executable file
·104 lines (80 loc) · 2.91 KB
/
Copy pathinstall_script.sh
File metadata and controls
executable file
·104 lines (80 loc) · 2.91 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
#!/bin/zsh
if [ "$1"="-d" ];then
result_args="${@:2}"
echo"DEVELOPMENT MODE IS ON"
sh $HOME/Documents/InstallShellScripts/install_script.sh ${@:2}
exit 0
fi
ERROR="\033[31m"
TITLE="\033[36m"
INFO="\033[37m"
SUCCESS="\033[32m"
SCRIPT="\033[32m"
INSTALL_SCRIPT="\033[35m"
COMMENT="\033[90m"
RESET="\033[0m"
usage() {
echo"\nOptions:"
echo"${INSTALL_SCRIPT}install_script$TITLE <sh_file_name>$COMMENT # The name of the sh file to install"
echo"${INSTALL_SCRIPT}install_script$TITLE <script_name> $SUCCESS-u$COMMENT # The name of the script to uninstall"
echo"${INSTALL_SCRIPT}install_script$TITLE$SUCCESS-l$COMMENT # Print the list of all installed scripts"
echo"${INSTALL_SCRIPT}install_script$TITLE$SUCCESS-d$COMMENT [arguments] # Execute the script in Documents folder instead of the installed script"
echo"$RESET"
}
echo"$TITLE"
echo" ___ _ _ ____ _____ _ _ _ ____ ____ ____ ___ ____ _____ "
echo" |_ _| \ | / ___|_ _|/ \ | | | | / ___| / ___| _ \|_ _| _ \_ _|"
echo" | || \| \___ \ | | / _ \ | | | | \___ \| | | |_) || || |_) || | "
echo" | || |\ |___) || |/ ___ \| |___| |___ ___) | |___| _ < | || __/ | | "
echo" |___|_| \_|____/ |_/_/ \_\_____|_____| |____/ \____|_| \_\___|_| |_| "
echo"$RESET"
if [ "$1"="-h" ];then
usage
exit 0
fi
if [ "$1"="-l" ];then
echo"Installed scripts:\n"
cat ~/.zshrc | grep alias| cut -d'' -f2 | cut -d'=' -f1 | sed 's/^/- /'
exit 0
fi
if [ -z"$1" ];then
echo"$ERROR Missing file name$RESET"
usage
exit -1
fi
fileName=$1
if [ "$2"="-u" ];then
echo"$INFO Removing script file called $SCRIPT$fileName$INFO from /usr/local/bin folder...$RESET"
rm -f /usr/local/bin/${fileName}.sh
scriptName=${fileName%.*}
echo"$INFO Removing alias for $SCRIPT$fileName$INFO...$RESET"
sed -i.bak "/alias $scriptName=$fileName/d"~/.zshrc
echo
echo"$SUCCESS Script uninstalled!$RESET"
echo"$INFO The script $SCRIPT$fileName$INFO has been uninstalled, and the alias has been removed.$RESET"
exec$SHELL
fi
if [ !-f$(pwd)/$fileName ]
then
echo"$ERROR File not found$RESET"
usage
exit -2
fi
scriptName=$(basename "$fileName" .sh)
echo"$INFO Adding script file called $SCRIPT$fileName$INFO to /usr/local/bin folder...$RESET"
# Add the script to the Bin folder
cp $fileName /usr/local/bin
echo"$INFO Changing permissions for $SCRIPT$fileName$INFO...$RESET"
# Change file permission
chmod +x /usr/local/bin/$fileName
echo"$INFO Creating alias for $SCRIPT$fileName$INFO...$RESET"
if grep -q "alias $scriptName=$fileName"~/.zshrc;then
echo"Alias already created."
else
# Adds the alias
echo"alias $scriptName=$fileName">>~/.zshrc
fi
echo
echo"$SUCCESS Done!$RESET"
echo"$INFO You can now launch your script by simply running $SCRIPT$scriptName$INFO. $RESET"
exec$SHELL