-
Notifications
You must be signed in to change notification settings - Fork 263
/
build_deb.sh
executable file
·129 lines (109 loc) · 2.78 KB
/
build_deb.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
126
127
128
129
#!/bin/bash
# info
author="jiejie"
email="[email protected]"
github="https://github.com/jiejieTop"
description="is a communication library"
# variable
package_dir=""
package_name=""
info_name=""
arch="x86"
system="all"
major_version="1"
minor_version="2.0"
version="$major_version.$minor_version"
current_pwd=$(
cd "$(dirname "$0")"
pwd
)
fun_do_generate_depend() {
date=$(date)
changelog_file="author : ${author}
VERSION : ${version}
DATE: ${date}
"
copyright_file="
******************************************************************
* @attention
*
* github : ${github}
* author : ${author}
*
* * ******************************************************************
"
postinst_file="#!/bin/sh
sudo ldconfig
echo '******************************************************************'
echo 'welcome to use ${info_name} v${version}!'
echo '******************************************************************'
"
control_file="Source: ${author}
Package: ${info_name}
Version: ${version}
Section: develop / communication
Priority: optional
Architecture: all
Depends :
Maintainer: ${author}[${email}]
Description: ${description}, git hash : ${git_hash}
"
echo "$control_file" >$package_dir/DEBIAN/control
echo "$changelog_file" >$package_dir/DEBIAN/changelog
echo "$copyright_file" >$package_dir/DEBIAN/copyright
echo "$postinst_file" >$package_dir/DEBIAN/postinst
}
fun_do_get_system_id()
{
source /etc/os-release
system="$ID-$VERSION_ID"
}
fun_do_generate_arch() {
hostnamectl | grep -i "Architecture: x86"
if [ $? -ne 0 ]; then
hostnamectl | grep -i "Architecture: arm"
if [ $? -ne 0 ]; then
exit 1
fi
arch="arm"
else
arch="x86"
fi
}
fun_do_config() {
if [ " $1" == " " ]; then
echo "the construction path of the deb package must be specified"
echo "$0 [path]"
exit -1
fi
package_dir=$1
if [ " $2" == " " ]; then
# take the name of the deb package according to the path
package_name=${package_dir##*/}.deb
else
package_name=$2
fi
info_name=${package_name%.*}
if [ ! -d "${package_dir}/DEBIAN" ]; then
mkdir -p ${package_dir}/DEBIAN
fun_do_generate_depend
echo "please create a simulated root directory in ${package_dir}, and put the content in this directory"
exit -1
fi
echo "build $package_name in $package_dir"
}
fun_do_make_deb() {
package_name="${package_name%.*}-$system-$arch-$version.${package_name##*.}"
sudo chmod 775 $package_dir/DEBIAN/postinst
dpkg -b $package_dir $package_name
}
main() {
cd $current_pwd
fun_do_config $1 $2
fun_do_generate_arch
fun_do_get_system_id
fun_do_generate_depend
fun_do_make_deb
cd -
}
main "$@"