This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·125 lines (100 loc) · 2.6 KB
/
install.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
#!/bin/bash
# Script to install utilities
# Author: Márk Sági-Kazár ([email protected])
# This script install all or specific utilities
#
# Version: 1.0
DIR=$(cd `dirname $0` && pwd)
path="${path:-/usr/bin}"
BUILD=${BUILD:-0}
# Echo colored text
e()
{
local color="\033[${2:-34}m"
echo -e "$color$1\033[0m"
}
## Exit error
ee()
{
local exit_code="${2:-1}"
local color="${3:-31}"
e "$1" "$color"
exit $exit_code
}
## Set path
setpath()
{
[ -z "$1" ] || path="$1"
if [ -d $path -a -w $path ]; then
e "Path is set to $path"
else
ee "Please specify a valid and writable path"
fi
}
# Checking root access
if [ $EUID -ne 0 ]; then
e "You are not running this script as root!" 31
fi
while getopts p:b option; do
case "${option}" in
p )
setpath ${OPTARG}
;;
b )
BUILD=1
;;
esac
done
shift $((OPTIND-1))
if [[ -z "$scripts" && $BUILD -eq 0 ]]; then
e "Installing all scripts"
scripts=("$DIR/scripts"/*)
else
IFS=' ' read -a scripts <<< "${scripts}"
fi
if [ $BUILD -eq 1 ]; then
e "Compiling all scripts"
BUILD="#!/bin/bash\n\n# Compiled script from several utilities.\n# Path: $path\n# Date: $(date +"%Y-%m-%d %H:%M:%S")\n"
for script in "${scripts[@]}"; do
script=`basename $script`
if [[ -f "$DIR/scripts/$script" && -s "$DIR/scripts/$script" ]]; then
e "\nCompiling $script"
BUILD="$BUILD\n\n$script()\n{\n"
while read line; do
if [[ "$line" == \#* || "$line" == "" ]]; then
continue
fi
line="${line//exit/return}"
BUILD="$BUILD$line\n"
done < "$DIR/scripts/$script"
BUILD="$BUILD}"
e "$script compiled" 32
else
e "\nScript $script not found or empty" 31
fi
done
echo -e "$BUILD" > "$path/utilities.sh"
if [ ! -x "$path/utilities.sh" ]; then
e "\nAdding execute permission to $path/utilities.sh"
chmod +x "$path/utilities.sh" || e "Cannot add execute permission to $path/utilities.sh" 31
fi
grep -R "[ -f $path/utilities.sh ] && source $path/utilities.sh" /etc/bash.bashrc &> /dev/null
[ $? -eq 0 ] || echo -e "[ -f $path/utilities.sh ] && source $path/utilities.sh" >> /etc/bash.bashrc
e "\nCompilation done." 32
else
for script in "${scripts[@]}"; do
script=`basename $script`
if [[ -f "$DIR/scripts/$script" && -s "$DIR/scripts/$script" ]]; then
e "\nInstalling $script"
cp -r "$DIR/scripts/$script" "$path" || e "Installing $script failed" 31
if [ ! -x "$path/$script" ]; then
e "Adding execute permission to $script"
chmod +x "$script" || e "Cannot add execute permission to $script" 31
fi
e "$script installed" 32
else
e "\nScript $script not found" 31
fi
done
e "\nInstallation done." 32
fi