-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpackage.sh
executable file
·118 lines (90 loc) · 2.2 KB
/
package.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
#!/bin/sh
usage() {
echo "Usage: package.sh <version number>"
exit 1;
}
# Avoid duplication of defined checks
check_defined() {
VAR_NAME=$1
VAR=$2
if [ -z "$VAR" ]
then
echo "$VAR_NAME must be defined in project.conf"
exit 1
fi
}
# Look up an executable and return a path to it via RESULT or die
is_installed() {
EXECUTABLE=$1
PACKAGE=$2
RESULT=`which $1`
if [ -z "$RESULT" ]
then
echo "Please install $PACKAGE and try this operation again"
exit 2
fi
}
if [ ! -e 'project.conf' ]
then
echo 'No project.conf file found in the current directory!' ;
exit 1;
fi
# Make sure that we were given a version number
VERSION="$1"
if [ -z "$VERSION" ]
then
usage
fi
# Setup configuration defaults
# Where will we find git?
GIT_PATH=`which git`
# make sure we have dh_make and dpkg_buildpackage installed
is_installed dh_make dh-make
DH_MAKE=$RESULT
is_installed dpkg-buildpackage dpkg-dev
DPKG_BUILDPACKAGE=$RESULT
# needed to sign packages
is_installed gpg gnupg
# Pull in configuration for the given project
. ./project.conf
# Validate that our required paramters are configured
check_defined 'AUTHOR_EMAIL' $AUTHOR_EMAIL
check_defined 'PROJECT_NAME' $PROJECT_NAME
check_defined 'PACKAGING_ROOT' $PACKAGING_ROOT
check_defined 'REPO_ROOT' $REPO_ROOT
# validate that the WORKING_DIR exists, create it if not
WORKING_DIR="$PACKAGING_ROOT/$PROJECT_NAME""-""$VERSION"
PACKAGE_FILES="$PACKAGING_ROOT/$PROJECT_NAME""_""$VERSION""*"
if [ ! -e $WORKING_DIR ]
then
echo "Creating Working DIR"
mkdir -p $WORKING_DIR
fi
# sub shell to avoid lossing our current dir
(
# Build out the package dir
cd $WORKING_DIR
# Setup a default project incase we don't want to have to do all of it.
$DH_MAKE --native -s --email $AUTHOR_EMAIL --createorig
find . -type f -name '*.ex' -delete
)
# sub shell to avoid lossing our current dir
(
# Pull in code from our project
GIT_WORK_TREE="$WORKING_DIR" $GIT_PATH checkout -f
)
(
#build the package
cd $WORKING_DIR
$DPKG_BUILDPACKAGE -A
)
# make sure that the repository exists
if [ ! -e "$REPO_ROOT/binary" ]
then
mkdir -p $REPO_ROOT/binary
fi
cp $PACKAGE_FILES $REPO_ROOT/binary
(
cd $REPO_ROOT
dpkg-scanpackages binary /dev/null | gzip -9c > binary/Packages.gz
)