-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcopr
158 lines (131 loc) · 5.7 KB
/
copr
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env bash
set -euo pipefail
# assign variables for author, reponame and releaseversion
author="$(echo "$2" | cut -d '/' -f1)"
reponame="$(echo "$2" | cut -d '/' -f2)"
releasever="$(rpm -E %fedora)"
repofile="/etc/yum.repos.d/_copr_$author-$reponame.repo"
repofilebak="$HOME/COPR/_copr_$author-$reponame.repo"
# The original COPR warning message
question=$(
cat <<EOF
Enabling a Copr repository. Please note that this repository is not part
of the main distribution, and quality may vary.
The Fedora Project does not exercise any power over the contents of
this repository beyond the rules outlined in the Copr FAQ at
<https://docs.pagure.org/copr.copr/user_documentation.html#what-i-can-build-in-copr>,
and packages are not held to any quality or security level.
Please do not file bug reports about these packages in Fedora
Bugzilla. In case of problems, contact the owner of this repository.
Do you really want to enable copr.fedorainfracloud.org/$author/$reponame? [y/N]:
EOF
)
# the helptext
helptext=$(
cat <<EOF
====== Experimental COPR Command in non-DNF Fedora Distributions ======
This Tool is not made or supported by the Fedora Project,
but aims to reproduce the "dnf copr" functionalities for easily adding COPRs.
Usage: copr [OPTION] [ARGUMENT]
Options:
enable Add COPR repository
disable Keep a repo but disable it
remove Remove COPR repository after backing it up
list List all COPR repositories in your repo folder
search Search for a COPR repository by name (in your Browser)
help Display this help text
Argument:
Name of the COPR repository (for search) or "author/repo" (for install and remove)
Examples:
copr enable kdesig/kde-nightly-qt6
copr remove kdesig/kde-nightly-qt6
copr list
copr search bubblejail
For help, write me here: https://discussion.fedoraproject.org/u/boredsquirrel/
EOF
)
##### SECURE REPO FILES #####
# changing unix permissions to make them root-owned and read-only by world
# chang SELinux labels to "system_u:object_r:system_conf_t:s0" like the default Fedora repos
secure-files () {
echo "Securing the repo files against manipulation. Please enter your password one last time."
run0 sh -c "
chown root:root /etc/yum.repos.d/* && \
chmod 744 /etc/yum.repos.d/* && \
chcon -R system_u:object_r:system_conf_t:s0 /etc/yum.repos.d/
" || {
echo "Failed to secure the repo files!"
exit 1
}
}
move-repo () {
# check if backup dir exists, create it when needed
[ ! -d "$HOME/COPR" ] && mkdir -p "$HOME/COPR"
run0 sh -c '
mv "$result" "$repofilebak" &&\
chown "$USER" "$repofilebak" &&\
echo 'COPR Repository "$reponame" removed.' ||\
echo "ERROR removing COPR repository."
'
}
# Main loop
if [[ "$1" == "enable" ]]; then
while true; do
read -rp "$question" yn
case $yn in
[Yy]*)
# test if the repo file already exists
if [[ -e "$repofile" ]]; then
# set the repo to active
run0 sed -i 's/enabled=0/enabled=1/g' "$repofile" && echo "Repository $author/$reponame enabled" || echo "Already enabled or repo not found."
else
# download the repofile
echo "downloading repo '$reponame' from '$author' for Fedora '$releasever'..."
curl -fsSL "https://copr.fedorainfracloud.org/coprs/$author/$reponame/repo/fedora-$releasever/$author-$reponame-fedora.repo" | run0 tee "$repofile" >/dev/null
secure-files
fi
break
;;
*)
echo "Unknown option, exiting."
break
;;
esac
done
# disable a repo
elif [[ "$1" == "disable" ]]; then
sed 's/enabled=1/enabled=0/g' "$repofile" >/dev/null &&
echo "Repository "$author"/"$reponame" disabled." ||
echo "Already disabled or repo not found."
# remove the named repo
elif [[ "$1" == "remove" ]]; then
if [[ -e "$repofile" ]]; then
move-repo
else
# search for the reponame
echo "Repo '$author'/'$reponame' not found, trying a search..."
repofile=$(grep -ril --include='*.repo' "$reponame" /etc/yum.repos.d/)
# if not found, exit
if [[ -z "$result" ]]; then
echo 'No repositories containing "$reponame" were found.'
exit 1
else
# if found, make sure it is the right one
read -rp 'Repo "$result" was found. Do you want to backup and remove this repo? (y/N) ' answer
if [[ "${answer,,}" == "y" ]]; then
move-repo
else
exit 1
fi
fi
fi
# list all installed COPR repositories
elif [[ "$1" == "list" ]]; then
find /etc/yum.repos.d/ -type f -name '_copr*' -exec basename {} \; | sed 's/_copr_//; s/\.repo$//'
# search, this is just implemented through the browser (hey, pip does the same!)
elif [[ "$1" == "search" ]]; then
xdg-open "https://copr.fedorainfracloud.org/coprs/fulltext/?fulltext=$2"
# display the helptext
elif [[ "$1" == "" || "$1" == "-h" || "$1" == "--h" || "$1" == "-help" || "$1" == "--help" || "$1" == "help" ]]; then
echo "$helptext"
fi