#!/usr/bin/perl 
# This script (sophomorix-setup-files) is maintained by Rüdiger Beck
# It is Free Software (License GPLv3)
# If you find errors, contact the author
# jeffbeck@web.de  or  jeffbeck@gmx.de



# This Script adds users that are necessary to use sophomorix-files 
# It should be run as postinst
#use Sophomorix::SophomorixConfig; 
use Sophomorix::SophomorixBase; 

# Einlesen der Konfigurationsdatei für Entwickler
{ package DevelConf ; do "/usr/share/sophomorix/devel/sophomorix-devel.conf"}

print "##### sophomorix-setup-files is configuring",
      " the system for sophomorix-files ...\n";

# gruppe admin anlegen
#system("groupadd -g 1000 admin");
system("groupadd admin");

# gruppe lehrer anlegen
#system("groupadd -g 1002 lehrer");
#system("groupadd lehrer");
#system("groupadd teacher");
system("groupadd ${DevelConf::teacher}");

# make some scripts owned by lehrer
#system("chown root.lehrer /usr/bin/sophomorix-teacher");
#system("chown root.teacher /usr/bin/sophomorix-teacher");
system("chown root.${DevelConf::teacher} /usr/bin/sophomorix-teacher");
system("chmod 4750 /usr/bin/sophomorix-teacher");


# admin anlegen
#system("useradd -u 500 -g admin -G lehrer -d /home/admin -s /bin/bash -c Windows_Systemverwalter -p admin!  admin");
system("useradd -g admin -d /home/admin -s /bin/bash -c Windows_Systemverwalter -p admin!  admin");

# admin muss in der Gruppe lehrer Mitglied sein
# (primäre Gruppe bleibt admin)
#system("usermod -G lehrer admin");
#system("gpasswd -a admin lehrer");
#system("gpasswd -a admin teacher");
system("gpasswd -a admin ${DevelConf::teacher}");

# repair.directories einlesen
&get_alle_verzeichnis_rechte();

# add files for the sophomorix-database

&check_datei_touch("${DevelConf::dyn_config_pfad}/user_db");
&check_datei_touch("${DevelConf::dyn_config_pfad}/class_db");
&check_datei_touch("${DevelConf::dyn_config_pfad}/subclass_db");
&check_datei_touch("${DevelConf::dyn_config_pfad}/projects_db");

&check_datei_touch("${DevelConf::dyn_config_pfad}/workstation_db");
&check_datei_touch("${DevelConf::dyn_config_pfad}/room_db");
&check_datei_touch("${DevelConf::dyn_config_pfad}/department_db");

# make important data readable by root only
&setup_verzeichnis("\$var_lib_pfad","$DevelConf::var_lib_pfad");
