void-packages

Void Source Packages
git clone git://ezup.dev/void-packages.git
Log | Files | Refs | README | LICENSE

register-shell (1214B)


      1#!/bin/sh
      2#
      3# Registers or unregisters a shell in /etc/shells.
      4#
      5# Arguments:	$ACTION = [run/targets]
      6#		$TARGET = [post-install/post-remove]
      7#		$PKGNAME
      8#		$VERSION
      9#		$UPDATE = [yes/no]
     10#
     11ACTION="$1"
     12TARGET="$2"
     13PKGNAME="$3"
     14VERSION="$4"
     15UPDATE="$5"
     16
     17case "$ACTION" in
     18targets)
     19	echo "post-install post-remove"
     20	;;
     21run)
     22	[ "$TARGET" != "post-install" -a "$TARGET" != "post-remove" ] && exit 1
     23
     24	if [ -z "$register_shell" ]; then
     25		echo "Trigger register-shell: empty \$register_shell!"
     26		exit 1
     27	fi
     28
     29	case "$TARGET" in
     30	post-install)
     31		if [ ! -f etc/shells ]; then
     32			for f in ${register_shell}; do
     33				echo $f >> etc/shells
     34				echo "Registered $f into /etc/shells."
     35			done
     36			chmod 644 etc/shells
     37		else
     38			for f in ${register_shell}; do
     39				if ! grep -qFx "$f" etc/shells; then
     40					echo "$f" >> etc/shells
     41					echo -n "Registered $f into "
     42					echo "/etc/shells."
     43				fi
     44			done
     45		fi
     46		;;
     47	post-remove)
     48		if [ -f etc/shells ]; then
     49			for f in ${register_shell}; do
     50				if grep -q $f etc/shells; then
     51					shell=$(echo $f|sed "s|\\/|\\\/|g")
     52					sed -i -e "/$shell/d" etc/shells
     53					echo -n "Unregistered $f from "
     54					echo "/etc/shells."
     55				fi
     56			done
     57		fi
     58		;;
     59	esac
     60	;;
     61*)
     62	exit 1
     63	;;
     64esac
     65
     66exit 0