aboutsummaryrefslogtreecommitdiff
path: root/sbodeps
blob: 62561c2f10096c9687040004d365524bb8df0e2b (plain)
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
#!/bin/bash

# This really is a bash script, please don't change to #!/bin/sh

# TODO: rewrite, this is fugly. Maybe use perl instead of bash.

SBOROOT=${SBOROOT:-/home/urchlay/sbogit}
if [ ! -d $SBOROOT ]; then
   SBOROOT=.
fi

SELF="$( echo "$0" | sed 's,.*/,,' )"

usage() {
   cat <<EOF
$SELF: print dependency tree of SBo builds
B. Watson, 20210308. Licensed under WTFPL: Do WTF you want with this.

Usage: $SELF [-i] [-q] [-t] [package [package ...]]

-i   Ignore installed packages (treat everything as not installed).
-q   Output a sbopkg queue file (sqf). With -i, this will be a complete
     queue, with all deps listed. Without -i, the queue file won't contain
     packages that are already installed (which might mean no output at
     all). This is actually the default (-q option not required).
-t   Output a recursive 'tree' listing of dependencies. This used to be
     the default.

A local copy of the slackbuilds.org repository is required, created
with e.g. rsync or 'git clone'. By default, this script assumes
the current directory is the repo of the Slackware version you're
running, but you can set SBOROOT in the environment to use a different
location. Example:

export SBOROOT=/home/bob/sbomirror/14.1

The SBOROOT (or current dir) needs to contain the category directories
(academic, accessibility, audio, etc etc).
EOF
}

print_installed_status() {
   if [ "$IGNORE" = "yes" ]; then
      echo
      return
   fi
   pkg_is_installed $1 >/dev/null && echo " (installed)" || echo " (NOT installed)"
}

find_deps() {
   local i
   local req
   local REQUIRES
   local info=$(/bin/ls $SBOROOT/*/$2/$2.info 2>/dev/null | head -1)

	if [ -z "$info" ]; then
		echo "$SELF: $2: no such package" 1>&2
		RETVAL=1
		return;
	fi

   eval $(grep ^REQUIRES= $info)
   if [ "$REQUIRES" = "" ]; then
      return
   fi
   for req in $REQUIRES; do
      for i in $(seq 1 $1 ); do
         echo -n "   "
      done
      echo -n $req
      if [ "$req" = "%README%" ]; then
         echo
      else
         print_installed_status $req
         if [ "$QUEUE" = "yes" ]; then
            if [ "$IGNORE" = "yes"  ] || ! pkg_is_installed $req ; then
               echo $1 $req >> $QTMPFILE
            fi
         fi
         find_deps $(( $1 + 1 )) $req
      fi
   done
}

QUEUE=yes
while [ "$argsdone" != "yes" ]; do
   case "$1" in
      -h|-help|--help) usage; exit 0 ;;
		-iq|-qi) QUEUE=yes ; IGNORE=yes ; shift ;;
		-it|-ti) QUEUE=no ; IGNORE=yes ; shift ;;
      -t) QUEUE=no ; shift ;;
      -q) QUEUE=yes ; shift ;;
      -i) IGNORE=yes ; shift ;;
      -*) echo "Unknown option $1"; usage; exit 1 ;;
      *) argsdone=yes ;;
   esac
done

if [ "$QUEUE" = "yes" ]; then
   QTMPFILE=${TMP:-/tmp}/sbodeps.$$.$RANDOM
   rm -f $QTMPFILE

   # save old stdout to fd 3, suppress stdout since we don't print our tree
   exec 3>&1 1>/dev/null
fi

if [ ! -e "$SBOROOT/system" ]; then
	echo "$SELF: path \"$SBOROOT\" doesn't look like an SBo repo, set SBOROOT in environment" 1>&2
	exit 1
fi

RETVAL=0

[ "$1" = "" ] && set "$( basename $( pwd ) )"
for arg; do
   [ "$arg" = "." ] && arg="$( basename $( pwd ) )"
   echo -n $arg
   print_installed_status $arg
   if [ "$QUEUE" = "yes" ]; then
  		if ! pkg_is_installed $arg || [ "$IGNORE" = "yes" ]; then
			echo 0 $arg >> $QTMPFILE
		fi
	fi
   find_deps 1 $arg
done

# The queue temp file contains the same info as the regular
# tree, though less human-readable (depth numbers instead of indents).

# To turn it into a .sqf, sort it depth-first, and remove any duplicates
# (can't use sort -u or uniq, as dups might occur at different depths &
# thus not be on consecutive lines).

if [ "$QUEUE" = "yes" -a -e "$QTMPFILE" ]; then
   exec 1>&3 # restore old stdout
   for q in $(sort -nr $QTMPFILE | cut -d' ' -f2); do
      r=seen_$(echo $q | sed 's,[^A-Za-z0-9_],_,g')
      s=${!r} # bash indirect variable ref, yay
      if [ "$s" != "yes" ]; then
         echo $q
         eval $r="yes"
      fi
   done
   rm -f $QTMPFILE
fi

exit $RETVAL