-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigure
More file actions
286 lines (284 loc) · 8.57 KB
/
configure
File metadata and controls
286 lines (284 loc) · 8.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#!/bin/sh
# configure script from SimpleInitGen.
echo "[ Getting Ready ]"
echo
echo -n "Deleting old makefile or makefile.notready file..."
if [ -f ./Makefile ]; then
rm -f ./Makefile
echo "ok."
elif [ -f ./Makefile.notready ]; then
rm -f ./Makefile.notready
echo "ok."
else
echo "files dont exist."
fi
echo -n "Deleting old init.c..."
if [ -f init.c ]; then
rm -f init.c
echo "ok."
else
echo "file dosent exist."
fi
echo -n "checking if GCC is installed..."
if [ -f /usr/bin/gcc ]; then
echo "ok."
else
echo "no."
echo "You must install GCC to compile!"
echo "Install it by typing: sudo apt install gcc"
exit 1
fi
echo -n "checking if Make is installed..."
if [ -f /usr/bin/make ]; then
echo "ok."
else
echo "no."
echo "You must install Make to compile!"
echo "Install it by typing: sudo apt install make"
exit 1
fi
echo -n "checking if strip (from binutils) is installed..."
if [ -f /usr/bin/strip ]; then
echo "ok."
else
echo "no."
echo "You must install binutils to compile!"
echo "Install it by typing: sudo apt install binutils"
exit 1
fi
echo
echo "[ Options ]"
echo
read -p "Mount /dev? (Y/N): " mount_dev
if [ "$mount_dev" = "Y" ] || [ "$mount_dev" = "y" ]; then
MOUNTDEV=1
elif [ "$mount_dev" = "N" ] || [ "$mount_dev" = "n" ]; then
MOUNTDEV=0
else
echo "Invalid answer! Quitting..."
exit 1
fi
read -p "Mount /proc? (Y/N): " mount_proc
if [ "$mount_proc" = "Y" ] || [ "$mount_proc" = "y" ]; then
MOUNTPROC=1
elif [ "$mount_proc" = "N" ] || [ "$mount_proc" = "n" ]; then
MOUNTPROC=0
else
echo "Invalid answer! Quitting..."
exit 1
fi
read -p "Mount /sys? (Y/N): " mount_sys
if [ "$mount_sys" = "Y" ] || [ "$mount_sys" = "y" ]; then
MOUNTSYS=1
elif [ "$mount_sys" = "N" ] || [ "$mount_sys" = "n" ]; then
MOUNTSYS=0
else
echo "Invalid answer! Quitting..."
exit 1
fi
read -p "Mount /tmp? (Y/N): " mount_tmp
if [ "$mount_tmp" = "Y" ] || [ "$mount_tmp" = "y" ]; then
MOUNTTMP=1
elif [ "$mount_tmp" = "N" ] || [ "$mount_tmp" = "n" ]; then
MOUNTTMP=0
else
echo "Invalid answer! Quitting..."
exit 1
fi
read -p "Run daemons/services in /etc/init.rc (if exists)? (Y/N): " run_ds
if [ "$run_ds" = "Y" ] || [ "$run_ds" = "y" ]; then
RUNDAS=1
elif [ "$run_ds" = "N" ] || [ "$run_ds" = "n" ]; then
RUNDAS=0
else
echo "Invalid answer! Quitting..."
exit 1
fi
read -p "Launch shell? (Y/N): " launch_shell
if [ "$launch_shell" = "Y" ] || [ "$launch_shell" = "y" ]; then
LAUNCHSHELL=1
read -p " Enter shell path: " shell_path
if [ -n "$shell_path" ]; then
SHELLPATH=$shell_path
else
echo "Invalid answer! Quitting..."
exit 1
fi
read -p " Launch shell automatically when exited? (Y/N): " auto_launch
if [ "$auto_launch" = "Y" ] || [ "$auto_launch" = "y" ]; then
AUTOLAUNCH=1
elif [ "$auto_launch" = "N" ] || [ "$auto_launch" = "n" ]; then
AUTOLAUNCH=0
else
echo "Invalid answer! Quitting..."
exit 1
fi
elif [ "$launch_shell" = "N" ] || [ "$launch_shell" = "n" ]; then
LAUNCHSHELL=0
else
echo "Invalid answer! Quitting..."
exit 1
fi
read -p "Print verbose messages? (Y/N): " verbose
if [ "$verbose" = "Y" ] || [ "$verbose" = "y" ]; then
VERBOSEMSG=1
elif [ "$verbose" = "N" ] || [ "$verbose" = "n" ]; then
VERBOSEMSG=0
else
echo "Invalid answer! Quitting..."
exit 1
fi
echo
echo "[ Creating Files ]"
echo
echo "Creating Makefile..."
echo "# Generated by SimpleInitGen." >> Makefile.notready
echo "CFLAGS = -static" >> Makefile.notready
echo "all: compile" >> Makefile.notready
echo "compile:" >> Makefile.notready
echo ' @echo "Compiling..."' >> Makefile.notready
echo ' @gcc $(CFLAGS) -o init init.c' >> Makefile.notready
echo ' @echo "Stripping for smaller file size..."' >> Makefile.notready
echo ' @strip init' >> Makefile.notready
echo ' @echo "Done, thanks for using SimpleInitGen!"' >> Makefile.notready
echo "clean:" >> Makefile.notready
echo ' @echo "Cleaning..."' >> Makefile.notready
echo ' @rm -f init' >> Makefile.notready
echo ' @echo "Cleaned, thanks for using SimpleInitGen!"' >> Makefile.notready
mv Makefile.notready Makefile
echo "Creating init.c..."
echo "// Generated by SimpleInitGen." >> init.c
echo "#include <stdio.h>" >> init.c
echo "#include <stdlib.h>" >> init.c
echo "#include <unistd.h>" >> init.c
if [ "$MOUNTDEV" = 1 ] || [ "$MOUNTPROC" = 1 ] || [ "$MOUNTSYS" = 1 ] || [ "$MOUNTTMP" = 1 ]; then
echo "#include <sys/mount.h>" >> init.c
fi
if [ "$VERBOSEMSG" = 1 ]; then
echo "#include <errno.h>" >> init.c
echo "#include <string.h>" >> init.c
fi
echo "#include <sys/types.h>" >> init.c
echo "#include <sys/wait.h>" >> init.c
if [ "$RUNDAS" = 1 ]; then
cat >> init.c <<'EOF'
#include <string.h>
#include <errno.h>
EOF
fi
echo "" >> init.c
echo "int ret;" >> init.c
echo "" >> init.c
if [ "$RUNDAS" = 1 ]; then
echo "int run_services(void) {" >> init.c
echo ' FILE *fp = fopen("/etc/init.rc", "r");' >> init.c
echo " if (!fp) {" >> init.c
if [ "$VERBOSEMSG" = 1 ]; then
cat >> init.c <<'EOF'
printf("Didn't find /etc/init.rc, skipping...\n");
EOF
fi
echo " return 0;" >> init.c
echo " }" >> init.c
echo " char line[256];" >> init.c
echo " while (fgets(line, sizeof(line), fp)) {" >> init.c
cat >> init.c <<'EOF'
line[strcspn(line, "\n")] = '\0';
if (line[0] == '\0' || line[0] == '#') continue;
EOF
if [ "$VERBOSEMSG" = 1 ]; then
echo ' printf("Init: Starting daemon/service (full arguments): %s\\n", line);' >> init.c
fi
echo " pid_t pid = fork();" >> init.c
echo " if (pid == 0) {" >> init.c
echo " char *argv[256];" >> init.c
echo " int argc = 0;" >> init.c
echo ' char *token = strtok(line, " ");' >> init.c
echo " while (token != NULL && argc < (sizeof(argv)/sizeof(argv[0]) - 1)) {" >> init.c
echo " argv[argc++] = token;" >> init.c
echo ' token = strtok(NULL, " ");' >> init.c
echo " }" >> init.c
echo " argv[argc] = NULL;" >> init.c
echo " execvp(argv[0], argv);" >> init.c
echo ' fprintf(stderr, "Init: Exec failed: %s!\\n", strerror(errno));' >> init.c
echo " exit(1);" >> init.c
echo " } else if (pid < 0) {" >> init.c
echo ' fprintf(stderr, "Init: Fork failed: %s!\\n", strerror(errno));' >> init.c
echo " }" >> init.c
echo " }" >> init.c
echo " fclose(fp);" >> init.c
echo " return 0;" >> init.c
echo "}" >> init.c
fi
echo "int main() {" >> init.c
printf ' printf("Init generated by SimpleInitGen.\\n");\n' >> init.c
if [ "$MOUNTDEV" = 1 ]; then
if [ "$VERBOSEMSG" = 1 ]; then
printf ' printf("Init: Mounting /dev...\\n");\n' >> init.c
fi
echo ' ret = mount("devtmpfs", "/dev", "devtmpfs", 0, NULL);' >> init.c
echo ' if (ret != 0) {' >> init.c
echo ' fprintf(stderr, "Init: Mounting failed: %s!\\n", strerror(errno));' >> init.c
echo ' }' >> init.c
fi
if [ "$MOUNTPROC" = 1 ]; then
if [ "$VERBOSEMSG" = 1 ]; then
printf ' printf("Init: Mounting /proc...\\n");\n' >> init.c
fi
echo ' ret = mount("proc", "/proc", "proc", 0, NULL);' >> init.c
echo ' if (ret != 0) {' >> init.c
echo ' fprintf(stderr, "Init: Mounting failed: %s!\\n", strerror(errno));' >> init.c
echo ' }' >> init.c
fi
if [ "$MOUNTSYS" = 1 ]; then
if [ "$VERBOSEMSG" = 1 ]; then
printf ' printf("Init: Mounting /sys...\\n");\n' >> init.c
fi
echo ' ret = mount("sysfs", "/sys", "sysfs", 0, NULL);' >> init.c
echo ' if (ret != 0) {' >> init.c
echo ' fprintf(stderr, "Init: Mounting failed: %s!\\n", strerror(errno));' >> init.c
echo ' }' >> init.c
fi
if [ "$MOUNTTMP" = 1 ]; then
if [ "$VERBOSEMSG" = 1 ]; then
printf ' printf("Init: Mounting /tmp...\\n");\n' >> init.c
fi
echo ' ret = mount("tmpfs", "/tmp", "tmpfs", 0, NULL);' >> init.c
echo ' if (ret != 0) {' >> init.c
echo ' fprintf(stderr, "Init: Mounting failed: %s!\\n", strerror(errno));' >> init.c
echo ' }' >> init.c
fi
if [ "$RUNDAS" = 1 ]; then
echo " run_services();" >> init.c
echo " sleep(2);" >> init.c
fi
if [ "$LAUNCHSHELL" = 1 ]; then
if [ "$AUTOLAUNCH" = 1 ]; then
if [ "$VERBOSEMSG" = 1 ]; then
printf ' printf("Init: Launching shell...\\n");\n' >> init.c
fi
echo ' while(1) {' >> init.c
echo " pid_t pid = fork();" >> init.c
echo " if (pid == 0) {" >> init.c
echo " execl(\"$SHELLPATH\", \"$SHELLPATH\", NULL);" >> init.c
echo " _exit(1);" >> init.c
echo " } else if (pid > 0) {" >> init.c
echo " int status;" >> init.c
echo " waitpid(pid, &status, 0);" >> init.c
if [ "$VERBOSEMSG" = 1 ]; then
printf ' printf("Init: Shell exited, relaunching...\\n");\n' >> init.c
fi
echo " } else {" >> init.c
echo " sleep(1);" >> init.c
echo " }" >> init.c
echo ' }' >> init.c
else
if [ "$VERBOSEMSG" = 1 ]; then
printf ' printf("Init: Launching shell...\\n");\n' >> init.c
fi
echo " execl(\"$SHELLPATH\", \"sh\", NULL);" >> init.c
fi
fi
echo " return 0;" >> init.c
echo "}" >> init.c
echo "Created both Makefile and init.c! Run 'make' to compile."