particle-os-modules/modules/dnf/dnf-repolist
fiftydinar fef0f17870
feat: dnf module (#377)
Co-authored-by: xyny <60004820+xynydev@users.noreply.github.com>
Co-authored-by: Gerald Pinder <gmpinder@gmail.com>
Co-authored-by: certifiedfoolio <156134535+cherry-os@users.noreply.github.com>
Co-authored-by: xyny <git@xyny.anonaddy.me>
Co-authored-by: somebody once told me <156134535+certifiedfoolio@users.noreply.github.com>
Co-authored-by: franute <franute@gmail.com>
2025-04-27 14:49:39 +00:00

29 lines
616 B
Bash
Executable file

#!/bin/bash
# convert the output of dnf repolist into json
output=$(dnf repolist -q --all 2>/dev/null)
lines=$(echo "$output" | tail -n +3)
echo "["
echo "$lines" | while read -r line; do
repo_id=$(echo "$line" | awk '{print $1}')
status=$(echo "$line" | awk '{print $NF}')
repo_name=$(echo "$line" | awk '{$1=""; $NF=""; print $0}' | sed -e 's/^ *//g' -e 's/ *$//g')
if [ "$status" = "enabled" ]; then
status=true
else
status=false
fi
cat <<EOF
{
"id":"$repo_id",
"name":"$repo_name",
"is_enabled":$status
},
EOF
done | sed '$s/},/}/'
echo "]"