-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfakedeb.sh
55 lines (46 loc) · 1.43 KB
/
fakedeb.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
#!/bin/bash
# 获取当前的日期,格式化成YYYY-MM-DD
VERSION=$(date +%Y-%m-%d)
# 检查传入的软件名参数,检测通过后赋值变量SOFT_NAME
if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then
echo "fakedeb-shell v1.0.1 (2024-11-02 08:31:29 CST)"
echo "Usage: $0 <SOFT_NAME> [VERSION]"
exit 1
fi
SOFT_NAME="$1"
# 如果提供了版本号参数,则使用它;否则使用当前日期
if [ "$#" -eq 2 ]; then
VERSION="$2"
fi
# 创建deb包的临时目录
TEMP_DIR=$(mktemp -d)
DEB_NAME="${SOFT_NAME}_${VERSION}_all.deb"
CONTROL_DIR="${TEMP_DIR}/DEBIAN"
# 创建必要的目录结构
mkdir -p "${CONTROL_DIR}"
chmod 755 "${CONTROL_DIR}"
# 创建空的DEBIAN/control文件
cat << EOF > "${CONTROL_DIR}/control"
Package: ${SOFT_NAME}
Version: ${VERSION}
Architecture: all
Maintainer: Your Name <[email protected]>
Description: A fake Debian package for ${SOFT_NAME}
EOF
# 使用dpkg-deb打包
if dpkg-deb --build --root-owner-group "${TEMP_DIR}"; then
# 移动输出文件位置
mv "${TEMP_DIR}.deb" ./${DEB_NAME}
# 显示创建的deb包路径
echo "Successful."
echo "Output: ${DEB_NAME}"
else
# 检查dpkg-deb命令是否未安装
if [ $? -eq 127 ]; then
echo "Error: dpkg-deb is not installed. Please install it before running this script."
else
echo "Error: An error occurred while building the Debian package."
fi
fi
# 清理:删除临时目录
rm -rf "${TEMP_DIR}"