Last active
December 15, 2015 01:29
-
-
Save kou1okada/5180307 to your computer and use it in GitHub Desktop.
Subset version apt-file for cygwin.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Copyright (c) 2013 Koichi OKADA. All rights reserved. | |
# This script is distributed under the MIT license. | |
# http://www.opensource.org/licenses/mit-license.php | |
SCRIPTNAME=${0##*/} | |
function usage () | |
{ | |
#-------------------------------------------------------------------- | |
cat <<EOD | |
Usage: ${SCRIPTNAME} [options] action [pattern] | |
subset version apt-file for cygwin | |
Configuration options: | |
--fixed-string -F Do not expand pattern | |
--help -h Show this help. | |
Action: | |
update Update setup.ini by apt-cyg | |
search|find <pattern> Search files in packages | |
list|show <pattern> List files in package | |
EOD | |
#-------------------------------------------------------------------- | |
} | |
function current_cygarch () | |
{ | |
arch | sed -e 's/^i686$/x86/g' | |
} | |
function init () | |
{ | |
CACHEDIR="$(cygpath -u "$(cat /etc/setup/last-cache)")" | |
MIRROR="$(cygpath -u "$(cat /etc/setup/last-mirror)")" | |
MIRRORDIR="$(echo "$MIRROR" | sed -e 's/\//%2f/g' -e 's/:/%3a/g')" | |
ARCH="$(current_cygarch)" | |
case "$ARCH" in | |
x86|x86_64) | |
;; | |
*) | |
echo -e "\e[31;1mError:\e[22m unknown arch: ${ARCH}\e[30m" | |
exit 1 | |
;; | |
esac | |
SETUPINI="${CACHEDIR}/${MIRRORDIR}/${ARCH}/setup.ini" | |
} | |
# check_args action $# requires | |
function check_args () | |
{ | |
if [ $2 -ne $3 ]; then | |
echo -e "\e[31;1mError:\e[22m less parameters for $1\e[30m" | |
echo | |
usage | |
exit 1 | |
fi | |
} | |
function search_packages | |
{ | |
#SETUPINI="$(cygpath -u "$(cat /etc/setup/last-cache)")"/"$(echo "$(cygpath -u "$(cat /etc/setup/last-mirror)")" | sed -e 's/\//%2f/g' -e 's/:/%3a/g')"/$ARCH/setup.ini | |
grep ^@ "$SETUPINI" | awk '{print $2}' | grep "$1" | |
} | |
function list_action () | |
{ | |
local TARGETS | |
if [ "$OPT_F" == "" ]; then | |
while read i; do | |
TARGETS+=("$i") | |
done < <(search_packages "$1") | |
else | |
TARGETS+=("$1") | |
fi | |
for pkg in "${TARGETS[@]}"; do | |
BASE_URL=$(cat /etc/setup/last-mirror) | |
FILE=$(apt-cyg -u describe "$pkg" | grep "^install:" | awk '{print $2}') | |
if [ "$FILE" == "" ]; then | |
echo -e "\e[31;1mError:\e[22m package is not found:\e[30m $1" | |
exit 1 | |
fi | |
case "$FILE" in | |
*.bz2) wget -qO- ${BASE_URL}${FILE} | tar jt ;; | |
*.xz ) wget -qO- ${BASE_URL}${FILE} | tar Jt ;; | |
esac | while read file; do | |
echo $pkg: $file | |
done | |
done | |
} | |
function search_action () | |
{ | |
cygcheck -p "$@" | |
} | |
if [ ! -x "$(which apt-cyg)" ]; then | |
echo -e "\e[31;1mError:\e[30;0m apt-cyg is not found." | |
echo | |
usage | |
exit | |
fi | |
while [ $# -gt 0 ]; do | |
case "$1" in | |
--help|-h) | |
usage | |
exit | |
;; | |
--fixed-string|-F) | |
OPT_F=1 | |
shift | |
;; | |
list|show) | |
check_args $1 $# 2 | |
shift | |
ACTION=list_action | |
ARGV+=("$1") | |
shift | |
;; | |
search|find) | |
check_args $1 $# 2 | |
shift | |
ACTION=search_action | |
ARGV+=("$1") | |
shift | |
;; | |
*) | |
echo -e "\e[31;1mError:\e[22m unknown parameter:\e[30m $1" | |
echo | |
usage | |
exit | |
;; | |
esac | |
done | |
init | |
if [ "$ACTION" != "" ]; then | |
${ACTION} "${ARGV[@]}" | |
else | |
usage | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment