From ca71cdb4c439667278d80cc2abb4d19862fb018a Mon Sep 17 00:00:00 2001 From: Lukc Date: Sat, 4 Sep 2010 13:13:38 +0000 Subject: Eselect port added. --- eselect/Pkgfile | 31 +++++++ eselect/news.eselect | 200 ++++++++++++++++++++++++++++++++++++++++ eselect/package-manager.bash.in | 143 ++++++++++++++++++++++++++++ 3 files changed, 374 insertions(+) create mode 100644 eselect/Pkgfile create mode 100644 eselect/news.eselect create mode 100644 eselect/package-manager.bash.in (limited to 'eselect') diff --git a/eselect/Pkgfile b/eselect/Pkgfile new file mode 100644 index 0000000..273bf29 --- /dev/null +++ b/eselect/Pkgfile @@ -0,0 +1,31 @@ +description="Bash framework for administration and system management tools." +packager="Lukc (XMPP: lukc AT upyum DOT com ; SMTP: lukc AT linkmauve DOT fr)" +maintainer="Lukc (XMPP: lukc AT upyum DOT com ; SMTP: lukc AT linkmauve DOT fr)" +depends=(bash) +url=http://www.gentoo.org/proj/en/eselect/index.xml + +name=eselect +version=1.2.10 +release=1 +archs=(no-arch) +kernels=(no-kernel) + +source=( + http://mirror.ovh.net/gentoo-distfiles/distfiles/$name-$version.tar.bz2 + package-manager.bash.in + news.eselect +) + +includes=(autotools) + +post_build() { + for module in bashcomp binutils editor env pager profile rc visual; do + rm $PKG/$sharedir/eselect/modules/$module.eselect + rm $PKG/$sharedir/man/man5/$module.eselect.5 + done + rm $PKG/$sharedir/eselect/modules/news.eselect + cp news.eselect $PKG/$sharedir/eselect/modules/news.eselect + cp package-manager.bash.in $PKG/$sharedir/eselect/libs/package-manager.bash +} + + diff --git a/eselect/news.eselect b/eselect/news.eselect new file mode 100644 index 0000000..fe3fba7 --- /dev/null +++ b/eselect/news.eselect @@ -0,0 +1,200 @@ +# vim: syntax=sh +# Copyright 2010 Luka Vandervelden +# Distributed under the terms of the New BSD Licence + +DESCRIPTION="Read Nutritive news items" +MAINTAINER="lukc@linkmauve.fr" +VERSION="0.1" + +# % eselect news +#Usage: eselect news +# +#Standard actions: +# help Display help text +# usage Display usage information +# version Display version information +# +#Extra actions: +# purge Purge read news +# unread ... Mark read news items as unread again +# all Mark all news items as unread +# item Number of item (from 'list' action) +# % + +### Global variables + +NEWS_DIR="/srv/news" +READ_FILE=~/.news_read + +### Global functions + +remove_underscores() { + for word in $@; do + echo "`echo "$word" | sed -e "s|_| |g"`" + done +} + +get_author() { + head -n 1 $1 +} + +get_date() { + head -n 2 $1 |\ + grep -v "$(get_author $1)" +} + +get_content() { + local item_lenght=0 + item_lenght=`wc -l $ITEM | cut -d ' ' -f 1` + tail -n $(($item_lenght-3)) $1 +} + +read_item() { + local ITEM="$1" + echo -e "\033[01;34mAuthor: \t$(get_author $ITEM)" + echo -e "\033[01;34mDate: \t$(get_date $ITEM)" + echo -e "\033[01;34m\t---- $(remove_underscores "$ITEM" | sed -e "s|\.new||;s|`dirname $ITEM`/||") ----\033[00m " + echo -e "\033[00m" + local content="$(get_content $ITEM)" + local sed_script=" s|=====$| \\\\033[00m | + s|=====| \\\\033[01;32m | + s| \* | \\\033[00;01m- | + s|$|\\\\033[00m|" + content="`echo "$content" | sed -e "$sed_script"`" + echo -e "$content" + if ! is_read $ITEM; then + mark_read $ITEM + fi +} + +is_read() { + if grep -q "##$1##" $READ_FILE 2>/dev/null; then + return 0 + else + return 1 + fi +} + +mark_read() { + echo "##$1##" >> $READ_FILE +} + +# count Display number of news items +# new Count unread news items (default) +# all Count all news items + +describe_count() { + echo "Display number of news items" +} + +describe_count_options() { + echo "new : Count unread news items (default)" + echo "all : Count all news items" +} + +do_count() { + local params= + local i=0 + case $1 in + ""|new|all);; + *) + die -q "$1: unknown option for count.";; + esac + for file in `ls ${NEWS_DIR}`; do + case $file in + *.new) + case $1 in + ""|new) + if is_read $NEWS_DIR/$file; then + i=$(($i+1)) + fi + ;; + "all") + i=$(($i+1)) + ;; + esac + ;; + esac + done + echo "${i}" +} + +# list List news items + +describe_list() { + echo "List news items" +} + +do_list() { + local params= + local i=0 + local news_list=() + for file in `ls ${NEWS_DIR}`; do + case $file in + *.new) + new_name="`echo $file | sed -e "s|\.new||"`" + news_list=(${news_list[@]} $new_name) + ;; + esac + done + write_list_start "News items:" + if [[ -n "${news_list[@]}" ]]; then + for item in ${news_list[@]}; do + i=$(($i+1)) + if is_read "$NEWS_DIR/${news_list[$(($i-1))]}.new"; then + write_numbered_list_entry $i "\033[01;34m(read) \t`remove_underscores ${news_list[$(($i-1))]}`" + else + write_numbered_list_entry $i "\033[01;34m(unread) \t`remove_underscores ${news_list[$(($i-1))]}`" + fi + done + else + write_kv_list_entry "(none found)" + fi +} + +### read +# read ... Read news items +# --mbox Output in mbox format +# --raw Output in raw format +# new Read unread news items (default) +# all Read all news items +# item Number of item (from 'list' action) + +describe_read() { + echo "Read news items" +} + +describe_read_parameters() { + echo "..." +} + +describe_read_options() { + echo "new : Read unread news items (default)" + echo "all : Read all news items" + echo "item : Number of item (from 'list' action)" +} + +do_read() { + local params= + local i=0 + for file in `ls ${NEWS_DIR}`; do + case $file in + *.new) + i=$(($i+1)) + if [[ "$i" = "$1" ]] || [[ "$1" = "all" ]] || ([[ "$1" = "new" ]] && ! is_read ${NEWS_DIR}/$file); then + read_item ${NEWS_DIR}/$file + case $1 in + all|new) + echo -e " \033[01;34m--------------------\033[00m";; + *) + exit 0;; + esac + fi + ;; + esac + done + if [[ "$1" != "all" ]] && [[ "$1" != "new" ]]; then + die -q "There is no entry with this number." + fi +} + diff --git a/eselect/package-manager.bash.in b/eselect/package-manager.bash.in new file mode 100644 index 0000000..4830fb4 --- /dev/null +++ b/eselect/package-manager.bash.in @@ -0,0 +1,143 @@ +# vim: syntax=sh +# +# Copyright © 2010 Luka Vandervelden +# Some rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer +# in this position and unchanged. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# package_manager +# It is less or more private. Scripts can use it, but that's not to them to +#+ check such things. They should use the next functions instead. +# Returns the package manager to use… \o/ +package_manager() { + local pm + : ${PACKAGE_MANAGER:="prt-get"} + case "${PACKAGE_MANAGER}" in + "prt-get") + if [[ -n "`type -p prt-get`" ]]; then + pm="prt-get" + fi + ;; + "pkg-get") + if [[ -n "`type -p pkg-get`" ]]; then + pm="pkg-get" + fi + pkgutils) + pm=pkgutils;; + esac + echo "${pm}" +} + +# arch +# Returns the arch on which we are. +arch() { + arch=$(uname -m) + case ${arch} in + alpha|ia64|m68k|ppc|ppc64) ;; + arm*) arch=arm ;; + i?86) arch=x86 ;; + mips*) arch=mips ;; + parisc*) arch=hppa ;; + "Power Macintosh") arch=ppc ;; + s390*) arch=s390 ;; + sh*) arch=sh ;; + sparc*) arch=sparc ;; + x86_64) arch=x86_64 ;; + *) write_warning_msg \ + "Unknown architecture. Please submit a bug report including the output: `uname -m`." + return 1 + ;; + esac + echo ${ret} +} + +isinst() { + [[ $# -eq 1 ]] || die "isinst() expects exactly one parameter." + + local pm="`package_manager`" + + case $pm in + prt-get|pkg-get) + $pm isinst $1 &>/dev/null + return $? + ;; + pkgutils) + grep -q "$1#" /var/lib/pkg/db &> /dev/null + return $? + ;; + *) + return 1 + ;; + esac +} + +# Give the version of a package. :) +version() { + [[ $# -eq 1 ]] || die "best_version() expects exactly one parameter." + + local pm="`package_manager`" + case $pm in + prt-get|pkg-get) + $pm info $1 | grep "Version:" | sed "s|Version: *||" 2>/dev/null + return $? + ;; + *) + # prt-get or pkg-get are needed to get the version of a package… + return 1 + ;; + esac +} + +get_repositories() { + local pm="`package_manager`" + + case $pm in + prt-get) + grep prtdir /etc/prt-get.conf | sed "s|prtdir ||" 2>/dev/null + return $? + ;; + pkg-get) + ## FIXME: I don't use this thing. If somebody can help me… O:) + return 0 + ;; + pkgutils) + return 1 + ;; + esac +} + +depinst() { + local pm="`package_manager`" + + case $pm in + prt-get) + prt-get depinst $@ + ;; + pkg-get) + pkg-get depinst $@ + ;; + pkgutils) + return 1 ## TODO: Install a package if present in a “usual” place. + ;; + esac +} + -- cgit v1.2.3-54-g00ecf