#!/bin/bash set -eu # # pac-cyg --- Install tool for cygwin similar to archlinux pacman # # Copyright (C) 2014 10sr # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see . # (http://www.fsf.org/licensing/licenses/gpl.html) use_cowsay=0 _mirrorlist_path=/etc/pac-cyg.mirrorlist _version=0.1.4 _cachedir=/var/cache/pac-cyg _setupdir=/etc/setup _arch= _tmpdir= # newline separated mirrorlist _mirrorlist_default="# main http://mirrors.kernel.org/sourceware/cygwin" _installed_db=$_setupdir/installed.db enable_cowsay=0 if command -v cowsay >/dev/null \ && test -n "$use_cowsay" && test "$use_cowsay" -gt 0 then enable_cowsay=1 fi ##########################33 # Utilities if command -v tput >/dev/null then __tput_bold=`tput bold` __tput_default=`tput sgr0` __tput_yellow=`tput setaf 3` else echo ">>> Executable tput is not available. Install ncurses to enable colorized output" __tput_bold= __tput_default= __tput_yellow= fi _msg(){ if (( $enable_cowsay )) then cowsay "$*" else echo ">> ${__tput_bold}$*${__tput_default}" fi } _warn(){ if (( $enable_cowsay )) >/dev/null then cowsay -d "$*" 1>&2 else echo ">>> ${__tput_yellow}${__tput_bold}$*${__tput_default}" 1>&2 fi } _die(){ _warn "$@" exit 1 } _ask(){ # _ask msg default # _ask use input with prompt MSG # DEFAULT must be y or n printf "$1 " read __reply test -n "$__reply" || __reply="$2" case $__reply in y|Y|yes|YES) return 0;; n|N|no|NO) return 1;; *) return 2;; esac } _detect_arch_or_die(){ case "$HOSTTYPE" in x86_64) echo x86_64;; i686) echo x86;; *) _die Unsupported architecture: $HOSTTYPE;; esac } _download(){ # _download if type wget >/dev/null 2>&1 then wget "$1" -O "$2" # -N elif type curl >/dev/null 2>&1 then curl --url "$1" --output "$2" else _warn No program for download found. _die Install wget or curl from setup.exe first. fi } _get_cache_dir(){ # _get_cache_dir # get cache directory for mirror_url __mirror_dir="$_cachedir/`echo $1 | sed -e 's|/|%2f|g s|:|%3a|g'`/$_arch" mkdir -p "$__mirror_dir" echo "$__mirror_dir" } _check_prepare_mirrorlist(){ # check if $_mirrorlist_path exits, and create newly if not yet with default # value $_mirrorlist_default # TODO: check if mirrorlist is in valid format if test -e $_mirrorlist_path then return fi _msg $_mirrorlist_path not exists yet. creating it echo "$_mirrorlist_default" >$_mirrorlist_path } _cat_mirrorlist(){ # cat mirrorlist with invalid line stripped # grep -v '^#' $_mirrorlist_path | grep '^\w\+\W\+\w\+\W\+$' grep -v '^#' $_mirrorlist_path } _is_installed(){ # _is_installed pkgname # fail if pkgname is not installed yet cut -d " " -f 1 $_installed_db | grep --line-regexp "$1" >/dev/null 2>&1 } # FIXME: make the variable naming consistent: proceeding __ for local variables ############################## # sync operations: install packages, search packages including uninstalled _help_sync(){ cat <<__EOC__ usage: pac-cyg -S [