]>
Commit | Line | Data |
---|---|---|
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 | |
8 | SYSCONFDIR=/etc | |
9 | LOCALSTATEDIR=/var | |
10 | ||
11 | progname=$0 | |
12 | auto_answer="" | |
13 | ||
14 | request() | |
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 | ||
42 | while : | |
43 | do | |
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 | |
80 | done | |
81 | ||
82 | # Check if running on NT | |
83 | _sys="`uname`" | |
84 | _nt=`expr "${_sys}" : "CYGWIN_NT"` | |
85 | ||
86 | # Check for running cygserver processes first. | |
87 | if ps -ef | grep -v grep | grep -q cygserver | |
88 | then | |
89 | echo | |
90 | echo "There is a cygserver already running. Nothing to do, apparently." | |
91 | echo | |
92 | exit 1 | |
93 | fi | |
94 | ||
95 | # Check for ${SYSCONFDIR} directory | |
96 | if [ -e "${SYSCONFDIR}" -a ! -d "${SYSCONFDIR}" ] | |
97 | then | |
98 | echo | |
99 | echo "${SYSCONFDIR} is existant but not a directory." | |
100 | echo "Cannot create global configuration file." | |
101 | echo | |
102 | exit 1 | |
103 | fi | |
104 | ||
105 | # Create it if necessary | |
106 | if [ ! -e "${SYSCONFDIR}" ] | |
107 | then | |
108 | mkdir "${SYSCONFDIR}" | |
109 | if [ ! -e "${SYSCONFDIR}" ] | |
110 | then | |
111 | echo | |
112 | echo "Creating ${SYSCONFDIR} directory failed" | |
113 | echo | |
114 | exit 1 | |
115 | fi | |
116 | fi | |
117 | ||
118 | # Create /var/log if not already existing | |
119 | if [ -f ${LOCALSTATEDIR}/log ] | |
120 | then | |
121 | echo "Creating ${LOCALSTATEDIR}/log failed!" | |
122 | else | |
123 | if [ ! -d ${LOCALSTATEDIR}/log ] | |
124 | then | |
125 | mkdir -p ${LOCALSTATEDIR}/log | |
126 | fi | |
127 | fi | |
128 | ||
129 | # Check if cygserver.conf exists. If yes, ask for overwriting | |
130 | if [ -f "${SYSCONFDIR}/cygserver.conf" ] | |
131 | then | |
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 | |
143 | fi | |
144 | ||
145 | # Create default cygserver.conf from skeleton files in /etc/defaults/etc | |
146 | if [ ! -f "${SYSCONFDIR}/cygserver.conf" ] | |
147 | then | |
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" | |
161 | fi | |
162 | ||
163 | # On NT ask if cygserver should be installed as service | |
164 | if [ ${_nt} -gt 0 ] | |
165 | then | |
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 | |
194 | fi | |
195 | ||
196 | echo | |
197 | echo "Further configuration options are available by editing the configuration" | |
198 | echo "file ${SYSCONFDIR}/cygserver.conf. Please read the inline information in that" | |
199 | echo "file carefully. The best option for the start is to just leave it alone." | |
200 | echo | |
72f11cac CV |
201 | echo "Basic Cygserver configuration finished. Have fun!" |
202 | echo |