Skip to content

Commit

Permalink
api: remove_repofile_if_unused align closer to deb822 spec
Browse files Browse the repository at this point in the history
  • Loading branch information
theofficialgman committed Feb 25, 2024
1 parent cbaf0d2 commit 1c27875
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions api
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,9 @@ remove_repofile_if_unused() { #Given a sources.list.d file, delete it if nothing
local IFS=$'\n'
done
elif [ "${file##*.}" == "sources" ]; then
#find empty lines in the file that separate stanzas
local empty_lines="$(grep -n '^$' "$file" | awk '{print $1}' | sed 's/:*//g')"
#find empty lines (empty line, line with all spaces, or line with all tabs) in the file that separate stanzas. empty lines are not allowed between fields within a stanza
#https://manpages.ubuntu.com/manpages/jammy/en/man5/deb822.5.html
local empty_lines="$(grep -P -n '^$|^ +$|^\t+$' "$file" | awk '{print $1}' | sed 's/:*//g')"
#get number of lines in file
local num_lines=$(wc -l "$file" | awk '{print $1}')

Expand All @@ -277,9 +278,10 @@ remove_repofile_if_unused() { #Given a sources.list.d file, delete it if nothing
sed -n "$line_start","$line_end"p "$file" | grep -q '^Enabled: no' && continue
# determine what uri, suite, and components are in a file
#each stanza can only have one matching section. if there are multiple matches the last one is used
local uri="$(sed -n "$line_start","$line_end"p "$file" | grep -v '^#' | grep '^URIs: ' | sed 's/URIs: //g' | tail -1)"
local suites="$(sed -n "$line_start","$line_end"p "$file" | grep -v '^#' | grep '^Suites: ' | sed 's/Suites: //g' | tail -1)"
local components="$(sed -n "$line_start","$line_end"p "$file" | grep -v '^#' | grep '^Components: ' | sed 's/Components: //g' | tail -1)"
#case should be ignored for fields
local uri="$(sed -n "$line_start","$line_end"p "$file" | grep -v '^#' | grep -i '^URIs: ' | sed 's/URIs: //Ig' | tail -1)"
local suites="$(sed -n "$line_start","$line_end"p "$file" | grep -v '^#' | grep -i '^Suites: ' | sed 's/Suites: //Ig' | tail -1)"
local components="$(sed -n "$line_start","$line_end"p "$file" | grep -v '^#' | grep -i '^Components: ' | sed 's/Components: //Ig' | tail -1)"
local IFS=' '
for suite in $suites ;do
if [ -z "$components" ]; then
Expand Down

0 comments on commit 1c27875

Please sign in to comment.