-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_linux_packages.py
More file actions
461 lines (376 loc) Β· 12.9 KB
/
create_linux_packages.py
File metadata and controls
461 lines (376 loc) Β· 12.9 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
#!/usr/bin/env python3
# ABScanner Complete Linux Package Creator
# Creates packages for multiple Linux distributions
import os
import sys
import subprocess
import shutil
import stat
from pathlib import Path
import tempfile
def create_rpm_package():
"""Create RPM package for Red Hat/CentOS/Fedora systems"""
print("π΄ Creating RPM Package...")
project_root = Path(__file__).parent
# Package information
package_name = "abscanner"
version = "1.0.0"
release = "1"
# Create RPM spec file
spec_content = f"""
Name: {package_name}
Version: {version}
Release: {release}%{{?dist}}
Summary: Advanced Sensitive Data Scanner
License: MIT
URL: https://github.com/CyberSinister/ABScanner
BuildArch: noarch
Requires: python3 >= 3.6
Requires: python3-pip
%description
ABScanner is a powerful tool for detecting sensitive data in files and directories.
It can identify credentials, API keys, passwords, credit card numbers, and other
sensitive information using advanced pattern matching and false positive filtering.
Features:
- Multi-threaded scanning for performance
- Comprehensive pattern detection
- False positive filtering
- Multiple output formats
- Recursive directory scanning
- Configurable patterns and exclusions
%prep
# No preparation needed for pure Python package
%build
# No building needed for pure Python package
%install
rm -rf $RPM_BUILD_ROOT
# Create directories
mkdir -p $RPM_BUILD_ROOT/opt/abscanner
mkdir -p $RPM_BUILD_ROOT/usr/local/bin
mkdir -p $RPM_BUILD_ROOT/usr/share/doc/abscanner
# Copy application files
cp -r %{{_sourcedir}}/main.py $RPM_BUILD_ROOT/opt/abscanner/
cp -r %{{_sourcedir}}/src $RPM_BUILD_ROOT/opt/abscanner/
cp -r %{{_sourcedir}}/config $RPM_BUILD_ROOT/opt/abscanner/
# Copy documentation
if [ -f "%{{_sourcedir}}/README.md" ]; then
cp %{{_sourcedir}}/README.md $RPM_BUILD_ROOT/usr/share/doc/abscanner/
fi
# Create launcher script
cat > $RPM_BUILD_ROOT/usr/local/bin/abscanner << 'EOF'
#!/bin/bash
# ABScanner Launcher Script
SCRIPT_DIR="/opt/abscanner"
cd "$SCRIPT_DIR"
if command -v python3 &> /dev/null; then
python3 main.py "$@"
elif command -v python &> /dev/null; then
python main.py "$@"
else
echo "Error: Python 3 is required but not installed."
echo "Please install Python 3: sudo yum install python3"
exit 1
fi
EOF
chmod +x $RPM_BUILD_ROOT/usr/local/bin/abscanner
%files
/opt/abscanner
/usr/local/bin/abscanner
/usr/share/doc/abscanner
%post
echo "Installing ABScanner dependencies..."
if command -v pip3 &> /dev/null; then
pip3 install colorama lxml openpyxl python-docx python-pptx PyPDF2 xlsxwriter pillow
elif command -v pip &> /dev/null; then
pip install colorama lxml openpyxl python-docx python-pptx PyPDF2 xlsxwriter pillow
fi
echo "ABScanner installation completed!"
echo "Usage: abscanner [directory_to_scan]"
echo "Help: abscanner --help"
%preun
# Pre-uninstall script
echo "Removing ABScanner..."
%postun
# Post-uninstall script
if [ $1 -eq 0 ]; then
echo "ABScanner has been removed."
fi
%changelog
* {get_rpm_date()} CyberSinister <contact@cybersinister.com> - {version}-{release}
- Initial RPM release
- Multi-threaded sensitive data scanning
- Advanced pattern matching with false positive filtering
- Support for multiple file formats
"""
spec_file = project_root / f"{package_name}.spec"
with open(spec_file, 'w') as f:
f.write(spec_content)
print(f"β
RPM spec file created: {spec_file}")
print(f"π To build RPM package:")
print(f" 1. Install rpmbuild: sudo yum install rpm-build")
print(f" 2. Create build directories: rpmdev-setuptree")
print(f" 3. Copy sources to ~/rpmbuild/SOURCES/")
print(f" 4. Build: rpmbuild -ba {spec_file}")
return str(spec_file)
def create_appimage():
"""Create AppImage for universal Linux compatibility"""
print("π¦ Creating AppImage Package...")
project_root = Path(__file__).parent
appimage_script = """#!/bin/bash
# ABScanner AppImage Creator
set -e
echo "Creating ABScanner AppImage..."
# Check if appimagetool is available
if ! command -v appimagetool &> /dev/null; then
echo "Error: appimagetool not found"
echo "Download from: https://appimage.github.io/appimagetool/"
exit 1
fi
# Create AppDir structure
APPDIR="ABScanner.AppDir"
rm -rf "$APPDIR"
mkdir -p "$APPDIR"
# Create directory structure
mkdir -p "$APPDIR/usr/bin"
mkdir -p "$APPDIR/usr/lib/abscanner"
mkdir -p "$APPDIR/usr/share/applications"
mkdir -p "$APPDIR/usr/share/icons/hicolor/256x256/apps"
# Copy application files
cp main.py "$APPDIR/usr/lib/abscanner/"
cp -r src "$APPDIR/usr/lib/abscanner/"
cp -r config "$APPDIR/usr/lib/abscanner/"
# Create launcher
cat > "$APPDIR/usr/bin/abscanner" << 'EOF'
#!/bin/bash
HERE="$(dirname "$(readlink -f "${0}")")"
cd "$HERE/../lib/abscanner"
python3 main.py "$@"
EOF
chmod +x "$APPDIR/usr/bin/abscanner"
# Create desktop entry
cat > "$APPDIR/usr/share/applications/abscanner.desktop" << 'EOF'
[Desktop Entry]
Type=Application
Name=ABScanner
Comment=Advanced Sensitive Data Scanner
Exec=abscanner
Icon=abscanner
Categories=Utility;Security;
Terminal=true
EOF
# Copy icon if available
if [ -f "abscanner.png" ]; then
cp abscanner.png "$APPDIR/usr/share/icons/hicolor/256x256/apps/abscanner.png"
elif [ -f "abscanner.ico" ]; then
# Convert ICO to PNG if needed
if command -v convert &> /dev/null; then
convert abscanner.ico "$APPDIR/usr/share/icons/hicolor/256x256/apps/abscanner.png"
fi
fi
# Create AppRun
cat > "$APPDIR/AppRun" << 'EOF'
#!/bin/bash
HERE="$(dirname "$(readlink -f "${0}")")"
export PATH="$HERE/usr/bin:$PATH"
exec "$HERE/usr/bin/abscanner" "$@"
EOF
chmod +x "$APPDIR/AppRun"
# Copy desktop file to root
cp "$APPDIR/usr/share/applications/abscanner.desktop" "$APPDIR/"
# Copy icon to root
if [ -f "$APPDIR/usr/share/icons/hicolor/256x256/apps/abscanner.png" ]; then
cp "$APPDIR/usr/share/icons/hicolor/256x256/apps/abscanner.png" "$APPDIR/"
fi
# Build AppImage
appimagetool "$APPDIR" ABScanner-x86_64.AppImage
echo "β
AppImage created: ABScanner-x86_64.AppImage"
echo "Usage: ./ABScanner-x86_64.AppImage [options]"
"""
appimage_script_path = project_root / "create_appimage.sh"
with open(appimage_script_path, 'w') as f:
f.write(appimage_script)
# Make executable
appimage_script_path.chmod(appimage_script_path.stat().st_mode | stat.S_IEXEC)
print(f"β
AppImage creation script: {appimage_script_path}")
print(f"π Usage:")
print(f" chmod +x create_appimage.sh")
print(f" ./create_appimage.sh")
return str(appimage_script_path)
def create_snap_package():
"""Create Snap package for universal Linux distribution"""
print("π¦ Creating Snap Package...")
project_root = Path(__file__).parent
snapcraft_yaml = """name: abscanner
base: core22
version: '1.0.0'
summary: Advanced Sensitive Data Scanner
description: |
ABScanner is a powerful tool for detecting sensitive data in files and directories.
It can identify credentials, API keys, passwords, credit card numbers, and other
sensitive information using advanced pattern matching and false positive filtering.
Features:
- Multi-threaded scanning for performance
- Comprehensive pattern detection
- False positive filtering
- Multiple output formats
- Recursive directory scanning
- Configurable patterns and exclusions
grade: stable
confinement: strict
apps:
abscanner:
command: bin/abscanner
plugs:
- home
- removable-media
parts:
abscanner:
plugin: python
source: .
python-requirements:
- colorama
- lxml
- openpyxl
- python-docx
- python-pptx
- PyPDF2
- xlsxwriter
- pillow
override-build: |
craftctl default
# Create wrapper script
mkdir -p $CRAFT_PART_INSTALL/bin
cat > $CRAFT_PART_INSTALL/bin/abscanner << 'EOF'
#!/bin/bash
cd $SNAP
python3 main.py "$@"
EOF
chmod +x $CRAFT_PART_INSTALL/bin/abscanner
organize:
main.py: main.py
src: src
config: config
"""
# Create snap directory
snap_dir = project_root / "snap"
snap_dir.mkdir(exist_ok=True)
snapcraft_file = snap_dir / "snapcraft.yaml"
with open(snapcraft_file, 'w') as f:
f.write(snapcraft_yaml)
print(f"β
Snapcraft file created: {snapcraft_file}")
print(f"π To build Snap package:")
print(f" 1. Install snapcraft: sudo snap install snapcraft --classic")
print(f" 2. Build: snapcraft")
print(f" 3. Install locally: sudo snap install --dangerous abscanner_1.0.0_amd64.snap")
return str(snapcraft_file)
def create_flatpak_manifest():
"""Create Flatpak manifest for universal Linux distribution"""
print("π¦ Creating Flatpak Manifest...")
project_root = Path(__file__).parent
flatpak_manifest = """{
"app-id": "com.cybersinister.ABScanner",
"runtime": "org.freedesktop.Platform",
"runtime-version": "22.08",
"sdk": "org.freedesktop.Sdk",
"command": "abscanner",
"finish-args": [
"--share=ipc",
"--filesystem=home",
"--filesystem=/tmp"
],
"modules": [
{
"name": "python3-pip",
"buildsystem": "simple",
"build-commands": [
"pip3 install --no-index --find-links=file://${PWD} --prefix=${FLATPAK_DEST} colorama lxml openpyxl python-docx python-pptx PyPDF2 xlsxwriter pillow"
]
},
{
"name": "abscanner",
"buildsystem": "simple",
"build-commands": [
"mkdir -p /app/lib/abscanner",
"cp main.py /app/lib/abscanner/",
"cp -r src /app/lib/abscanner/",
"cp -r config /app/lib/abscanner/",
"mkdir -p /app/bin",
"cat > /app/bin/abscanner << 'EOF'\\n#!/bin/bash\\ncd /app/lib/abscanner\\npython3 main.py \"$@\"\\nEOF",
"chmod +x /app/bin/abscanner"
],
"sources": [
{
"type": "dir",
"path": "."
}
]
}
]
}"""
manifest_file = project_root / "com.cybersinister.ABScanner.json"
with open(manifest_file, 'w') as f:
f.write(flatpak_manifest)
print(f"β
Flatpak manifest created: {manifest_file}")
print(f"π To build Flatpak:")
print(f" 1. Install flatpak-builder: sudo apt install flatpak-builder")
print(f" 2. Build: flatpak-builder build-dir com.cybersinister.ABScanner.json")
print(f" 3. Install: flatpak-builder --user --install build-dir com.cybersinister.ABScanner.json")
return str(manifest_file)
def get_rpm_date():
"""Get date in RPM changelog format"""
import datetime
return datetime.datetime.now().strftime("%a %b %d %Y")
if __name__ == "__main__":
print("π§ ABScanner Complete Linux Package Creator")
print("=" * 60)
results = {}
# Create all package types
print("Creating multiple Linux package formats...\n")
# RPM Package
try:
rpm_result = create_rpm_package()
results['rpm'] = rpm_result
print()
except Exception as e:
print(f"β RPM creation failed: {e}\n")
# AppImage
try:
appimage_result = create_appimage()
results['appimage'] = appimage_result
print()
except Exception as e:
print(f"β AppImage creation failed: {e}\n")
# Snap Package
try:
snap_result = create_snap_package()
results['snap'] = snap_result
print()
except Exception as e:
print(f"β Snap creation failed: {e}\n")
# Flatpak
try:
flatpak_result = create_flatpak_manifest()
results['flatpak'] = flatpak_result
print()
except Exception as e:
print(f"β Flatpak creation failed: {e}\n")
# Summary
print("π Linux Distribution Package Summary")
print("=" * 60)
if results:
print("β
Created package configurations for:")
for pkg_type, path in results.items():
print(f" π¦ {pkg_type.upper()}: {Path(path).name}")
print("\nπ Distribution Strategy:")
print(" π΅ Ubuntu/Debian: Use .deb package (create_debian_package.py)")
print(" π΄ RHEL/CentOS/Fedora: Use .rpm package")
print(" π¦ Universal: Use AppImage or Snap")
print(" πͺ App Stores: Submit Snap/Flatpak to respective stores")
print("\nπ― Recommended Distribution Order:")
print(" 1. Create .deb package for Debian/Ubuntu")
print(" 2. Build RPM for Red Hat family")
print(" 3. Create AppImage for universal compatibility")
print(" 4. Submit to Snap Store and Flathub")
else:
print("β No packages could be created")
print("\nπ Your ABScanner is ready for comprehensive Linux distribution!")