Skip to content

Commit

Permalink
fix "remove"
Browse files Browse the repository at this point in the history
  • Loading branch information
boredsquirrel authored Dec 5, 2024
1 parent 523c9f6 commit ff0cf1f
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions copr
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ EOF
# 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=$(
secure-files () {
echo "Securing the repo files against manipulation. Please enter your password one last time."
pkexec sh -c "
chown root:root /etc/yum.repos.d/* && \
Expand All @@ -72,7 +72,19 @@ secure-files=$(
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"

pkexec sh -c '
mv "$result" "$repofilebak" &&\
chown "$USER" "$repofilebak" &&\
echo 'COPR Repository "$reponame" removed.' ||\
echo "ERROR removing COPR repository."
'
}

# Main loop

Expand All @@ -84,13 +96,14 @@ if [[ "$1" == "enable" ]]; then
# test if the repo file already exists
if [[ -e "$repofile" ]]; then
# set the repo to active
sed -i 's/enabled=0/enabled=1/g' "$repofile" && echo "Repository $author/$reponame enabled" || echo "Already enabled or repo not found."
pkexec 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 "$author/$reponame -> $releasever"
curl -fsSL "https://copr.fedorainfracloud.org/coprs/$author/$reponame/repo/fedora-$releasever/$author-$reponame-fedora.repo" | pkexec tee "$repofile" >/dev/null
secure-files
fi
break
;;
*)
echo "Unknown option, exiting."
Expand All @@ -108,37 +121,25 @@ elif [[ "$1" == "disable" ]]; then

# remove the named repo
elif [[ "$1" == "remove" ]]; then
secure-files
# backup the repofile and change owner to user
mkdir ~/COPR

if [[ -e "$repofile" ]]; then
# Backup existing repo file and set ownership to the user
pkexec cp "$repofile" "$repofilebak" &&
pkexec chown "$USER" "$repofilebak" &&
echo "Backup created in your home folder."

# Remove the repo file
pkexec rm "$repofile" &&
echo 'COPR Repository "$author"/"$reponame" removed.' ||
echo "ERROR removing COPR repository."
move-repo
else
# search for the reponame
echo 'Repo with name "$author"/"$reponame"" not found, trying a search...'
repofile=$(grep -ril --include='*.repo' "$reponame" /etc/yum.repos.d/)

result=$(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
read -rp 'Repo "$result" was found. Do you want to backup and remove this repo? (y/N) ' answer
if [[ "${answer,,}" == "y" ]]; then
pkexec cp "$result" "$repofilebak" &&
pkexec chown "$(whoami)" "$repofilebak" &&
pkexec rm "$result" || # && echo 'COPR Repository "$reponame" removed.' \
echo "ERROR removing COPR repository."
move-repo
else
exit 1
fi
fi
fi
Expand Down

0 comments on commit ff0cf1f

Please sign in to comment.