forked from igatjens/deb-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPackageDebTools.sh
136 lines (117 loc) · 3.77 KB
/
PackageDebTools.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
130
131
132
133
134
135
136
#!/bin/sh
Main() {
unset VER MANUAL AUTO
while getopts ":v:ma" OPTION >/dev/null 2>&1; do
case $OPTION in
v) VER=$OPTARG ;;
m) MANUAL=true ;;
a) AUTO=true ;;
:) echo >&2 "Option '$OPTARG' requires a version to be specified." && exit 1 ;;
*) echo >&2 "Unknown option: '$OPTARG'." && echo "Usage: ${0##*/} [-v 'version'] [-m] [-a]" && exit 1 ;;
esac
done
if [ -z "$VER" ]; then
echo >&2 "The '-v' option is mandatory and requires a version to be specified." && exit 1
fi
SetVariables
if [ "$AUTO" = true ]; then
echo "Starting automatic mode."
ShowDetails
else
Welcome
fi
}
Cleanup() { rm -R "$TEMP_DIR" >/dev/null 2>&1 && exit; }
trap "Cleanup" INT
SetVariables() {
PKG_NAME=deb-tools
PKG_VER=$VER+deepines
PKG_DEV="Isaías Gätjens M <[email protected]>"
PKG_ARCH=all
PKG_FULL_NAME=${PKG_NAME}_${PKG_VER}_${PKG_ARCH}
SH_DIR="$(pwd -P)"
TEMP_DIR="$(mktemp -d)"
WORK_DIR="$TEMP_DIR/$PKG_FULL_NAME"
}
ShowDetails() {
echo "Packaging details:
Name: $PKG_NAME
Version: $PKG_VER
Architecture: $PKG_ARCH
Final package name: $PKG_FULL_NAME.deb
"
}
Welcome() {
echo "Welcome to '$PKG_NAME' packaging assistant!" && sleep 1
echo "This script will help you in the packaging process." && sleep 1
echo "Press Ctrl+C at any time to cancel the process."
echo
ShowDetails
printf "%s" 'Starting in ' && i=5 && while [ $i -gt 0 ]; do
printf "%u... " "$i" && i=$((i - 1)) && sleep 1
done && printf "%s\n" 'Now!'
echo
}
Open() { # Create file (if needed), open and wait to finish...
if [ "$MANUAL" = true ]; then
touch "$1" >/dev/null 2>&1
echo "Manually checking '$1'..."
mimeopen -n "$1" >/dev/null 2>&1
fi
}
Main "$@"
mkdir -p "$WORK_DIR/DEBIAN"
cd "$WORK_DIR" || exit 1
echo "Copying scripts..."
mkdir -p usr/bin
cp -a "$SH_DIR/Src/." usr/bin
DOC_PATH="usr/share/doc/$PKG_NAME"
echo "Copying docs..."
mkdir -p $DOC_PATH
cp -a "$SH_DIR/Data/Doc/." $DOC_PATH
MAN_PATH="usr/share/man/man1"
echo "Copying manual pages..."
mkdir -p $MAN_PATH
cp -a "$SH_DIR/Data/ManPage/." $MAN_PATH
gzip -r9n "$MAN_PATH/."
echo "Updating changelog..."
CLOG="$DOC_PATH/changelog.Debian"
gunzip "$CLOG.gz"
Open "$CLOG" # (-m) Manually update the changelog file.
# TODO: Use dch (devscripts package) if available.
gzip -9n "$CLOG"
# Generate md5sums
find . -not \( -path ./DEBIAN -prune \) -type f -exec md5sum {} \; |
sed "s|\./||" >DEBIAN/md5sums
# Generate 'Installed-Size' variable.
INSIZE=$(du -s --exclude='DEBIAN/*' | grep -Eo "[0-9]*")
Open "./DEBIAN/" # (-m) Manually update preinst, postinst, etc.
# TODO: Maybe change the section back to "admin" when the new store is available.
GenerateControl() {
cat <<EOF
Package: $PKG_NAME
Version: $PKG_VER
Architecture: $PKG_ARCH
Installed-Size: $INSIZE
Section: devel
Maintainer: $PKG_DEV
Homepage: https://github.com/igatjens/deb-tools
Priority: optional
Pre-Depends: dpkg (>= 1.5)
Depends: dpkg (>= 1.5), sed (>=4.5), grep (>=3.1), fakeroot (>=1.20), coreutils (>=8.20)
Description: Packaging tools
Tools to create, maintain, audit and manage .deb files.
EOF
}
echo "Generating control file..."
GenerateControl >DEBIAN/control
Open "./DEBIAN/control" # (-m) Manually update the control file.
echo "Fixing permissions..." # For lintian mainly.
find . -type d -exec chmod 755 {} \; # Set all directory permissions to 755 (non-standard-dir-perm).
find . -executable -type f -exec chmod 755 {} \; # Set all executable files permissions to 755 (non-standard-executable-perm).
find usr/share -type f -exec chmod 644 {} \; # Set all usr/share file permissions to 644 (non-standard-file-perm).
find usr/bin -type f -exec chmod +x {} \; # Mark each script as executable
echo "Build package..."
fakeroot dpkg-deb --build "$WORK_DIR" "$SH_DIR" # Should use "dpkg-buildpackage -rfakeroot" instead, but no.
echo "Finished!"
Cleanup