File size: 3,123 Bytes
a4b70d9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/bin/bash
# Debian package build script for g4f

set -e

PACKAGE_NAME="g4f"
VERSION="${G4F_VERSION:-0.0.0-dev}"
ARCHITECTURE="${ARCH:-amd64}"
MAINTAINER="Tekky <support@g4f.ai>"
DESCRIPTION="The official gpt4free repository"
LONG_DESCRIPTION="Various collection of powerful language models"

# Clean up any previous builds
rm -rf debian/

# Create package directory structure
mkdir -p debian/${PACKAGE_NAME}/DEBIAN
mkdir -p debian/${PACKAGE_NAME}/usr/bin
mkdir -p debian/${PACKAGE_NAME}/usr/lib/python3/dist-packages
mkdir -p debian/${PACKAGE_NAME}/usr/share/doc/${PACKAGE_NAME}
mkdir -p debian/${PACKAGE_NAME}/usr/share/applications

# Create control file
cat > debian/${PACKAGE_NAME}/DEBIAN/control << EOF
Package: ${PACKAGE_NAME}
Version: ${VERSION}
Section: python
Priority: optional
Architecture: ${ARCHITECTURE}
Essential: no
Maintainer: ${MAINTAINER}
Description: ${DESCRIPTION}
 ${LONG_DESCRIPTION}
Depends: python3 (>= 3.10), python3-pip, python3-aiohttp, python3-requests
Homepage: https://github.com/xtekky/gpt4free
EOF

# Create postinst script
cat > debian/${PACKAGE_NAME}/DEBIAN/postinst << 'EOF'
#!/bin/bash
set -e

# Install Python dependencies
pip3 install --break-system-packages aiohttp requests brotli pycryptodome nest_asyncio

# Make g4f command available
if [ ! -L /usr/local/bin/g4f ]; then
    ln -s /usr/bin/g4f /usr/local/bin/g4f
fi

echo "g4f installed successfully"
echo "Usage: g4f --help"
EOF

# Create prerm script
cat > debian/${PACKAGE_NAME}/DEBIAN/prerm << 'EOF'
#!/bin/bash
set -e

# Remove symlink if it exists
if [ -L /usr/local/bin/g4f ]; then
    rm -f /usr/local/bin/g4f
fi
EOF

# Make scripts executable
chmod 755 debian/${PACKAGE_NAME}/DEBIAN/postinst
chmod 755 debian/${PACKAGE_NAME}/DEBIAN/prerm

# Install the package files
export PYTHONPATH=""
python3 setup.py install --root=debian/${PACKAGE_NAME} --prefix=/usr --install-lib=/usr/lib/python3/dist-packages --install-scripts=/usr/bin

# Create documentation
cp README.md debian/${PACKAGE_NAME}/usr/share/doc/${PACKAGE_NAME}/
cp LICENSE debian/${PACKAGE_NAME}/usr/share/doc/${PACKAGE_NAME}/copyright
gzip -9 debian/${PACKAGE_NAME}/usr/share/doc/${PACKAGE_NAME}/README.md

# Create desktop file
cat > debian/${PACKAGE_NAME}/usr/share/applications/${PACKAGE_NAME}.desktop << EOF
[Desktop Entry]
Version=1.0
Type=Application
Name=g4f
Comment=${DESCRIPTION}
Exec=/usr/bin/g4f
Icon=application-x-executable
Terminal=false
Categories=Development;Network;
EOF

# Fix permissions
find debian/${PACKAGE_NAME} -type d -exec chmod 755 {} \;
find debian/${PACKAGE_NAME} -type f -exec chmod 644 {} \;
chmod 755 debian/${PACKAGE_NAME}/usr/bin/g4f
chmod 755 debian/${PACKAGE_NAME}/DEBIAN/postinst
chmod 755 debian/${PACKAGE_NAME}/DEBIAN/prerm

# Calculate installed size
INSTALLED_SIZE=$(du -sk debian/${PACKAGE_NAME}/usr | cut -f1)

# Add installed size to control file
echo "Installed-Size: ${INSTALLED_SIZE}" >> debian/${PACKAGE_NAME}/DEBIAN/control

# Build the package
dpkg-deb --build debian/${PACKAGE_NAME} ${PACKAGE_NAME}-${VERSION}-${ARCHITECTURE}.deb

echo "Debian package created: ${PACKAGE_NAME}-${VERSION}-${ARCHITECTURE}.deb"