aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Junghans <ottxor@gentoo.org>2013-01-06 17:45:26 -0700
committerChristoph Junghans <ottxor@gentoo.org>2013-01-06 17:45:26 -0700
commit43ca639fb83870d24dc022ba22e3aa6b61d85299 (patch)
tree598862e0f94e5487144bca0be9fc1aa067f1d0c1
parentHappy new year 2013! (diff)
downloadeselect-43ca639fb83870d24dc022ba22e3aa6b61d85299.tar.gz
eselect-43ca639fb83870d24dc022ba22e3aa6b61d85299.tar.bz2
eselect-43ca639fb83870d24dc022ba22e3aa6b61d85299.zip
awk, timezone: added
-rw-r--r--AUTHORS3
-rw-r--r--ChangeLog6
-rw-r--r--modules/awk.eselect159
-rw-r--r--modules/timezone.eselect132
4 files changed, 300 insertions, 0 deletions
diff --git a/AUTHORS b/AUTHORS
index a54f624..fb58161 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -27,3 +27,6 @@ Ryan Hill <dirtyepic@gentoo.org>
Chí-Thanh Christopher Nguyễn <chithanh@gentoo.org>
Modules: mesa
+
+Christoph Junghans <ottxor@gentoo.org>
+ Modules: awk, timezone
diff --git a/ChangeLog b/ChangeLog
index d4c3a67..9499f4e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2013-01-06 Christoph Junghans <ottxor@gentoo.org>
+
+ * modules/awk.eselect: Add awk selection module
+ * modules/timezoe.eselect: Add timezone setting module
+ * AUTHOR: Add myself
+
2013-01-01 Matt Turner <mattst88@gentoo.org>
* modules/opengl.eselect: switch GLES3, bug #444114.
diff --git a/modules/awk.eselect b/modules/awk.eselect
new file mode 100644
index 0000000..61650c4
--- /dev/null
+++ b/modules/awk.eselect
@@ -0,0 +1,159 @@
+# Copyright 1999-2013 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id: $
+
+DESCRIPTION="Manage {,/usr}/bin/awk implementations"
+MAINTAINER="ottxor@gentoo.org"
+VERSION="0.2"
+
+## Functions ##
+
+# find a list of awk symlink targets, best first
+find_targets() {
+ local t
+ for t in \
+ "${EROOT}/usr/bin/gawk" \
+ "${EROOT}/usr/bin/mawk" \
+ "${EROOT}/usr/bin/nawk" \
+ "${EROOT}/bin/busybox" \
+ ; do
+ if [[ -x ${t} ]]; then
+ echo ${t##*/}
+ fi
+ done
+}
+
+# set the awk symlink
+set_symlinks() {
+ local target=${1} targets extension dir i rel_target
+
+ [[ ! -L ${EROOT}/bin/awk && -e ${EROOT}/bin/awk ]] && \
+ die -q "/bin/awk is not a symlink!"
+
+ [[ ! -L ${EROOT}/usr/bin/awk && -e ${EROOT}/usr/bin/awk ]] && \
+ die -q "/usr/bin/awk is not a symlink!"
+
+ if is_number "${target}" && [[ ${target} -ge 1 ]]; then
+ targets=( $(find_targets) )
+ target=${targets[target-1]}
+ fi
+
+ if [[ ${target} == "busybox" ]]; then
+ dir="${EROOT}/bin"
+ else
+ dir="${EROOT}/usr/bin"
+ fi
+
+ [[ -x ${dir}/${target} ]] || die -q "Target '${target}' doesn't appear to be valid!"
+
+ for i in /bin /usr/bin; do
+ rel_target=$(relative_name "${dir}/${target}" "${EROOT}${i}")
+ ln -sf "${rel_target}" "${EROOT}${i}/awk" || \
+ die -q "Couldn't set ${target} ${i}/awk symlink"
+ done
+
+ rm -f "${EROOT}"/usr/share/man/man1/awk.1{,.bz2,.gz,lzma}
+ for x in ".1" ".1.bz2" ".1.gz" ".1.lzma" ; do
+ if [[ -e ${EROOT}/usr/share/man/man1/${target}${x} ]] ; then
+ extension="${x}"
+ break
+ fi
+ done
+
+ #busybox has no man page
+ if [[ -z "${extension}" ]] ; then
+ echo "Couldn't find a man page for ${target}; skipping." 1>&2
+ return 1
+ fi
+
+ if ! ln -s "${target}${extension}" "${EROOT}/usr/share/man/man1/awk${extension}"; then
+ echo "Couldn't create man page symlink for ${target}; skipping." 1>&2
+ return 1
+ fi
+}
+
+### show action ###
+
+describe_show() {
+ echo "Show the current awk implementation"
+}
+
+do_show() {
+ [[ -z ${@} ]] || die -q "Too many parameters"
+
+ write_list_start "Current awk implementation:"
+ if [[ -L ${EROOT}/usr/bin/awk ]]; then
+ write_kv_list_entry "$(basename $(readlink ${ROOT}/usr/bin/awk))" ""
+ elif [[ -e ${EROOT}/usr/bin/awk ]]; then
+ write_kv_list_entry "(not a symlink)" ""
+ else
+ write_kv_list_entry "(unset)" ""
+ fi
+}
+
+### list action ###
+
+describe_list() {
+ echo "List available awk implementations"
+}
+
+do_list() {
+ [[ -z ${@} ]] || die -q "Too many parameters"
+
+ local i targets
+
+ targets=( $(find_targets) )
+ for (( i = 0; i < ${#targets[@]}; i++ )) ; do
+ [[ ${targets[${i}]} == $(basename $(readlink "${EROOT}"/usr/bin/awk)) ]] && \
+ targets[${i}]=$(highlight_marker "${targets[${i}]}")
+ done
+ write_list_start "Available awk implementations:"
+ write_numbered_list -m '(none found)' "${targets[@]}"
+}
+
+### set action ###
+
+describe_set() {
+ echo "Set a new awk implementation"
+}
+
+describe_set_options() {
+ echo "target : Target name or number (from 'list' action)"
+}
+
+describe_set_parameters() {
+ echo "<target>"
+}
+
+do_set() {
+ if [[ -z ${1} ]]; then
+ die -q "Not enough parameters"
+ elif [[ -n ${2} ]]; then
+ die -q "Too many parameters"
+ else
+ set_symlinks "${1}"
+ fi
+}
+
+### update action ###
+
+describe_update() {
+ echo "Automatically update the awk implementation"
+}
+
+describe_update_options() {
+ echo "ifunset : Do not override existing implementation"
+}
+
+do_update() {
+ [[ -z ${1} || ( -z ${2} && ( ${1} == ifunset || ${1} == '--if-unset' ) ) ]] || \
+ die -q "Usage error"
+
+ [[ ( ${1} == ifunset || ${1} == '--if-unset' ) \
+ && -L ${EROOT}/usr/bin/awk && -x ${EROOT}/usr/bin/awk ]] && \
+ return
+
+ set_symlinks 1
+}
+
+# vim: set syn=sh :
diff --git a/modules/timezone.eselect b/modules/timezone.eselect
new file mode 100644
index 0000000..d2abd57
--- /dev/null
+++ b/modules/timezone.eselect
@@ -0,0 +1,132 @@
+# Copyright 1999-2013 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id: $
+
+DESCRIPTION="Manages timezone selection"
+MAINTAINER="ottxor@gentoo.org"
+VERSION="0.2"
+
+ZONE_DIR="${EROOT}/usr/share/zoneinfo"
+## Functions ##
+
+# find a list of zones in ZONE_DIR
+find_targets() {
+ local t
+ [[ -d ${ZONE_DIR}/${1} ]] || die -q "Directory ${1} does not exist in ${ZONE_DIR}"
+ for t in $(find "${ZONE_DIR}/${1}" -type f | sort ) ; do
+ [[ $(file ${t}) = *"timezone data"* ]] && echo ${t#${ZONE_DIR}/}
+ done
+}
+
+### show action ###
+
+describe_show() {
+ echo "Show the current timezone selection"
+}
+
+do_show() {
+ [[ -z ${@} ]] || die -q "Too many parameters"
+
+ local zone
+
+ [[ -f ${EROOT}/etc/timezone ]] && \
+ zone=$(grep -e "^[^#]" "${EROOT}"/etc/timezone)
+
+ write_list_start "Current timezone selection:"
+ if [[ -z ${zone} ]]; then
+ write_kv_list_entry "(unset in ${EROOT}/etc/timezone)" ""
+ elif [[ ! -f ${ZONE_DIR}/${zone} ]]; then
+ write_kv_list_entry "(invalid zone in ${EROOT}/etc/localtime)" ""
+ elif [[ -f ${EROOT}/etc/localtime ]]; then
+ cmp -s "${ZONE_DIR}/${zone}" "${EROOT}/etc/localtime" && \
+ write_kv_list_entry "${zone}" "" || \
+ write_kv_list_entry "(set to ${zone} in ${EROOT}/etc/timezone, but differs from ${EROOT}/etc/localtime"
+ else
+ write_kv_list_entry "(set to ${zone} in ${EROOT}/etc/timezone, but unset in ${EROOT}/etc/localtime)" ""
+ fi
+}
+
+### list action ###
+
+describe_list() {
+ echo "List available timezones"
+}
+
+describe_list_options() {
+ echo "basedir : Basedir to show zones from (from 'list' action)"
+}
+
+describe_list_parameters() {
+ echo "[basedir]"
+}
+
+do_list() {
+ local basedir=
+ if [[ -n ${1} ]]; then
+ basedir="${1}"
+ shift
+ [[ -d ${ZONE_DIR}/${basedir} ]] || die -q "Directory ${basedir} does not exist in ${ZONE_DIR}"
+ fi
+
+ [[ -z ${@} ]] || die -q "Too many parameters"
+
+ local i targets
+
+ local zone
+
+ zone=$(grep -e "^[^#]" "${EROOT}"/etc/timezone)
+
+ targets=( $(find_targets "${basedir}") )
+ for (( i = 0; i < ${#targets[@]}; i++ )) ; do
+ [[ ${targets[${i}]} == ${zone} ]] && \
+ targets[${i}]=$(highlight_marker "${targets[${i}]}")
+ done
+ write_list_start "Available timezones:"
+ if [[ -z ${basedir} ]] ; then
+ write_numbered_list -m '(none found)' "${targets[@]}"
+ else
+ for (( i = 0; i < ${#targets[@]}; i++ )) ; do
+ write_kv_list_entry -p "${targets[i]}" ""
+ done
+ fi
+}
+
+### set action ###
+
+describe_set() {
+ echo "Set a new timezone"
+}
+
+describe_set_options() {
+ echo "target : Target name or number (from 'list' action)"
+}
+
+describe_set_parameters() {
+ echo "<target>"
+}
+
+do_set() {
+ if [[ -z ${1} ]]; then
+ die -q "Not enough parameters"
+ elif [[ -n ${2} ]]; then
+ die -q "Too many parameters"
+ fi
+
+ local target=${1} targets
+
+ if is_number "${target}" && [[ ${target} -ge 1 ]]; then
+ targets=( $(find_targets "") )
+ target=${targets[target-1]}
+ fi
+
+ [[ -f ${ZONE_DIR}/${target} ]] || die -q "Target '${target}' doesn't appear to be valid!"
+
+ #if localtime is a symlink cp would fail
+ rm -f "${EROOT}/etc/localtime" || die -q "Couldn't remove ${EROOT}/etc/localtime"
+ cp "${ZONE_DIR}/${target}" "${EROOT}"/etc/localtime || \
+ die -q "Couldn't copy ${target} to ${EROOT}/etc/localtime"
+ echo "${target}" > "${EROOT}"/etc/timezone || \
+ die -q "Couldn't save ${target} in ${EROOT}/etc/timezone"
+}
+
+# vim: set syn=sh :