-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·169 lines (138 loc) · 5.74 KB
/
build.sh
File metadata and controls
executable file
·169 lines (138 loc) · 5.74 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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/bin/bash
set -e
echo "Building UPK .deb package using setuptools approach (Size Optimized)..."
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Check if running as root for installation
if [[ $EUID -eq 0 ]]; then
print_warning "This script should not be run as root for building"
print_warning "Use sudo only when installing the final .deb package"
exit 1
fi
# Read version from VERSION file
VERSION=$(cat upk/VERSION)
print_status "Building UPK version: $VERSION"
# Create temporary directory for packaging
TEMP_DIR=$(mktemp -d)
print_status "Creating temporary directory: $TEMP_DIR"
# Create package structure
mkdir -p "$TEMP_DIR"/{DEBIAN,usr/bin,usr/share/doc/upk,usr/lib/python3/dist-packages/upk}
# Copy source files to package structure
print_status "Copying source files to package structure..."
cp -r upk/* "$TEMP_DIR/usr/lib/python3/dist-packages/upk/"
# Create wrapper script
print_status "Creating wrapper script..."
cat > "$TEMP_DIR/usr/bin/upk" << 'EOF'
#!/bin/bash
# UPK wrapper script
exec python3 -m upk.upk "$@"
EOF
chmod +x "$TEMP_DIR/usr/bin/upk"
print_success "Source files copied and wrapper script created"
# Create bash completion
print_status "Creating bash completion script..."
mkdir -p "$TEMP_DIR/usr/share/bash-completion/completions"
# Check if required dependencies are available for completion generation
if ! python3 -c "import click, rich" &>/dev/null; then
print_warning "Missing Python dependencies (click, rich) required for bash completion generation."
print_status "Attempting to install them..."
pip3 install click rich || { print_error "Failed to install dependencies. Please install 'click' and 'rich' manually."; exit 1; }
fi
# Set PYTHONPATH to current directory to ensure backends can be imported
export PYTHONPATH=$PYTHONPATH:.
_UPK_COMPLETE=bash_source python3 -m upk.upk > "$TEMP_DIR/usr/share/bash-completion/completions/upk"
print_success "Bash completion script created"
# Create control file from template
print_status "Creating control file from template..."
cp "templates/DEBIAN/control" "$TEMP_DIR/DEBIAN/control"
# Replace VERSION_PLACEHOLDER with actual version
sed -i "s/VERSION_PLACEHOLDER/$VERSION/g" "$TEMP_DIR/DEBIAN/control"
# Create postinst script from template
print_status "Creating post-installation script from template..."
cp "templates/DEBIAN/postinst" "$TEMP_DIR/DEBIAN/postinst"
chmod 755 "$TEMP_DIR/DEBIAN/postinst"
# Create postrm script from template
print_status "Creating post-removal script from template..."
cp "templates/DEBIAN/postrm" "$TEMP_DIR/DEBIAN/postrm"
chmod 755 "$TEMP_DIR/DEBIAN/postrm"
# Create changelog dynamically from CHANGELOG.md
print_status "Generating Debian changelog from CHANGELOG.md..."
# We take the first section of CHANGELOG.md (the latest version) and format it
CHANGELOG_CONTENT=$(grep -Pzn '(?s)## \[\d+\.\d+\.\d+\].*?(?=\n## |$)' CHANGELOG.md | tr -d '\0' | sed '1d' | sed 's/^/ /')
cat > "$TEMP_DIR/usr/share/doc/upk/changelog.Debian" << EOL
upk ($VERSION) unstable; urgency=medium
$CHANGELOG_CONTENT
-- undefinederror <github@object.ninja> $(date -R)
EOL
gzip -n -9 "$TEMP_DIR/usr/share/doc/upk/changelog.Debian"
print_success "Debian changelog generated and compressed"
# Create copyright file from template
print_status "Creating copyright file from template..."
cp "templates/usr/share/doc/upk/copyright" "$TEMP_DIR/usr/share/doc/upk/copyright"
# Create README from template
print_status "Creating README from template..."
cp "templates/usr/share/doc/upk/README.Debian" "$TEMP_DIR/usr/share/doc/upk/README.Debian"
# Set proper permissions
print_status "Setting proper permissions..."
find "$TEMP_DIR" -type d -exec chmod 755 {} \;
find "$TEMP_DIR" -type f -exec chmod 644 {} \;
chmod 755 "$TEMP_DIR/usr/bin/upk"
chmod 755 "$TEMP_DIR/DEBIAN/postinst"
chmod 755 "$TEMP_DIR/DEBIAN/postrm"
# Build the package
print_status "Building .deb package..."
HERE="$(pwd)"
cd "$TEMP_DIR"
DEB_FILE_NAME="upk-${VERSION}.deb"
dpkg-deb --build . $DEB_FILE_NAME
# Check if build was successful
if [ $? -eq 0 ]; then
# Return to original directory and copy the built package
cd $HERE
DEB_FILE="$TEMP_DIR/$DEB_FILE_NAME"
if [ -f "$DEB_FILE" ]; then
cp "$DEB_FILE" "$HERE/"
print_success "Package built successfully: $DEB_FILE_NAME"
print_status "Size: $(ls -lh "$DEB_FILE_NAME" | awk '{print $5}')"
# Show package contents
print_status "Package contents:"
dpkg-deb --contents "$DEB_FILE_NAME" | head -20
print_success "Build process completed successfully!"
print_status "To install the package, run: sudo dpkg -i $DEB_FILE_NAME"
else
print_error "Error: No .deb file found in $TEMP_DIR"
print_error "Checking what files exist in temp directory:"
ls -la "$TEMP_DIR"
print_error "Checking current directory for .deb files:"
ls -la *.deb 2>/dev/null || echo "No .deb files found in current directory"
print_error "Checking if dpkg-deb actually created the file:"
ls -la "$TEMP_DIR.deb" 2>/dev/null || echo "File not found at expected location"
print_error "Checking if the file exists but with different permissions:"
find "$TEMP_DIR" -name "*.deb" -type f 2>/dev/null || echo "No .deb files found in temp directory"
exit 1
fi
else
print_error "Package build failed"
exit 1
fi
# Clean up
print_status "Cleaning up temporary files..."
rm -rf "$TEMP_DIR"
print_success "UPK .deb package build completed!"