wip: large changes
This commit is contained in:
62
src/shell.c
Normal file
62
src/shell.c
Normal file
@@ -0,0 +1,62 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
#include <errno.h>
|
||||
#include <lib/err.h>
|
||||
#include <lib/fs.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
int write_shell(char *package, char *license, int year, char *author, char *m)
|
||||
{
|
||||
fs_write(package, "\
|
||||
#!/bin/sh\n\
|
||||
# SPDX-License-Identifier: %s\n\
|
||||
#\n\
|
||||
# %s\n\
|
||||
\n\
|
||||
me=$0\n\
|
||||
scriptversion=\"1.0.0\"\n\
|
||||
\n\
|
||||
version=\"$me $scriptversion\n\
|
||||
\n\
|
||||
Copyright (C) %d %s\n\
|
||||
This is free software; you are free to change and redistribute it.\n\
|
||||
There is NO WARRANTY, to the textent permitted by law.\"\n\
|
||||
\n\
|
||||
usage=\"\\\n\
|
||||
Usage: $me [OPTION]...\n\
|
||||
%s\n\
|
||||
\n\
|
||||
Options:\n\
|
||||
\n\
|
||||
--help print this help and exit\n\
|
||||
--version output version information\"\n\
|
||||
\n\
|
||||
while [ $# -gt 0 ]; do\n\
|
||||
case $1 in\n\
|
||||
--help) echo \"$usage\"; exit 0;;\n\
|
||||
--version) echo \"$version\"; exit 0;;\n\
|
||||
-*)\n\
|
||||
echo \"$0: Unknwon option '$1'.\" >&2\n\
|
||||
echo \"$0: Try '--help' for more information.\" >&2\n\
|
||||
exit 1 ;;\n\
|
||||
esac\n\
|
||||
shift\n\
|
||||
done\n\
|
||||
\n\
|
||||
echo \"$0: done.\"\n\
|
||||
\n\
|
||||
# End: %s\
|
||||
",
|
||||
license, m, year, author, m, package);
|
||||
struct stat st;
|
||||
|
||||
if (stat(package, &st) != 0) {
|
||||
fatalfa(errno);
|
||||
}
|
||||
|
||||
mode_t mode = st.st_mode | S_IXUSR;
|
||||
|
||||
if (chmod(package, mode) != 0) {
|
||||
fatalfa(errno);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user