summaryrefslogtreecommitdiffstats
path: root/server/bin
diff options
context:
space:
mode:
Diffstat (limited to 'server/bin')
-rwxr-xr-xserver/bin/checkperms2
-rwxr-xr-xserver/bin/setserveraddr83
-rwxr-xr-xserver/bin/setserveraddr3115
3 files changed, 189 insertions, 11 deletions
diff --git a/server/bin/checkperms b/server/bin/checkperms
index ca9e1d7d..c02b3350 100755
--- a/server/bin/checkperms
+++ b/server/bin/checkperms
@@ -57,5 +57,5 @@ chown -R $APACHE_USER:$APACHE_GROUP $OPENGNSYS_DIR/tftpboot/menu.lst
chown -R :$OPENGNSYS_USER $OPENGNSYS_DIR/tftpboot/ogLive*
find -L $OPENGNSYS_DIR/tftpboot -type d -exec chmod 755 {} \;
find -L $OPENGNSYS_DIR/tftpboot -type f -exec chmod 644 {} \;
-#chown $APACHE_USER:$APACHE_GROUP $OPENGNSYS_DIR/log/{ogagent,remotepc,rest}.log
+chown $APACHE_USER:$APACHE_GROUP $OPENGNSYS_DIR/log/{ogagent,remotepc,rest}.log 2>/dev/null
diff --git a/server/bin/setserveraddr b/server/bin/setserveraddr
index a979595f..eb52d64d 100755
--- a/server/bin/setserveraddr
+++ b/server/bin/setserveraddr
@@ -22,7 +22,7 @@
PROG="$(basename "$0")"
OPENGNSYS=/opt/opengnsys
PXEDIR=$OPENGNSYS/tftpboot/menu.lst
-CONFIGFILE=$OPENGNSYS/etc/opengnsys.json
+DEFAULTFILE=/etc/default/opengnsys
# Checking parameters.
if [ $# -ne 1 ]; then
@@ -56,7 +56,8 @@ done
if [ -n "$SERVERIP" ]; then
# Temporary files.
tmpfile=$(mktemp /tmp/og.XXXXX)
- trap "rm -f $tmpfile" 1 2 3 6 9 15
+ MYCNF=$(mktemp /tmp/.my.cnf.XXXXX)
+ trap "rm -f $tmpfile $MYCNF" 1 2 3 6 9 15
# Checking whether the DHCP settings need to be changed.
CHANGE=0
@@ -84,12 +85,73 @@ if [ -n "$SERVERIP" ]; then
echo "DHCP configuration has not changed."
fi
- OLDSERVERIP=$(jq -r .server.ip $CONFIGFILE)
- if [ "$SERVERIP" != "$OLDSERVERIP" ]; then
- # Updating configuration file.
- jq ".server.ip=\"$SERVERIP\"" $CONFIGFILE | sponge $CONFIGFILE
- # Updating all PXE files.
- find $PXEDIR -name "01-*" -exec sed -i -e "s/$OLDSERVERIP/$SERVERIP/g" {} \;
+ # Saving old IP address.
+ source $OPENGNSYS/etc/ogAdmRepo.cfg
+ OLDSERVERIP=$IPlocal
+
+ # Checking if configuration files need to be modified.
+ CHANGE=0
+ for f in $OPENGNSYS/{etc/{ogAdmServer,ogAdmRepo,ogAdmAgent}.cfg,www/controlacceso.php,client/etc/ogAdmClient.cfg}; do
+ # Error if configuration file cannot be found.
+ if [ ! -f $f ]; then
+ echo "$PROG: File $file does not exist." >&2
+ exit 2
+ fi
+ # Updating configuration variables (if URLs does not contain "localhost").
+ sed -e "s,ServidorAdm=.*,ServidorAdm=$SERVERIP," \
+ -e "s,IPlocal=.*,IPlocal=$SERVERIP," \
+ -e "s,UrlMenu=https?://\([^/]*\)/\(.*\),UrlMenu=https://$SERVERIP/\2," \
+ -e '/localhost/!s,https\?://[^/]*/\(.*\),https://'$SERVERIP'/\1,' $f >$tmpfile
+ file="${f/./-$SERVERDEV.}"
+ # Copying updated file, if needed.
+ if [ ! $f -ef $file ] || ! diff -q $tmpfile $file &>/dev/null; then
+ cp $tmpfile $file
+ ln -f $file $f
+ CHANGE=1
+ fi
+ done
+
+ # Processing when something has changed.
+ if [ $CHANGE == 1 ]; then
+ # Restart OpenGnsys services.
+ /etc/init.d/opengnsys restart
+ # If Repository is active, generating a new API token.
+ source $DEFAULTFILE
+ if [ "$RUN_OGADMREPO" == "yes" ]; then
+ REPOKEY=$(php -r 'echo md5(uniqid(rand(), true));')
+ sed -i -e "s/ApiToken=.*/ApiToken=$REPOKEY/" $OPENGNSYS/etc/ogAdmRepo.cfg
+ fi
+ # If OpenGnsys Server is active, updating the database.
+ if [ "$RUN_OGADMSERVER" == "yes" ]; then
+ source $OPENGNSYS/etc/ogAdmServer.cfg
+ # Creating credentials file.
+ cat << EOT > $MYCNF
+[client]
+user=$USUARIO
+password=$PASSWORD
+EOT
+ # Updating OpenGnsys Server IP address.
+ mysql --defaults-extra-file=$MYCNF -D "$CATALOG" -e \
+ "UPDATE entornos
+ SET ipserveradm='$SERVERIP'
+ WHERE identorno=1"
+ # If OpenGnsys Repository is active, updating IP address and API token.
+ if [ "$RUN_OGADMREPO" == "yes" ]; then
+ mysql --defaults-extra-file=$MYCNF -D "$CATALOG" -e \
+ "UPDATE repositorios
+ SET ip='$SERVERIP', apikey='$REPOKEY'
+ WHERE ip='$OLDSERVERIP'"
+ unset REPOKEY
+ fi
+ # Updating all menu URLs.
+ mysql --defaults-extra-file=$MYCNF -D "$CATALOG" -e \
+ "UPDATE menus
+ SET htmlmenupub = REPLACE(htmlmenupub, '$OLDSERVERIP', '$SERVERIP'),
+ htmlmenupri = REPLACE(htmlmenupri, '$OLDSERVERIP', '$SERVERIP');"
+ # Updating all PXE files.
+ find $PXEDIR -name "01-*" -exec sed -i -e "s/$OLDSERVERIP/$SERVERIP/g" {} \;
+ fi
+
# Showing manual task to do after execution.
cat << EOT
Default server interface set to: $SERVERDEV ($SERVERIP)
@@ -99,6 +161,7 @@ Manual tasks:
- Check PXE files.
- Log-in as Web Console user:
- Check menu URLs.
+${REPOKEY:+" - Update repository API token"}
EOT
else
# Showing message if nothing changes.
@@ -110,6 +173,6 @@ else
exit 1
fi
-# Removing temporary file.
-rm -f $tmpfile
+# Removing temporary files.
+rm -f $tmpfile $MYCNF
diff --git a/server/bin/setserveraddr3 b/server/bin/setserveraddr3
new file mode 100755
index 00000000..a979595f
--- /dev/null
+++ b/server/bin/setserveraddr3
@@ -0,0 +1,115 @@
+#!/bin/bash
+
+#/**
+# setserveraddr {str_ipaddress | str_netiface}
+#@file setserveraddr
+#@brief Command the modifies configuration files to assign the default network interface.
+#@param str_ipaddress IP address assigned to a network interface
+#@param str_netiface network interface name defined by the operating system.
+#@version Initial version.
+#@author Ramón M. Gómez - ETSII Univ. Sevilla
+#@date 2011-01-25
+#@version 1.0.5 - Regenerate configuration files.
+#@author Ramón M. Gómez - ETSII Univ. Sevilla
+#@date 2014-06-06
+#@version 1.1.1 - Updating menu URLs, PXE files, and repository API key.
+#@author Ramón M. Gómez - ETSII Univ. Sevilla
+#@date 2018-11-15
+#*/ ##
+
+
+# Variables.
+PROG="$(basename "$0")"
+OPENGNSYS=/opt/opengnsys
+PXEDIR=$OPENGNSYS/tftpboot/menu.lst
+CONFIGFILE=$OPENGNSYS/etc/opengnsys.json
+
+# Checking parameters.
+if [ $# -ne 1 ]; then
+ echo "$PROG: Incorrect operand. Format: $PROG ipaddress|netiface" >&2
+ exit 1
+fi
+if [ "$USER" != "root" ]; then
+ echo "$PROG: Need to be root." >&2
+ exit 1
+fi
+
+# Showing warning to inform that initiated clients may hang.
+read -rp "WARNING: initiated clients can hang. Continue? (y/n): " ANSWER
+if [ "${ANSWER,,}" != "y" ]; then
+ echo "Operation canceled."
+ exit 0
+fi
+
+# Detecting network interfaces.
+DEVICES=$(ip -o link show up | awk -F: '$2!~/lo/ {print $2}')
+for DEV in $DEVICES; do
+ # If the network interface is found, get its IP address.
+ IP=$(ip -o addr show dev "$DEV" | awk '$3~/inet$/ {sub (/\/.*/, ""); print ($4)}')
+ if [ "$DEV" == "$1" ] || [ "$IP" == "$1" ]; then
+ SERVERIP="$IP"
+ SERVERDEV="$DEV"
+ fi
+done
+
+# Checking if IP address has been detected.
+if [ -n "$SERVERIP" ]; then
+ # Temporary files.
+ tmpfile=$(mktemp /tmp/og.XXXXX)
+ trap "rm -f $tmpfile" 1 2 3 6 9 15
+
+ # Checking whether the DHCP settings need to be changed.
+ CHANGE=0
+ for f in /etc/{dhcp,hcp3}/dhcpd.conf; do
+ if [ -f $f ]; then
+ # Changing DHCP "next-server" parameter.
+ file="${f/./-$SERVERDEV.}"
+ sed -e "s/next-server.*/next-server $SERVERIP;/" \
+ -e "s/option routers ;/option routers ${SERVERIP%.*}.1;/" $file >$tmpfile
+ # Copying and linking file if there are changes.
+ if [ ! $f -ef $file ] || ! diff -q $tmpfile $file &>/dev/null; then
+ mv $tmpfile $file
+ chmod 644 $file
+ ln -f $file $f
+ CHANGE=1
+ fi
+ fi
+ done
+ # Restarting DHCP service if its configuration has changed.
+ if [ $CHANGE == 1 ]; then
+ for f in /etc/init.d/{isc-dhcp-server,dhcp3-server,dhcpd}; do
+ [ -x $f ] && $f restart
+ done
+ else
+ echo "DHCP configuration has not changed."
+ fi
+
+ OLDSERVERIP=$(jq -r .server.ip $CONFIGFILE)
+ if [ "$SERVERIP" != "$OLDSERVERIP" ]; then
+ # Updating configuration file.
+ jq ".server.ip=\"$SERVERIP\"" $CONFIGFILE | sponge $CONFIGFILE
+ # Updating all PXE files.
+ find $PXEDIR -name "01-*" -exec sed -i -e "s/$OLDSERVERIP/$SERVERIP/g" {} \;
+ # Showing manual task to do after execution.
+ cat << EOT
+Default server interface set to: $SERVERDEV ($SERVERIP)
+
+Manual tasks:
+- Check DHCP configuration file and restart service, if needed.
+- Check PXE files.
+- Log-in as Web Console user:
+ - Check menu URLs.
+EOT
+ else
+ # Showing message if nothing changes.
+ echo "Default interface has not changed: $1"
+ fi
+else
+ # Error if network interface is not found.
+ echo "$PROG: Network device not found. Format: $PROG ipaddress|netiface" >&2
+ exit 1
+fi
+
+# Removing temporary file.
+rm -f $tmpfile
+