diff options
author | B. Watson <yalhcru@gmail.com> | 2019-12-30 07:51:50 -0500 |
---|---|---|
committer | B. Watson <yalhcru@gmail.com> | 2019-12-30 07:52:17 -0500 |
commit | 2541587957c2ae00bdb63b7361ae6b7c66d71c90 (patch) | |
tree | aa988aba6dbf9569121237f17560ab9f1bf9ec31 | |
parent | 310219eb1be874f2480ddbf4fbe472e007a4b2ab (diff) | |
download | elvi-impersonators-2541587957c2ae00bdb63b7361ae6b7c66d71c90.tar.gz |
slack: Support -<version>, rewrite perl stuff in sed
-rwxr-xr-x | slack | 74 |
1 files changed, 49 insertions, 25 deletions
@@ -5,9 +5,9 @@ # Author: B. Watson (yalhcru at gmail) # Licensed under the WTFPL. See http://www.wtfpl.net/txt/copying/ for details. -# Unfortunately we can't use get with this form. Well, we can, +# Unfortunately we can't use GET with this form. Well, we can, # except the checkboxes for "search sets" don't work. So it has -# to be a post request, which means this elvis depends on wget. I +# to be a POST request, which means this elvis depends on wget. I # suppose it could support curl instead (or in addition) but I don't # see the point. @@ -15,9 +15,20 @@ . surfraw || exit 1 -if [ "$( type -p wget )" = "" ]; then - err "wget is required for this. please install it." -fi +check_bins() { + local i missing + for i in "$@"; do + if [ -z "$( type -p $i )" ]; then + warn "required external binary $i not found on PATH." + missing="${missing}$i " + fi + done + if [ -n "$missing" ]; then + err "please install the missing binaries, or adjust PATH (currently \"$PATH\")" + fi +} + +url="https://packages.slackware.com/" get_slack_ver() { local ver sitevers i @@ -34,11 +45,12 @@ get_slack_ver() { return fi - # now check the site, make sure it's a supported version - # TODO: rewrite to use sed or awk? maybe not that big a deal. + # now check the site, make sure it's a supported version. this would + # be easier in perl, but I wanna keep external deps to a minimum. sitevers="$( - wget -qO- "https://packages.slackware.com" | \ - perl -ne 'print "$1 " while (/<option value="slackware-([\d.]+)"/go)' + wget -qO- "$url" | \ + sed 's,<,\n<,g' | \ + sed -n 's/<option *value *= *"slackware-\([^"]*\)".*/\1/p' )" # if we can't get the the list of versions from the site, use contents @@ -86,10 +98,10 @@ Description: Surfraw search Slackware.com packages Local options: -v=<version> Slackware version (default $SURFRAW_slack_ver). - For .0 releases, include the .0 (eg 14.0, not 14). + -<version> Same as -v=<version>. E.g. -14.2 -C, -cur Same as -v=current -32/-i586, -64/-x86_64 Architecture (default -$defarch) - -pa, -pkg, -P Package search (default) + -p, -pkg Package search (default) -d, -desc Description search -l, -label Label search -c, -content Content search @@ -101,7 +113,7 @@ Local options: S = source t = testing Default: $SURFRAW_slack_sets - -S, -src Search source (same as -c -sS) + -S, -src Search source (same as -c -s=S) -a, -all Search all sets (same as -s=ePpsSt) Notes: - Default version and architecture read from the OS (/etc/slackware-version @@ -122,24 +134,24 @@ SURFRAW_slack_mode=package SURFRAW_slack_sets=eps For 32-bit architecture (i586), use: SURFRAW_slack_arch="" - In other words do NOT set it to 32, the only valid values + In other words do NOT set it to 32 (or i586), the only valid values are "64" and "". EOF w3_global_usage } -# have to use -pa/-pkg/-P for "package", not -p as it conflicts with -# the global -p/-print -# -v=<version> does NOT conflict with global -version +# -p conflicts with the global -p, but -print still works. +# -v=<version> does NOT conflict with global -v/-version. w3_parse_option_hook() { opt="$1" optarg="$2" case "$opt" in -v*=*) SURFRAW_slack_ver="$optarg" ;; - -C*|-cur*) SURFRAW_slack_ver="current" ;; -32|-i?86) SURFRAW_slack_arch="" ;; - -64|x86_64) SURFRAW_slack_arch="64" ;; - -pa*|-pk*|-P) SURFRAW_slack_mode="package" ;; + -64|-x86_64) SURFRAW_slack_arch="64" ;; + -[0-9]*) SURFRAW_slack_ver=${opt/-/} ;; + -C*|-cur*) SURFRAW_slack_ver="current" ;; + -p|-p[ak]*) SURFRAW_slack_mode="package" ;; -d*) SURFRAW_slack_mode="description" ;; -l*) SURFRAW_slack_mode="label" ;; -c*) SURFRAW_slack_mode="content" ;; @@ -152,12 +164,23 @@ w3_parse_option_hook() { return 0 } +check_bins wget sed w3_config w3_parse_args "$@" -url="https://packages.slackware.com/" - -# try to make content search more user-friendlier. +# Add .0 if the user asked for e.g. version 13 or 14. +case "$SURFRAW_slack_ver" in + current) ;; + [0-9]*.[0-9]*) ;; + *) SURFRAW_slack_ver="$SURFRAW_slack_ver.0" ;; +esac + +# Try to make content search more user-friendlier: +# 1. The form expects no leading slash, so you'd have to remember to +# search for "bin/sh" instead of "/bin/sh"... +# 2. Symlinks aren't in the search database, so if we're searching for +# a symlink that exists locally, search for its target instead. +# Applying both the above allows us to search for e.g. "/usr/bin/gcc". if [ "$SURFRAW_slack_mode" = "content" ]; then if echo "$w3_args" | grep -q ^/; then # resolve symlink, if possible @@ -192,9 +215,10 @@ postdata="${postdata}&result=1000" # wget should be quiet unless -print is enabled. [ "$SURFRAW_print" = "yes" ] || Q="-q" -# do the post, show the results. -# all the image, css, js URLs are absolute paths so they'll load OK. -# the "Packages" and form target URLs are relative, so fix them with sed. +# Do the post, show the results. +# All the image, css, js URLs are absolute paths so they'll load OK. +# The "Packages" and form target URLs are relative, so fix them with fugly +# sed code. dir="$( mktemp -td sr.slack.XXXXXX )" [ -d $dir ] || exit 1 |