www.zeroshell.org Forum Index www.zeroshell.org
Linux Distribution for server and embedded devices
 
 SearchSearch  RegisterRegister  UsergroupsUsergroups 
 ProfileProfile  Log inLog in  Log in to check your private messagesPrivate Message 

[Janus / twin Alix2] #6 Hack the GUI to run custom commands

 
Post new topic   Reply to topic    www.zeroshell.org Forum Index -> ZeroShell
View previous topic :: View next topic  
Author Message
PatrickB



Joined: 03 Nov 2012
Posts: 47

PostPosted: Sun Jul 12, 2015 10:06 am    Post subject: [Janus / twin Alix2] #6 Hack the GUI to run custom commands Reply with quote

Hello.

In my post #5 of this series I described scripts performing backup & restore operations.

This is an example of task to be run manually, and doing it from a command in ZS's GUI would be handier than having to open a shell...

In this thread I asked for a customizable page in the GUI to do such things:
http://www.zeroshell.org/forum/viewtopic.php?t=4964

In the meantime, here is the poor solution I found to do it Crying or Very sad


The scripts in the GUI and what is behind

The GUI page SETUP / Scripts/Cron leads to a Script Editor with a list where are predefined some scripts. Then it is possible to add scheduled jobs.

The implementation is done in:

/Database/var/register/system/startup/scripts

Code:
root@janus2> ll /Database/var/register/system/startup/scripts
total 48K
drwxr-xr-x    2 root     root         4.0K May  8 23:09 Backup
drwxr-xr-x    3 root     root         4.0K Feb 21 18:46 NTPupdate-Cron
drwxr-xr-x    3 root     root         4.0K Feb  4  2000 Shibboleth-Cron
drwxr-xr-x    2 root     root         4.0K Jun 27  2008 cpauth
drwxr-xr-x    2 root     root         4.0K Jun 27  2008 cpgw
drwxr-xr-x    2 root     root         4.0K Jun 27  2008 firewallchain
drwxr-xr-x    2 root     root         4.0K Jun 27  2008 nat
drwxr-xr-x    2 root     root         4.0K Jun 26  2008 postboot
drwxr-xr-x    2 root     root         4.0K Jun 27  2008 preboot
drwxr-xr-x    2 root     root         4.0K Jun 27  2008 qos
drwxr-xr-x    2 root     root         4.0K Jun 27  2008 test
drwxr-xr-x    2 root     root         4.0K Jun 27  2008 wireless

root@janus2> ll /Database/var/register/system/startup/scripts/NTPupdate-Cron
total 16K
-rw-r--r--    1 root     root           14 Feb 21 18:46 Description
-rw-r--r--    1 root     root            4 Feb 21 18:46 Enabled
-rwxr-xr-x    1 root     root           54 Feb 21 18:46 File
drwxr-xr-x    2 root     root         4.0K Feb 21 18:46 cron


It is possible to create a script as a Cron job, but after that:
- the folder is suffixed with '-Cron',
- a priori there is a mandatory scheduling,
- the name in the list can no longer be changed from the GUI...

But from the shell it is possible to rename the main folder and the name in file 'Description', and also to remove the folder 'cron', what removes the scheduling.
This enables to have a new manual command available in the list of the GUI's Script Editor.

I also wanted to have my commands at the top of the list. This can be done through a smart choice for the main folder name:
- prefixing with '_' is ignored in the sorting,
- using '!' or '-' causes problems as they are taken as command options,
- using '.' makes the command invisible,
- finally I choosed ',' this way:

Code:
drwxr-xr-x    2 root     root         4.0K May 15 21:45 ,Export-Data
drwxr-xr-x    2 root     root         4.0K May 15 21:48 ,Import-Data
drwxr-xr-x    3 root     root         4.0K Feb 21 18:46 NTPupdate-Cron
drwxr-xr-x    3 root     root         4.0K Feb  4  2000 Shibboleth-Cron


In the 'Description' files there is no comma of course, but "Export Data" and "Import Data" are on top of the list in the GUI, as I wanted.

Content of such commands

Of course I could create a dedicated command for every data kind to backup and also to restore, but it would be a mess.
I preferred to have a unique script per function, with an option to select inside.

It would have been simple to code a old style menu there, but such scripts are run with no possible interactivity Evil or Very Mad

Finally it looks like this:

Code:
# Backup to MyBackupServer
# ------------------------

# No interactivity is possible. Set BackupOption with a value predefined below.

# Backup options:
# --------------
#
# 1  - DNS
#
# The option keys for 'export-from-ldap-one.sh' are defined in '/opt/etc/ldap-attribute-map.txt'
#

BackupOption=1

#-------------------------------------------------------------------------------------
# <!> DO NOT MODIFY BELOW in USER MODE

PATH=/opt/bin:$PATH

case $BackupOption in
    1)
    echo "Backup of LDAP's section: DNS" ;
    bash /opt/bin/export-from-ldap-one.sh "DNS" ;
    exit $? ;
    ;;

    *) echo -e "Invalid backup option '$BackupOption'. Aborting.\n" ;
    exit 1 ;;
esac

exit 0;


In the GUI's Script Editor, I adjust BackupOption then run the script Confused

Of course I would prefer to run that by clicking on a button in a User-defined page of the GUI, taking the option in a checkbox of the form !
But in the meantime it works quite easily this way...

Hope it can help someone.

Ideas for improvements are welcome.

Best regards.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    www.zeroshell.org Forum Index -> ZeroShell All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group