-
Notifications
You must be signed in to change notification settings - Fork 6
/
init_build
executable file
·127 lines (111 loc) · 3.2 KB
/
init_build
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
126
127
#!/bin/sh
#
# init_build
#
VERSION="1.2"
die()
{
printf '%s\n' "$1" >&2
exit 1
}
OS=$(uname -s)
if [ "$OS" = Linux ]
then
[ -z "$(whereis -b git | cut -d: -f2)" ] && die "Please install git"
elif [ "$OS" = FreeBSD ]
then
[ -z "$(whereis -b git | cut -d: -f2)" ] && die "Please install git"
[ -z "$(which gmake)" ] && die "Please install gmake"
elif [ "$OS" = Darwin ]
then
[ -z "$(which git)" ] && die "Please install git"
fi
# Check that the script is not run by root
[ "$(id -u)" -eq 0 ] && die "DO NOT run this as root"
show_help()
{
cat <<EOF
Prepare for a build of the Husky sources.
Usage:.
init_build [-d|--dir TOP_DIRECTORY] [-v|--version] [-h|-\?|--help]
Options:
-d TOP_DIRECTORY
--dir TOP_DIRECTORY
Put all Husky sources in TOP_DIRECTORY. It should be an absolute path.
-v
--version
Print the script version and exit.
-h
-?
--help
Print this help and exit.
EOF
}
top_directory=~/husky
help=0
case $1 in
-h|-\?|--help)
help=1
;;
-v|--version)
echo "version = $VERSION"
exit
;;
-d|--dir)
if [ "$2" ]
then
top_directory="$2"
[ "${top_directory%"${top_directory#?}"}" != '/' ] && \
[ "${top_directory%"${top_directory#??}"}" != '~/' ] && \
die 'ERROR: the directory must start with "/" or "~/"'
shift
else
die 'ERROR: "-d" or "--dir" requires a non-empty option argument'
fi
;;
-*)
printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
;;
*)
;;
esac
if [ $help -eq 1 ]
then
show_help
exit
fi
[ "${top_directory%?}/" = "${top_directory}" ] && top_directory="${top_directory%?}"
mkdir -p $top_directory
cd $top_directory
[ -d "$top_directory/huskybse/.git" ] && cd huskybse && { git pull; cd ..; } || \
git clone https://github.com/huskyproject/huskybse.git
huskymak=huskybse/huskymak.cfg
[ "$OS" = FreeBSD ] && huskymak=huskybse/huskymak.cfg.bsd
[ "$OS" = Darwin ] && huskymak=huskybse/huskymak.cfg.macos
[ "$OS:0:5" = MINGW ] && huskymak=huskybse/huskymak.cfg.mgw
cp -f -p huskybse/Makefile Makefile
cp -f -p $huskymak huskymak.cfg.new
cp -f -p huskybse/script/build.sh build.sh
if [ -f huskymak.cfg ]
then
if [ -n "$(diff $huskymak huskymak.cfg)" ]
then
mv -f huskymak.cfg huskymak.cfg.old
cp -p $huskymak huskymak.cfg
echo
echo "########################################################################"
echo "Your huskymak.cfg was renamed to huskymak.cfg.old"
echo "Now you need to make changes to \"$top_directory/huskymak.cfg\""
echo "per your requirements and then run \"$top_directory/build.sh\"."
echo "########################################################################"
echo
fi
else
cp -p $huskymak huskymak.cfg
echo
echo "########################################################################"
echo "Now you need to make changes to \"$top_directory/huskymak.cfg\""
echo "per your requirements and then run \"$top_directory/build.sh\"."
echo "########################################################################"
echo
fi