diff options
author | B. Watson <yalhcru@gmail.com> | 2019-12-30 05:48:56 -0500 |
---|---|---|
committer | B. Watson <yalhcru@gmail.com> | 2019-12-30 05:48:56 -0500 |
commit | a2cc7e065abd8024392a60b00110073b11e019f1 (patch) | |
tree | 65fcf68d869c36156fecde391895b4f22b529017 /slack | |
parent | 107d068ea14529fdec7d9c0183fb094dd39952a1 (diff) | |
download | elvi-impersonators-a2cc7e065abd8024392a60b00110073b11e019f1.tar.gz |
Do-over...
Diffstat (limited to 'slack')
-rwxr-xr-x | slack | 205 |
1 files changed, 205 insertions, 0 deletions
@@ -0,0 +1,205 @@ +#!/bin/sh + +# elvis: slack -- Search Slackware.com packages + +# 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, +# 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 +# suppose it could support curl instead (or in addition) but I don't +# see the point. + +# The source search is pretty useless, but that's not this script's fault. + +. surfraw || exit 1 + +if [ "$( type -p wget )" = "" ]; then + err "wget is required for this. please install it." +fi + +get_slack_ver() { + local ver sitevers i + + # initially set to the currently running version, if we can. + # unfortunately, this can be wrong: if someone upgraded to -current + # but didn't upgrade aaa_base, it'll still say 14.2 (or whatever they + # upgraded from). + if [ -e /etc/slackware-version ]; then + ver="$( cut -d' ' -f2 < /etc/slackware-version )" + else + # we're not on slackware, assume current + echo "current" + 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. + sitevers="$( + wget -qO- "https://packages.slackware.com" | \ + perl -ne 'print "$1 " while (/<option value="slackware-([\d.]+)"/go)' + )" + + # if we can't get the the list of versions from the site, use contents + # of slackware-version, or current if we ain't got one. probably doesn't + # matter, if the site is broken. + if [ -z "$sitevers" ]; then + echo "${ver:-current}" + return + fi + + # if it's a supported version, use it + for i in $sitevers; do + if [ "$i" = "$ver" ]; then + echo "$ver" + return + fi + done + + # fall back to current + echo "current" + return +} + +get_slack_arch() { + case "$( uname -m )" in + x86_64) SURFRAW_slack_arch="64" ;; + *) SURFRAW_slack_arch="" ;; + esac + echo "$SURFRAW_slack_arch" +} + +w3_config_hook() { + def SURFRAW_slack_ver "$( get_slack_ver )" + def SURFRAW_slack_arch "$( get_slack_arch )" + def SURFRAW_slack_mode "package" + def SURFRAW_slack_sets "eps" +} + +w3_usage_hook() { + local defarch + [ "$SURFRAW_slack_arch" = 64 ] && defarch=64 || defarch=32 + cat <<EOF +Usage: $w3_argv0 [options] [search words]... +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). + -C, -cur Same as -v=current + -32/-i586, -64/-x86_64 Architecture (default -$defarch) + -pa, -pkg, -P Package search (default) + -d, -desc Description search + -l, -label Label search + -c, -content Content search + -s=<sets> Search sets, <sets> may consist of: + e = extra + P = pasture + p = patches + s = slackware + S = source + t = testing + Default: $SURFRAW_slack_sets + -S, -src Search source (same as -c -sS) + -a, -all Search all sets (same as -s=ePpsSt) +Notes: + - Default version and architecture read from the OS (/etc/slackware-version + and uname -m). You can hardcode them in ~/.config/surfraw/conf (see below). + - Search modes: "package" looks at package names, "description" + looks at the .txt files named after the packages (created from the + slack-desc), "label" looks at the first line of .txt file, and "content" + looks at the contents of packages. + - "content" searches are for finding out which package a file belongs to. + Be aware that symlinks aren't found by this, although if the symlink + exists on the local system, its target will be used instead. + - The source search is basically useless without "content" mode. Actually + it's pretty useless anyway. + - Defaults can be set in the config file "~/.config/surfraw/conf". Example: +SURFRAW_slack_ver=14.2 +SURFRAW_slack_arch=64 +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 + 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 +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" ;; + -d*) SURFRAW_slack_mode="description" ;; + -l*) SURFRAW_slack_mode="label" ;; + -c*) SURFRAW_slack_mode="content" ;; + -s*=*) SURFRAW_slack_sets="$optarg" ;; + -S*|-src*) SURFRAW_slack_sets="S" + SURFRAW_slack_mode="content" ;; + -a*) SURFRAW_slack_sets="ePpsSt" ;; + *) return 1 ;; + esac + return 0 +} + +w3_config +w3_parse_args "$@" + +url="https://packages.slackware.com/" + +# try to make content search more user-friendlier. +if [ "$SURFRAW_slack_mode" = "content" ]; then + if echo "$w3_args" | grep -q ^/; then + # resolve symlink, if possible + w3_args_new="$( readlink -e "$w3_args" )" + [ -n "$w3_args_new" ] && w3_args="$w3_args_new" + # remove leading /'s since the form fails with them + w3_args="$( echo "$w3_args" | sed 's,^/*,,' )" + fi +fi + +postdata="search=$( w3_url_of_arg $w3_args )" +postdata="${postdata}&release=slackware${SURFRAW_slack_arch}-${SURFRAW_slack_ver}" +postdata="${postdata}&mode=${SURFRAW_slack_mode}" + +# Pick apart sets. Might be a cleaner way to do this. +sets="$( echo "$SURFRAW_slack_sets" | sed 's,\(.\),\1 ,g' )" +for i in $sets; do + case "$i" in + e) postdata="${postdata}&extra=on" ;; + P) postdata="${postdata}&pasture=on" ;; + p) postdata="${postdata}&patches=on" ;; + s) postdata="${postdata}&slackware=on" ;; + S) postdata="${postdata}&source=on" ;; + t) postdata="${postdata}&testing=on" ;; + *) err "invalid -s arg '$i'." ;; + esac +done + +# hardcode number of results, more is always better, right? +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. + +dir="$( mktemp -td sr.slack.XXXXXX )" +[ -d $dir ] || exit 1 +wget $Q -O $dir/slack.html --post-data="$postdata" $url +sed -i "s,= *\"[./]\",=\"$url\",g" $dir/slack.html +w3_browse_url "file://$dir/slack.html" +[ "$SURFRAW_print" = "yes" ] && echo "POST data: $postdata" +rm -rf $dir |