Skip to content
Snippets Groups Projects
Commit abd0930f authored by Eric Vidal's avatar Eric Vidal :speech_balloon:
Browse files

-e it used now to specify the editor to use

parent beb0c702
No related branches found
No related tags found
No related merge requests found
......@@ -14,11 +14,13 @@ Handles an environment file and variable of a service depending on the options p
## Interface
```
66-env [ -h ] [ -z ] [ -v verbosity ] [ -t tree ] [ -c version ] [ -s version ] [ -V|L ] [ -r key=value ] [ -i src,dst ] [ -e ] service
66-env [ -h ] [ -z ] [ -v verbosity ] [ -t tree ] [ -c version ] [ -s version ] [ -V|L ] [ -r key=value ] [ -i src,dst ] [ -e editor ] service
```
- This program allows to handle the configuration file of *service* found by default at `%%service_admconf%%/<service>`. Depending of the options passed, you can displays the contents of the file, see the current version used, edits the configuration file and so on.
The edition of the configuration file is the **default** option if neither option is passed.
## Exit codes
- *0* success
......@@ -55,7 +57,7 @@ Handles an environment file and variable of a service depending on the options p
- **-i** *src,dst* : imports configuration file from *src* version to *dst* version. The *src* version and *dst* version need to be separated by a comma without space before and after it. It **do not import** the configuration written by the `66-enable` process but only deal with extra configuration files written by the sysadmin.
- **-e** : edit the configuration file with `EDITOR` set in your system environment. This is the default option if neither option is passed. If you use this option with a `sudo` command, you need to specify the `-E` option at sudo call—see [examples](66-env.html#Usage examples). Note: the upstream file (meaning the one prefixed with a dot) is **never** touched. A copy of the upstream file is copied (if it doesn't exist yet) and the *66-env* tool modifies that file.(see [Service configuration file](service-configuration-file) for further information).
- **-e** *editor*: edit the configuration file with *editor*. If you don't specify this option, it try to found the `EDITOR` variable from the environment variable. Note: the upstream file (meaning the one prefixed with a dot) is **never** touched. A copy of the upstream file is copied (if it doesn't exist yet) and the *66-env* tool modifies that file.(see [Service configuration file](service-configuration-file) for further information).
## Usage examples
......@@ -70,7 +72,7 @@ Handles an environment file and variable of a service depending on the options p
66-env -V ntpd
sudo -E 66-env -e ntpd
sudo 66-env -e nano ntpd
66-env -s 0.1.6 ntpd
```
......
......@@ -40,6 +40,8 @@
#include <66/constants.h>
#include <66/resolve.h>
static char const *EDITOR = 0 ;
enum tasks_e
{
T_UNSET = 0 ,
......@@ -69,13 +71,16 @@ static void run_editor(char const *src, char const *const *envp)
{
log_flow() ;
char *editor = getenv("EDITOR") ;
if (!editor) {
editor = getenv("SUDO_USER") ;
if (editor) log_dieu(LOG_EXIT_SYS,"get EDITOR with sudo command -- please try to use the -E sudo option e.g. sudo -E 66-env -e <service>") ;
else log_dieusys(LOG_EXIT_SYS,"get EDITOR") ;
if (!EDITOR) {
EDITOR = getenv("EDITOR") ;
if (!EDITOR) {
log_die(LOG_EXIT_SYS,"EDITOR is not set at the environment variable -- please use the -e option to specify the editor to use e.g. 66-env -e nano <service>.") ;
}
}
char const *const newarg[3] = { editor, src, 0 } ;
char const *const newarg[3] = { EDITOR, src, 0 } ;
xexec_ae (newarg[0],newarg,envp) ;
}
......@@ -154,7 +159,7 @@ static void replace_value_of_key(stralloc *srclist,char const *key)
if (!stralloc_0(srclist))
log_die_nomem("stralloc") ;
srclist->len-- ;
srclist->len-- ;
stralloc_free(&sakey) ;
}
......@@ -180,7 +185,7 @@ int ssexec_env(int argc, char const *const *argv,char const *const *envp,ssexec_
for (;;)
{
int opt = getopt_args(argc,argv, ">c:s:VLr:ei:", &l) ;
int opt = getopt_args(argc,argv, ">c:s:VLr:e:i:", &l) ;
if (opt == -1) break ;
if (opt == -2) log_die(LOG_EXIT_USER,"options must be set first") ;
switch (opt)
......@@ -224,9 +229,7 @@ int ssexec_env(int argc, char const *const *argv,char const *const *envp,ssexec_
case 'e' :
if (todo != T_UNSET) log_usage(usage_env) ;
todo = T_EDIT ;
EDITOR = l.arg ;
break ;
case 'i' :
......
......@@ -123,7 +123,7 @@ char const *help_svctl =
" -K: kill the service(s) and keep it down\n"
;
char const *usage_env = "66-env [ -h ] [ -z ] [ -v verbosity ] [ -t tree ] [ -c version ] [ -s version ] [ -V|L ] [ -r key=value ] [ -i src,dst ] [ -e ] service" ;
char const *usage_env = "66-env [ -h ] [ -z ] [ -v verbosity ] [ -t tree ] [ -c version ] [ -s version ] [ -V|L ] [ -r key=value ] [ -i src,dst ] [ -e editor ] service" ;
char const *help_env =
"\n"
......@@ -138,7 +138,7 @@ char const *help_env =
" -L: lists the environment variables of the service\n"
" -r: replace the value of the key\n"
" -i: import configuration files from src version to dst version\n"
" -e: edit the file with EDITOR\n"
" -e: edit the file with editor\n"
;
char const *usage_all = "66-all [ -h ] [ -z ] [ -v verbosity ] [ -T timeout ] [ -l live ] [ -t tree ] [ -f ] up|down|unsupervise" ;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment