forked from chenchongbiao/dbuilder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbuilder-source
executable file
·132 lines (112 loc) · 3.51 KB
/
dbuilder-source
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
#!/bin/bash
# 尝试使用未设置值的变量,脚本将停止执行
set -o nounset
get_source() {
save_source_path=$(jq -r ".package.save_source_path" $config_file)
if [[ -z $save_source_path ]]; then
echo "代码保存路径为空,请输入数据 (例: /tmp/packages): "
read save_source_path
tmp=$(mktemp)
jq --indent 4 \
--arg save_source_path $save_source_path \
'.package.save_source_path=$save_source_path' $config_file > $tmp &&
mv $tmp $config_file
fi
# 创建文件夹
[ ! -d $save_source_path ] && mkdir -p $save_source_path
version=$(jq -r ".package.version" $config_file)
if [[ -z $version ]]; then
echo "发行版为空,请输入数据 (例: [ buster ] [ buster-backports ] [ bullseye ] [ bookworm ] [ trixie ] [ sid ]): "
read version
tmp=$(mktemp)
jq --indent 4 --arg version $version '.package.version=$version' $config_file > $tmp && mv $tmp $config_file
fi
url="https://packages.debian.org/${version}/${2}"
version_list=(bookworm bullseye buster)
psource_exist=$(curl $url | grep "psource")
if [ -z "$psource_exist" ]; then
for version in "${version_list[@]}";
do
url="https://packages.debian.org/${version}/${2}"
psource_exist=$(curl $url | grep "psource")
[ ! -z "$psource_exist" ] && break
done
fi
info=$(python3 $dbuilder_path/crawler $url)
export psource=$(echo $info | jq -r ".psource") # 导出源码名
export description=$(echo $info | jq -r ".description")
export purl=$(echo $info | jq -r ".purl")
export psource_path=$save_source_path/$psource # 导出软件源码包的路径
mkdir -p $psource_path
cd $psource_path
dget $purl
cat <<EOF
软件包名: ${2}
源码包名: $psource
描述: $description
dsc下载链接: $purl
EOF
# 尝试获取仓库信息
gh repo view deepin-community/$psource &>/dev/null
if [ $? -ne 0 ]; then
# 仓库不存在时执行的操作
cat <<EOF >>/tmp/repos.yml
- repo: $psource #main
group: deepin-sysdev-team
info: $description
EOF
fi
}
check_build_deps() {
get_source "$@"
cd $psource_path
dsc_file=$(basename $(ls ${psource_path}/*.dsc))
if [ ! -e "$psource" ]; then
dpkg-source -x $dsc_file "${psource}"
fi
cd $psource
result=$(echo "n" | sudo apt build-dep .)
echo "$result"
package_name=$(echo "$result" | grep -oP '(Depends|依赖): \K\S+')
# 将提取的包名添加到数组中
package_list=($package_name)
# 遍历打印数组中的包名
for package in "${package_list[@]}"; do
echo " ${2} --- $package;"
done
}
# 进行预处理操作,回退patch,删除一些文件
preproces() {
get_source "$@"
cd $psource_path
export dsc_file=$(ls ${psource_path}/*.dsc)
if [ ! -e "$psource" ]; then
dpkg-source -x $dsc_file "$psource"
fi
# 进入解压后的源代码包
cd $psource
# 回退patch
quilt pop -af
#删除一些隐藏目录
rm -rf .{pc,github,git,gitignore}
found_files=$(find debian -type f -name "*t64*")
if [ -n "$found_files" ]; then
echo "找到以下含有 't64' 的文件:"
echo "$found_files"
read -p "按任意键继续执行..." -n 1 -r
echo
else
echo "没有找到含有 't64' 的文件。"
fi
}
case $1 in
get)
get_source "$@"
;;
deps)
check_build_deps "$@"
;;
pre)
preproces "$@"
;;
esac