-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcommon.sh
107 lines (93 loc) · 2.35 KB
/
common.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
#!/bin/bash
#
# Copyright (C) 2012 Erick Birbe <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
SRC_DEST="rtl8192se_linux_2.6.0019.1207.2010"
MODULE_NAME="r8192se_pci"
PWD=$( pwd )/
STATUS_SUCCESS=0
STATUS_ERROR=1
## Functions ##
# Writes a string to stderror as ERROR
write_error()
{
echo "ERROR: $*" 1>&2
}
# Writes a string to stderror as WARNING
write_warning()
{
echo "WARNING: $*" 1>&2
}
# Determines if the user is root
is_root()
{
if [[ $EUID -ne 0 ]]; then
write_error "This script must be run as root"
return $STATUS_ERROR
fi
}
# Check is root user
check_is_root()
{
if ! is_root; then
echo "Login as administrator user and try again."
exit $STATUS_ERROR
fi
}
# Determines if an aplication executable exists in PATH
application_exists()
{
if ! [ -x "`which $1`" ]; then
write_error "Impossible to find the '$1' executable."
return $STATUS_ERROR
fi
}
# Install aplications with apt-get
install_debian_app ()
{
apt-get install $*
if [ $? -ne 0 ]; then
write_error "There was a problem installing: $*."
return $STATUS_ERROR
fi
}
# Check for necessary applications
check_apps()
{
IS_FINE=$STATUS_SUCCESS
DEPENDS=""
if ! [ -d /usr/src/linux-headers-$(uname -r) ]; then
IS_FINE=$STATUS_ERROR
DEPENDS="$DEPENDS linux-headers-$(uname -r)"
fi
if ! application_exists make; then
IS_FINE=$STATUS_ERROR
DEPENDS="$DEPENDS make"
fi
if ! application_exists quilt; then
IS_FINE=$STATUS_ERROR
DEPENDS="$DEPENDS quilt"
fi
if [ $IS_FINE -ne $STATUS_SUCCESS ]; then
echo "Trying to install the dependencies:" $DEPENDS
if ! install_debian_app $DEPENDS; then
echo "Please install the required dependencies and try again."
exit $STATUS_ERROR
fi
fi
}
##