source: alternc/trunk/tools/get_account_by_domain @ 2613

Revision 2613, 3.3 KB checked in by anarcat, 3 years ago (diff)

s/ksh/bash/ in here, i can't believe we still had ksh dependencies...

  • Property svn:executable set to *
Line 
1#!/bin/bash
2#
3# $Id: get_account_by_domain 22 2005-04-11 17:21:15Z jerome $
4# ----------------------------------------------------------------------
5# AlternC - Web Hosting System
6# Copyright (C) 2002 by the AlternC Development Team.
7# http://alternc.org
8# ----------------------------------------------------------------------
9# Based on:
10# Valentin Lacambre's web hosting softwares: http://altern.org/
11# ----------------------------------------------------------------------
12# LICENSE
13#
14# This program is free software; you can redistribute it and/or
15# modify it under the terms of the GNU General Public License (GPL)
16# as published by the Free Software Foundation; either version 2
17# of the License, or (at your option) any later version.
18#
19# This program is distributed in the hope that it will be useful,
20# but WITHOUT ANY WARRANTY; without even the implied warranty of
21# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22# GNU General Public License for more details.
23#
24# To read the license please visit http://www.gnu.org/copyleft/gpl.html
25# ----------------------------------------------------------------------
26# Original Author of file: Jerome Moinet
27# Purpose of file: gives account by domains or sub-domains
28# ----------------------------------------------------------------------
29#
30PATH=""
31PROG_NAME=get_account_by_domain
32PROG_VERSION=0.1.0
33ALTERNC_ETC=/etc/alternc
34ALTERNC_CONF_FILE=$ALTERNC_ETC/local.sh
35export TEXTDOMAIN=alternc-admintools
36
37# Be sure to use the right programs on Debian
38# and be sure they are there
39id=/usr/bin/id
40mysql=/usr/bin/mysql
41sed=/bin/sed
42gettext=/usr/bin/gettext
43printf=/usr/bin/printf
44
45
46# Must have gettext first to display error messages
47[ -x "$gettext" ] || { echo "Cannot execute $gettext"; exit 1 ; }
48
49for i in $id $mysql $sed $printf
50do
51  ! [ -x "$i" ] && { echo "$($gettext "Unable to execute") ${i}."; exit 1 ; }
52done
53
54
55# Language-dependent messages
56# Uses gettext and mo files.
57# Don't change these messages, change the .po file instead.
58HELP=$($gettext "Gives account hosting domain or sub-domain.")
59USAGE=`$printf "$($gettext "Usage: %s [domain|sub-domain].")" $PROG_NAME`
60NOT_FOUND_MSG=$($gettext "does not exist.")
61NON_ROOT_MSG=$($gettext "You have to be root (uid 0) to execute this program.")
62MISSING_PROG=$($gettext "Unable to execute")
63MISSING_CONF_FILE=`$printf "$($gettext "Can't find %s. Are you sure AlterncC is properly installed?")" $ALTERNC_CONF_FILE`
64MYSQL_UNREACHABLE_DATABASE=`$printf "$($gettext "Cannot access accounts database. Please check either %s or Mysql state.")" $ALTERNC_CONF_FILE`
65
66
67#-------------------------
68# Main
69#-------------------------
70# Must be root
71[ "`$id -u`" != "0" ] && { echo $NON_ROOT_MSG ; exit 1 ; }
72# Must have minimum 1 parameter
73[ -z "$1" ] && { echo $USAGE ; exit 1 ; }
74# Handle -h and --help flags
75[ "$1" = "-h" ] || [ "$1" = "--help" ] && { echo $HELP ; echo $USAGE ; exit 0 ; }
76# Have to get AlternC conf file :
77! [ -f "$ALTERNC_CONF_FILE" ] && { echo $MISSING_CONF_FILE ; exit 1 ; } || . $ALTERNC_CONF_FILE
78mysql="$mysql --defaults-file=/etc/alternc/my.cnf"
79$mysql -e "select count(*) from domaines_standby;" > /dev/null 2>&1
80[ "$?" != 0 ] && { echo "$MYSQL_UNREACHABLE_DATABASE" ; exit 1 ; }
81
82# Does the stuff
83$mysql -B -N -e "select concat(a.login, \" (\", a.mail, \")\") from membres a, sub_domaines b where a.uid = b.compte and concat(if(sub=\"\", \"\", concat(sub, \".\")), domaine)  = \"${1}\";"
84
85
Note: See TracBrowser for help on using the repository browser.