]> sourceware.org Git - newlib-cygwin.git/blame - winsup/cygserver/cygserver-config
Cygwin: set NTDDI_VERSION to enable more recent windows definitions
[newlib-cygwin.git] / winsup / cygserver / cygserver-config
CommitLineData
72f11cac
CV
1#!/bin/bash
2#
72f11cac
CV
3# This file is part of the Cygwin DLL.
4
5# Directory where the config files are stored
6SYSCONFDIR=/etc
7LOCALSTATEDIR=/var
8
9progname=$0
10auto_answer=""
0f3cacfa 11service_name=cygserver
72f11cac
CV
12
13request()
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
41while :
42do
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
0f3cacfa
CV
65 -N | --name )
66 service_name=$1
67 shift
68 ;;
69
72f11cac
CV
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."
0f3cacfa 79 echo " --name -N <name> cygserver windows service name."
72f11cac
CV
80 echo
81 exit 1
82 ;;
83
84 esac
85done
86
87# Check if running on NT
88_sys="`uname`"
89_nt=`expr "${_sys}" : "CYGWIN_NT"`
90
91# Check for running cygserver processes first.
0f3cacfa 92if ps -ef | grep -v grep | grep -q ${service_name}
72f11cac
CV
93then
94 echo
0f3cacfa 95 echo "There is a cygserver (${service_name}) already running. Nothing to do, apparently."
72f11cac
CV
96 echo
97 exit 1
98fi
99
100# Check for ${SYSCONFDIR} directory
101if [ -e "${SYSCONFDIR}" -a ! -d "${SYSCONFDIR}" ]
102then
103 echo
104 echo "${SYSCONFDIR} is existant but not a directory."
105 echo "Cannot create global configuration file."
106 echo
107 exit 1
108fi
109
110# Create it if necessary
111if [ ! -e "${SYSCONFDIR}" ]
112then
113 mkdir "${SYSCONFDIR}"
114 if [ ! -e "${SYSCONFDIR}" ]
115 then
116 echo
117 echo "Creating ${SYSCONFDIR} directory failed"
118 echo
119 exit 1
120 fi
121fi
122
123# Create /var/log if not already existing
124if [ -f ${LOCALSTATEDIR}/log ]
125then
126 echo "Creating ${LOCALSTATEDIR}/log failed!"
127else
128 if [ ! -d ${LOCALSTATEDIR}/log ]
129 then
130 mkdir -p ${LOCALSTATEDIR}/log
131 fi
132fi
133
134# Check if cygserver.conf exists. If yes, ask for overwriting
135if [ -f "${SYSCONFDIR}/cygserver.conf" ]
136then
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
148fi
149
150# Create default cygserver.conf from skeleton files in /etc/defaults/etc
151if [ ! -f "${SYSCONFDIR}/cygserver.conf" ]
152then
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"
b5a7cb02 165 chown 18.544 "${SYSCONFDIR}/cygserver.conf"
72f11cac
CV
166fi
167
168# On NT ask if cygserver should be installed as service
169if [ ${_nt} -gt 0 ]
170then
171 # But only if it is not already installed
0f3cacfa 172 if ! cygrunsrv -Q ${service_name} > /dev/null 2>&1
72f11cac
CV
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
0f3cacfa 181 if ! cygrunsrv -I ${service_name} -d "CYGWIN cygserver" -p /usr/sbin/cygserver
72f11cac
CV
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."
0f3cacfa 194 echo "To start it, call \`net start ${service_name}' or \`cygrunsrv -S ${service_name}'."
72f11cac
CV
195 fi
196 touch "${LOCALSTATEDIR}/log/cygserver.log"
b5a7cb02 197 chown 18.544 "${LOCALSTATEDIR}/log/cygserver.log"
72f11cac
CV
198 fi
199fi
200
201echo
202echo "Further configuration options are available by editing the configuration"
203echo "file ${SYSCONFDIR}/cygserver.conf. Please read the inline information in that"
204echo "file carefully. The best option for the start is to just leave it alone."
205echo
72f11cac
CV
206echo "Basic Cygserver configuration finished. Have fun!"
207echo
This page took 0.229813 seconds and 5 git commands to generate.