This repository has been archived by the owner on Jul 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprep.sh
executable file
·110 lines (95 loc) · 2.34 KB
/
prep.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
#!/bin/bash
#
# This file prepares the openwrt source tree prior to doing a build.
#
# Basically, this means that minor configuration changes that need
# to be done prior to performing the build are done here.
#
# This file assumes that its being run in the same directory as the .config
# file found in the root of openwrt tree.
SCRIPT_NAME=$(basename $0)
SCRIPT_DIR=$(dirname $0)
if [ ! -f .config ]; then
echo "No .config file found in the current directory."
exit 1
fi
HOSTNAME=gateway
###########################################################################
#
# Prints the program usage
#
usage() {
cat <<END
${SCRIPT_NAME} [OPTION]
where OPTION can be one of:
--hostname NAME Specify the hostname
-h, --help Print this help
-v, --verbose Turn on some verbose reporting
-x Does a 'set -x'
END
}
###########################################################################
#
# Update hostname
#
update_hostname() {
SYSTEM_INIT=./package/base-files/files/etc/init.d/system
OLD_HOSTNAME=$(sed -n -e "/hostname:string:/ s/.*hostname:string:\([^']*\).*/\1/p" "${SYSTEM_INIT}")
echo "Updating hostname from '${OLD_HOSTNAME}' to '${HOSTNAME}'"
sed -i -e "s/hostname:string:${OLD_HOSTNAME}/hostname:string:${HOSTNAME}/" "${SYSTEM_INIT}"
}
###########################################################################
#
# Parses command line arguments and run the program.
#
main() {
while getopts ":vhx-:" opt "$@"; do
case $opt in
-)
case "${OPTARG}" in
help)
usage
exit 1
;;
hostname)
HOSTNAME="${!OPTIND}"
OPTIND=$(( OPTIND + 1 ))
;;
verbose)
VERBOSE=1
;;
*)
if [ "$OPTERR" = 1 ] && [ "${optspec:0:1}" != ":" ]; then
echo "Unknown option --${OPTARG}" >&2
echo ""
usage
exit 1
fi
esac
;;
h)
usage
exit 1
;;
v)
VERBOSE=1
;;
x)
set -x
;;
?)
echo "Unrecognized option: ${opt}"
echo ""
usage
exit 1
;;
esac
done
shift $(( OPTIND - 1 ))
if [ "${VERBOSE}" == "1" ]; then
echo "HOSTNAME = ${HOSTNAME}"
fi
echo ""
update_hostname
}
main "$@"