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