-
Notifications
You must be signed in to change notification settings - Fork 1
/
dbuilder-source
executable file
·122 lines (103 loc) · 3.22 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
#!/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}
}
case $1 in
get)
get_source "$@"
;;
deps)
check_build_deps "$@"
;;
pre)
preproces "$@"
;;
esac