]> sourceware.org Git - newlib-cygwin.git/blob - winsup/cygserver/cygserver-config
cygserver: Only print basename of source in debug output to raise readability
[newlib-cygwin.git] / winsup / cygserver / cygserver-config
1 #!/bin/bash
2 #
3 # This file is part of the Cygwin DLL.
4
5 # Directory where the config files are stored
6 SYSCONFDIR=/etc
7 LOCALSTATEDIR=/var
8
9 progname=$0
10 auto_answer=""
11 service_name=cygserver
12
13 request()
14 {
15 if [ "${auto_answer}" = "yes" ]
16 then
17 echo "$1 (yes/no) yes"
18 return 0
19 elif [ "${auto_answer}" = "no" ]
20 then
21 echo "$1 (yes/no) no"
22 return 1
23 fi
24
25 answer=""
26 while [ "X${answer}" != "Xyes" -a "X${answer}" != "Xno" ]
27 do
28 echo -n "$1 (yes/no) "
29 read -e answer
30 done
31 if [ "X${answer}" = "Xyes" ]
32 then
33 return 0
34 else
35 return 1
36 fi
37 }
38
39 # Check options
40
41 while :
42 do
43 case $# in
44 0)
45 break
46 ;;
47 esac
48
49 option=$1
50 shift
51
52 case "${option}" in
53 -d | --debug )
54 set -x
55 ;;
56
57 -y | --yes )
58 auto_answer=yes
59 ;;
60
61 -n | --no )
62 auto_answer=no
63 ;;
64
65 -N | --name )
66 service_name=$1
67 shift
68 ;;
69
70 *)
71 echo "usage: ${progname} [OPTION]..."
72 echo
73 echo "This script creates an Cygserver service configuration."
74 echo
75 echo "Options:"
76 echo " --debug -d Enable shell's debug output."
77 echo " --yes -y Answer all questions with \"yes\" automatically."
78 echo " --no -n Answer all questions with \"no\" automatically."
79 echo " --name -N <name> cygserver windows service name."
80 echo
81 exit 1
82 ;;
83
84 esac
85 done
86
87 # Check if running on NT
88 _sys="`uname`"
89 _nt=`expr "${_sys}" : "CYGWIN_NT"`
90
91 # Check for running cygserver processes first.
92 if ps -ef | grep -v grep | grep -q ${service_name}
93 then
94 echo
95 echo "There is a cygserver (${service_name}) already running. Nothing to do, apparently."
96 echo
97 exit 1
98 fi
99
100 # Check for ${SYSCONFDIR} directory
101 if [ -e "${SYSCONFDIR}" -a ! -d "${SYSCONFDIR}" ]
102 then
103 echo
104 echo "${SYSCONFDIR} is existant but not a directory."
105 echo "Cannot create global configuration file."
106 echo
107 exit 1
108 fi
109
110 # Create it if necessary
111 if [ ! -e "${SYSCONFDIR}" ]
112 then
113 mkdir "${SYSCONFDIR}"
114 if [ ! -e "${SYSCONFDIR}" ]
115 then
116 echo
117 echo "Creating ${SYSCONFDIR} directory failed"
118 echo
119 exit 1
120 fi
121 fi
122
123 # Create /var/log if not already existing
124 if [ -f ${LOCALSTATEDIR}/log ]
125 then
126 echo "Creating ${LOCALSTATEDIR}/log failed!"
127 else
128 if [ ! -d ${LOCALSTATEDIR}/log ]
129 then
130 mkdir -p ${LOCALSTATEDIR}/log
131 fi
132 fi
133
134 # Check if cygserver.conf exists. If yes, ask for overwriting
135 if [ -f "${SYSCONFDIR}/cygserver.conf" ]
136 then
137 if request "Overwrite existing ${SYSCONFDIR}/cygserver.conf file?"
138 then
139 rm -f "${SYSCONFDIR}/cygserver.conf"
140 if [ -f "${SYSCONFDIR}/cygserver.conf" ]
141 then
142 echo
143 echo "Can't overwrite. ${SYSCONFDIR}/cygserver.conf is write protected."
144 echo
145 exit 1
146 fi
147 fi
148 fi
149
150 # Create default cygserver.conf from skeleton files in /etc/defaults/etc
151 if [ ! -f "${SYSCONFDIR}/cygserver.conf" ]
152 then
153 echo "Generating ${SYSCONFDIR}/cygserver.conf file"
154 cp "${SYSCONFDIR}/defaults/etc/cygserver.conf" "${SYSCONFDIR}/cygserver.conf"
155 if [ ! -f "${SYSCONFDIR}/cygserver.conf" ]
156 then
157 echo
158 echo "Couldn't create ${SYSCONFDIR}/cygserver.conf."
159 echo "Perhaps there's no default file in ${SYSCONFDIR}/defaults/etc?"
160 echo "Reinstalling Cygwin might help."
161 echo
162 exit 1
163 fi
164 chmod 664 "${SYSCONFDIR}/cygserver.conf"
165 chown 18.544 "${SYSCONFDIR}/cygserver.conf"
166 fi
167
168 # On NT ask if cygserver should be installed as service
169 if [ ${_nt} -gt 0 ]
170 then
171 # But only if it is not already installed
172 if ! cygrunsrv -Q ${service_name} > /dev/null 2>&1
173 then
174 echo
175 echo
176 echo "Warning: The following function requires administrator privileges!"
177 echo
178 echo "Do you want to install cygserver as service?"
179 if request "(Say \"no\" if it's already installed as service)"
180 then
181 if ! cygrunsrv -I ${service_name} -d "CYGWIN cygserver" -p /usr/sbin/cygserver
182 then
183 echo
184 echo "Installation of cygserver as service failed. Please check the"
185 echo "error messages you got. They might give a clue why it failed."
186 echo
187 echo "A good start is either you don't have administrator privileges"
188 echo "or a missing cygrunsrv binary. Please check for both."
189 echo
190 exit 1
191 fi
192 echo
193 echo "The service has been installed under LocalSystem account."
194 echo "To start it, call \`net start ${service_name}' or \`cygrunsrv -S ${service_name}'."
195 fi
196 touch "${LOCALSTATEDIR}/log/cygserver.log"
197 chown 18.544 "${LOCALSTATEDIR}/log/cygserver.log"
198 fi
199 fi
200
201 echo
202 echo "Further configuration options are available by editing the configuration"
203 echo "file ${SYSCONFDIR}/cygserver.conf. Please read the inline information in that"
204 echo "file carefully. The best option for the start is to just leave it alone."
205 echo
206 echo "Basic Cygserver configuration finished. Have fun!"
207 echo
This page took 0.045235 seconds and 5 git commands to generate.