features.h: support POSIX.1-2024
[newlib-cygwin.git] / winsup / cygserver / cygserver-config
blob373bfd24dd2fbd2fa45f9e1e749a3e09b3e5b300
1 #!/bin/bash
3 # This file is part of the Cygwin DLL.
5 # Directory where the config files are stored
6 SYSCONFDIR=/etc
7 LOCALSTATEDIR=/var
9 progname=$0
10 auto_answer=""
11 service_name=cygserver
13 request()
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
25 answer=""
26 while [ "X${answer}" != "Xyes" -a "X${answer}" != "Xno" ]
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
39 # Check options
41 while :
43 case $# in
45 break
47 esac
49 option=$1
50 shift
52 case "${option}" in
53 -d | --debug )
54 set -x
57 -y | --yes )
58 auto_answer=yes
61 -n | --no )
62 auto_answer=no
65 -N | --name )
66 service_name=$1
67 shift
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
84 esac
85 done
87 # Check if running on NT
88 _sys="`uname`"
89 _nt=`expr "${_sys}" : "CYGWIN_NT"`
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
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
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
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
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
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
164 chmod 664 "${SYSCONFDIR}/cygserver.conf"
165 chown 18.544 "${SYSCONFDIR}/cygserver.conf"
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
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}'."
196 touch "${LOCALSTATEDIR}/log/cygserver.log"
197 chown 18.544 "${LOCALSTATEDIR}/log/cygserver.log"
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