diff options
author | Cecil Hugh Watson <knoppmyth@gmail.com> | 2009-11-25 18:40:21 (GMT) |
---|---|---|
committer | Cecil Hugh Watson <knoppmyth@gmail.com> | 2009-11-25 18:40:21 (GMT) |
commit | f9d8baf1e8d94e1252cbd90999d9f2382cff8a57 (patch) | |
tree | 1424c8c8b9ac2cc086ce7376ec85446ff48919fc /abs/core-testing/LinHES-config-22/myth_user_call | |
parent | b0fcb5694aa74b1098dc1647fa272c157d24b856 (diff) | |
parent | 1e4ef029d3646f3e86bc2a725cbed7ac1e3e6613 (diff) | |
download | linhes_pkgbuild-f9d8baf1e8d94e1252cbd90999d9f2382cff8a57.zip linhes_pkgbuild-f9d8baf1e8d94e1252cbd90999d9f2382cff8a57.tar.gz linhes_pkgbuild-f9d8baf1e8d94e1252cbd90999d9f2382cff8a57.tar.bz2 |
Merge branch 'HEAD' of ssh://cesman@knoppmyth.net/mount/repository/LinHES-PKGBUILD
Diffstat (limited to 'abs/core-testing/LinHES-config-22/myth_user_call')
-rw-r--r-- | abs/core-testing/LinHES-config-22/myth_user_call | 174 |
1 files changed, 174 insertions, 0 deletions
diff --git a/abs/core-testing/LinHES-config-22/myth_user_call b/abs/core-testing/LinHES-config-22/myth_user_call new file mode 100644 index 0000000..0914b03 --- /dev/null +++ b/abs/core-testing/LinHES-config-22/myth_user_call @@ -0,0 +1,174 @@ +#!/bin/bash +#Wrapper script to manage USERNAME accounts + web security +# myth_USERNAME_all -c add -u USERNAME +# myth_USERNAME_all -c delete -u USERNAME +# myth_USERNAME_all -c pass -u USERNAME -p pass +# myth_USERNAME_all -c web -u USERNAME -p pass + +INIT_CHECK=TRUE +FULL_CALL="$@" +function CHROOT_CHECK { + INIT=`ps -p 1 -o comm=` + if [ x$INIT = xrunit ] + then + CHROOT_NEEDED=FALSE + else + CHROOT_NEEDED=TRUE + fi +} + +function store_commands () { + echo "$FULL_CALL" >> /root/myth_user_call.out + chmod 600 /root/myth_user_call.out +} + + +function add_user() { + if [ $CHROOT_NEEDED = TRUE ] + then + echo "calling myth_call_user in chroot to add user" + store_commands + else + echo "adding user $USERNAME" + useradd -m -s /bin/bash $USERNAME -G audio,video,optical,storage,users + usermod -a -G mythtv $USERNAME + + fi + +} + + +function del_user() { + if [ $CHROOT_NEEDED = TRUE ] + then + echo "calling myth_call_user in chroot to delete user" + store_commands + else + echo "removing user $USERNAME" + userdel $USERNAME + fi + +} + + +function pass_change() { + if [ $CHROOT_NEEDED = TRUE ] + then + echo "calling myth_call_user in chroot to change password" + store_commands + else + echo "changing password for $USERNAME" + echo $USERNAME:$PASSWORD | chpasswd + fi + +} + + +function web_security { + + grep -q ${USERNAME}: /etc/lighttpd/lighttpd.user + if [ $? = 0 ] + then + #delete user + sed -i "/${USERNAME}\:/d" /etc/lighttpd/lighttpd.user + fi + echo "${USERNAME}:${PASSWORD}" >> /etc/lighttpd/lighttpd.user + +} + +function ARG_ERR() { + if [ x$OPTARG = "x" ] + then + echo "$SWITCH NEEDS AND ARG" + exit 11 + fi +} + + +function print_help { + + echo "Valid options are:" + echo " -c (add|delete|pass|web)" + echo " -u USERNAMEname" + echo " -p password" + exit 1 +} + +if [ $# -eq 0 ] +then + print_help +fi + +declare -r OPTSTRING="c:u:p:i" +while getopts "$OPTSTRING" SWITCH +do + case $SWITCH in + + c) ARG_ERR + OPERATION=$OPTARG + ;; + u) ARG_ERR + USERNAME=$OPTARG + ;; + p) ARG_ERR + PASSWORD=$OPTARG + ;; + i) INIT_CHECK=FALSE + + esac +done + +if [ $INIT_CHECK = TRUE ] +then + CHROOT_CHECK +else + CHROOT_NEEDED=FALSE +fi + +case $OPERATION in + add) + if [ x$USERNAME = x ] + then + print_help + fi + add_user + ;; + delete) + if [ x$USERNAME = x ] + then + print_help + fi + del_user + ;; + pass) + if [ x$USERNAME = x ] + then + print_help + fi + + if [ x$PASSWORD = x ] + then + print_help + fi + pass_change + ;; + + web) + if [ x$USERNAME = x ] + then + print_help + fi + + + if [ x$PASSWORD = x ] + then + print_help + fi + echo "adding webUSERNAME $USERNAME with pass $PASSWORD" + web_security + ;; + *) print_help + ;; +esac + + |