-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpack
More file actions
executable file
·101 lines (90 loc) · 2.66 KB
/
pack
File metadata and controls
executable file
·101 lines (90 loc) · 2.66 KB
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
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
LANG=C
# shellcheck source=../shellib.sh
. "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")/../shellib.sh"
# Set package metadata
# Prepare package
# Prepare package contents
# Prepare package metadata
# Create package
# Clean up
# Output deb package control
# #1 ... package name
# #2 ... full package version
# #3 ... package architecture
# #4 ... package section
# #5 ... package homepage
# #6 ... package maintainer
# #7 ... package description
# Output: deb package control
function out_deb_pkg_control() {
cat <<EOF
Package: $1
Version: $2
Architecture: $3
Section: $4
Homepage: $5
Maintainer: $6
Description: $7
EOF
}
# Pack to a DEB package
function pack_deb() {
# Prepare package metadata
local package_name="${CI_PROJECT_NAME:-${PWD##*/}}"
local package_ver="$1"
local package_arch='all'
local package_file="${package_name}_${package_ver}_$package_arch"
local package_section='libs'
local package_homepage="${CI_PROJECT_URL:-}"
if [ -n "${GITLAB_USER_NAME:-}" ]; then
package_maintainer="$GITLAB_USER_NAME"
if [ -n "${GITLAB_USER_EMAIL:-}" ]; then
package_maintainer="$package_maintainer <$GITLAB_USER_EMAIL>"
fi
else
if [ -n "${USER:-}" ]; then
package_maintainer="$(getent passwd "$USER" | cut -d ':' -f 5 | cut -d ',' -f 1)"
else
package_maintainer='Unknown'
fi
fi
package_desc="${CI_PROJECT_TITLE:-${PWD##*/}}
Simple Bash scripting library."
# Prepare package content
local build_dir='build'
local package_root="$build_dir/$package_file"
local package_deb_dir="$package_root/DEBIAN"
if [ ! -f "$build_dir/shellib.sh" ]; then
err "$build_dir/shellib.sh does not exist, nothing to pack"
return "$status_err"
fi
# Create package content
mkdir -p "$package_deb_dir"
local package_lib_dir="$package_root/usr/lib"
mkdir -p "$package_lib_dir"
cp "$build_dir/shellib.sh" "$package_lib_dir/shellib.sh"
# Create control file
out_deb_pkg_control "$package_name" "$package_ver" "$package_arch" "$package_section" "$package_homepage" "$package_maintainer" "$package_desc" >"$package_deb_dir/control"
# Create package
(
cd "$build_dir" || exit "$status_err"
dpkg-deb --build --root-owner-group "$package_file"
)
# Clean up
rm -rf "$package_root"
}
# Main
function main {
if [ -z "${1+x}" ]; then
err 'Next version expected as the first parameter'
return "$status_err"
fi
pack_deb "$1"
}
# Skip functions execution under test
if [ "${BASH_SOURCE[0]}" == "${0}" ]; then
main "$@"
fi