-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil_package.sh
108 lines (99 loc) · 1.77 KB
/
util_package.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
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
# 更新软件源
function update_repo_cache(){
echo "Updating sources ..."
case $TARGET_OS in
Ubuntu)
apt update
;;
Rocky)
dnf makecache
;;
*)
raise_error "unsupport OS"
;;
esac
if [[ $? -ne 0 ]]; then
raise_error "update failed"
fi
}
# 安装软件
function install_package(){
# package_name
if [[ $# -lt 1 ]]; then
return
else
local pkg_name="$*"
fi
echo "Installing $pkg_name ..."
case $TARGET_OS in
Ubuntu)
apt install -y $pkg_name
;;
Rocky)
dnf install --allowerasing -y $pkg_name
;;
*)
raise_error "unsupport OS"
;;
esac
if [[ $? -ne 0 ]]; then
raise_error "install $pkg_name failed"
fi
}
# 从 git clone
function git_clone(){
if [[ $# -lt 1 ]]; then
return
else
local git_args="$*"
fi
echo "Cloning from $1"
install_package git
git clone --depth 1 ${git_args} || raise_error "git clone $1 failed"
}
# 从 url 安装二进制文件
function install_url(){
if [[ $# -lt 1 ]]; then
return
else
local pkgs_url=$*
fi
echo "Installing $pkgs_url"
install_package curl
local tempdir=$(mktemp -d) || raise_error "make temp dirctory failed"
trap "RM $tempdir" EXIT
cd ${tempdir}
for pkg_url in $pkgs_url;do
echo "Downloading $pkg_url"
local pkg_name=${pkg_url##*/}
curl -L -f -# -o $pkg_name $pkgs_url || raise_error "download $pkg_name failed"
install_package ./$pkg_name
RM $pkg_name
done
cd -
}
# 删除软件
function remove_package(){
# package_name
if [[ $# -lt 1 ]]; then
return
else
local pkg_name="$*"
fi
echo "Removing $pkg_name ..."
case $TARGET_OS in
Ubuntu)
apt --purge remove -y $pkg_name
;;
Rocky)
dnf remove -y $pkg_name
;;
*)
! raise_error "unsupport OS"
;;
esac
if [[ $? -ne 0 ]]; then
raise_error "remove $pkg_name failed"
fi
}