Initial CVS repository import (last CVS history was lost)
[mmondor.git] / mmsoftware / mmlib / makefuncs.sh
CommitLineData
47071c2b
MM
1#!/bin/sh
2# $Id: makefuncs.sh,v 1.1 2002/12/11 10:12:36 mmondor Exp $
3
4PATH="$PATH:/bin:/sbin:/usr/bin:/usr/sbin"
5
6show()
7{
8 echo "$@"
9 $@
10}
11
12killbin()
13{
14 echo " Making sure $1 binary is not running"
15 pid=`ps axo pid,ucomm | grep $1 | awk '{print $1}'`
16 if [ ! -z "$pid" ]; then
17 kill $pid 2>/dev/null
18 fi
19}
20
21startbin()
22{
23 echo " Starting $1 binary"
24 $MMPREFIX/sbin/$1 $2 >/dev/null
25}
26
27makebin()
28{
29 echo
30 echo " Building $1"
31 ./makepart.sh
32}
33
34clean()
35{
36 echo
37 echo " Cleaning $1"
38 ./makepart.sh clean
39}
40
41instbin()
42{
43 f2="$MMPREFIX/sbin/$1"
44 instdir "$MMPREFIX/sbin"
45 echo " Installing $1 binary as $f2"
46 cp -f "$1" "$f2"
47 if [ -z "$3" ]; then
48 chown $MMDEFAULTUSER.$MMDEFAULTGROUP "$f2"
49 else
50 chown $MMDEFAULTUSER.$3 "$f2"
51 fi
52 if [ -z "$2" ]; then
53 chmod 755 "$f2"
54 else
55 chmod $2 "$f2"
56 fi
57 ls -l "$f2"
58}
59
60instconf()
61{
62 f2="$MMCONFDIR/$1"
63 instdir "$MMCONFDIR"
64 if [ ! -f "$f2" ]; then
65 echo " Installing $1 configuration file as $f2"
66 cp "$1" "$f2"
67 else
68 echo " Preserving existing $f2 configuration file"
69 fi
70 if [ -z "$3" ]; then
71 chown $MMDEFAULTUSER.$MMDEFAULTGROUP "$f2"
72 else
73 chown $MMDEFAULTUSER.$3 "$f2"
74 fi
75 if [ -z "$2" ]; then
76 chmod 644 "$f2"
77 else
78 chmod $2 "$f2"
79 fi
80 ls -l "$f2"
81}
82
83instman()
84{
85 f2="$MMPREFIX/man/man$2/$1"
86 instdir "$MMPREFIX/man/man$2"
87 echo " Installing $1 man page as $f2"
88 cp "$1" "$f2"
89 chown $MMDEFAULTUSER.$MMDEFAULTGROUP "$f2"
90 chmod 644 "$f2"
91 ls -l "$f2"
92}
93
94instdir()
95{
96 if [ ! -d "$1" ]; then
97 echo " Creating $1 directory"
98 mkdir "$1"
99 else
100 echo " Preserving existing $1 directory"
101 fi
102 if [ -z "$4" ]; then g=$MMDEFAULTGROUP; else g=$4; fi
103 if [ -z "$3" ]; then o=$MMDEFAULTUSER; else o=$3; fi
104 chown $o.$g "$1"
105 if [ -z "$2" ]; then
106 chmod 755 "$1"
107 else
108 chmod $2 "$1"
109 fi
110 ls -ld "$1"
111}
112
113instgroup()
114{
115 g=`grep "$1:" /etc/group`
116 if [ -z "$g" ]; then
117 echo " Creating group $1"
118 groupadd $1
119 else
120 echo " Preserving existing group $1"
121 fi
122}
123
124instuser()
125{
126 u=`grep "$1:" /etc/passwd`
127 if [ -z "$u" ]; then
128 instgroup $2
129 echo " Creating user $1 of group $2"
130 if [ -f /sbin/nologin ]; then
131 useradd -d /unexisting -g $2 -s /sbin/nologin $1
132 else
133 useradd -d /unexisting -g $2 -s /bin/false $1
134 fi
135 else
136 echo " Preserving existing user $1"
137 fi
138}