Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include Juan's script #23

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

JedMeister
Copy link
Member

@JedMeister JedMeister commented Oct 11, 2021

I propose that we add this script by Juan to the TurnKey Domain Controller appliance.

Note that I've named the script turnkey-dc-conf. As per general convention, TurnKey provided end user helper script names generally start with turnkey- (or tkl). The rationale for that is that it makes it easier for users to know that it's a script we include; plus easy to find via cli tab complete.

Also, this needs though testing to double check that it all works as it should (I've only visually reviewed the code).

Closes turnkeylinux/tracker#1655

@j20003
Copy link

j20003 commented Nov 2, 2021

Hi!
Lines 102 and 128 delete $name
It is a bug in the dialog code that
in principle were independent response boxes instead of forms

Change the term "./domainconfmenu.sh" to the final name turnkey-dc-conf
throughout the script

You would have to add the code to work correctly
to create the necessary directories in /home
and files of users and shares in /samba

#create directory
mkdir /home/users &&
mkdir /home/shares &&

#create separate files and link them in smb.conf
echo > /etc/samba/diruserdc.conf &&
echo > /etc/samba/shares.conf &&
echo >> /etc/samba/smb.conf &&
echo >> /etc/samba/smb.conf &&
echo >> /etc/samba/smb.conf "include = /etc/samba/shares.conf" &&
echo >> /etc/samba/smb.conf "include = /etc/samba/diruserdc.conf" &&
smbcontrol all reload-config

##The latter is necessary for the script to work

@JedMeister
Copy link
Member Author

Lines 102 and 128 delete $name
It is a bug in the dialog code that
in principle were independent response boxes instead of forms

It probably won't fix it, but perhaps it's worth trying with $name quoted (i.e. in double quotes)? I'll do that now as it won't hurt at all.

I used slightly different code to what you suggested but it should do the same thing.

The only thing that I'm not 100% sure about is the smbcontrol all reload-config command. As you can see, I've added all that stuff at the start, but it occurs that perhaps that line should be at the end instead (or as well)?!

- Double quote variables.
- Reindent the code (first level indent only one space; normal 4
  space indents after that).
- implement some bashisms (e.g. double braket tests)
- removed some superfluous spaces and blank lines
@JedMeister
Copy link
Member Author

I've double quoted the $name in the hope that that might help!?

I also ended up making quite a few other changes, although they should all be cosmetic (shouldn't affect functionality).

@j20003
Copy link

j20003 commented Nov 2, 2021

I am writing a code to solve this, it can be added to the menu or executed independently, we will see

Hi!
This only needs to be executed once, inserted this way creates two more lines in smb.conf each time the application is launched and leaves /etc/samba/shares.conf blank
and /etc/samba/diruserdc.conf too

mkdir -p /home/{users,shares}
echo > /etc/samba/diruserdc.conf
echo > /etc/samba/shares.conf
cat >> /etc/samba/smb.conf <<EOF
include = /etc/samba/shares.conf
include = /etc/samba/diruserdc.conf

After investigating the operation of bash, when set -e in #!/Bin/bash, it exits the execution of the command when the return is 0, since the grep command when it does not find a match, its return is 1, if we apply the option -e in #!/bin/bash, it will always terminate the execution of the command when grep is used even if it works correctly, I don't know how to solve this.

@JedMeister
Copy link
Member Author

Hi @j20003 - sorry for slow response.

I'll have a closer look at this next week. I'm a bit bogged down with v17.0 development at the moment. I am currently blocking others from being able to work on upgrading appliances for the upcoming v17.0 release so I need to prioritise that.

I'd really like to get this working and included in the next Domain Controller though, so I'll try to circle back to this ASAP.

@j20003
Copy link

j20003 commented Nov 4, 2021

Perfect, verified that removing the -e from
#!/bin/bash -e works, when I can I'll check it out.

@JedMeister
Copy link
Member Author

Perfect, verified that removing the -e from
#!/bin/bash -e works, when I can I'll check it out.

Ah ok. Setting 'e' forces the script to exit if/when it hits an error (non zero exit code from one of the commands that is being run). So one of the commands must be failing.

It's good practice to set 'e' as otherwise scripts can have unexpected results (i.e. actually they aren't working properly - even when they appear to work). To troubleshoot what is actually failing, try setting 'x' too. I.e.:

#!/bin/bash -ex

That will make the output really verbose and because we're using dialog, it will make things quite ugly. But on the plus side, you will see exactly what the error is/was.

@JedMeister
Copy link
Member Author

Also:

This only needs to be executed once, inserted this way creates two more lines in smb.conf each time the application is launched and leaves /etc/samba/shares.conf blank
and /etc/samba/diruserdc.conf too

mkdir -p /home/{users,shares}
echo > /etc/samba/diruserdc.conf
echo > /etc/samba/shares.conf
cat >> /etc/samba/smb.conf <<EOF
include = /etc/samba/shares.conf
include = /etc/samba/diruserdc.conf

Ah ok. Sorry I misunderstood. So those lines shouldn't actually be part of the script! We should just make those adjustments at initial build time (in the conf.d script).

@j20003
Copy link

j20003 commented Nov 4, 2021

Also:

This only needs to be executed once, inserted this way creates two more lines in smb.conf each time the application is launched and leaves /etc/samba/shares.conf blank
and /etc/samba/diruserdc.conf too
mkdir -p /home/{users,shares}
echo > /etc/samba/diruserdc.conf
echo > /etc/samba/shares.conf
cat >> /etc/samba/smb.conf <<EOF
include = /etc/samba/shares.conf
include = /etc/samba/diruserdc.conf

Ah ok. Sorry I misunderstood. So those lines shouldn't actually be part of the script! We should just make those adjustments at initial build time (in the conf.d script).

That's the idea, get it ready for the turnkey-dc-conf script to work or it could be entered as the first option of turnkey-dc-conf Something like this code:

`#!/bin/bash -x

   (dialog --title "Initial Conf DC" \
	--stdout \
	--msgbox "\nThey will check if the necessary links and directories are created,\nif not they will be created.  " 0 0 )

var1=$(grep "include = /etc/samba/shares.conf" /etc/samba/smb.conf)
sleep 2
var2='include = /etc/samba/shares.conf'
sleep 2
var3=$(grep "include = /etc/samba/diruserdc.conf" /etc/samba/smb.conf)
sleep 2
var4='include = /etc/samba/diruserdc.conf'
sleep 2
var5=$(ls /home | grep users)
sleep 2
var6=users
sleep 2
var7=$(ls /home | grep shares)
sleep 2
var8=shares
sleep 2

if [[ $var1 == $var2 ]];then

if [[ $var3 == $var4 ]];then
	
	if [[ $var5 == $var6 ]];then
		
		if [[ $var7 == $var8 ]];then		

	(dialog --title "Check Result" \
	--stdout \
	--msgbox "\nLink--> include = /etc/samba/shares.conf and
	\nlink--> include = /etc/samba/diruserdc.conf
	\nin file smb.conf exists\n
	\nFiles shares.conf and diruserdc.conf in /etc/samba/ exists\n
	\nFloders \home\shares and \home\users exists\n\nNothing to do" 0 0 )
	exit
		fi
	fi
fi

fi

       password=$(dialog --title "" \
               --stdout \
               --msgbox "The necessary elements will be created " 0 0 )

#Making directorys, separate files and link them in smb.conf
mkdir /home/users
mkdir /home/shares
echo > /etc/samba/diruserdc.conf
echo > /etc/samba/shares.conf
echo >> /etc/samba/smb.conf
echo >> /etc/samba/smb.conf
echo >> /etc/samba/smb.conf "include = /etc/samba/shares.conf"
echo >> /etc/samba/smb.conf "include = /etc/samba/diruserdc.conf"
smbcontrol all reload-config

grep "include = /etc/samba/shares.conf" /etc/samba/smb.conf
sleep 3
grep "include = /etc/samba/diruserdc.conf" /etc/samba/smb.conf
sleep 3
ls /home | grep users
sleep 3
ls /home | grep shares
sleep3

	(dialog --title "Check Result" \
	--stdout \
	--msgbox "\nLink--> include = /etc/samba/shares.conf and\nlink--> include = /etc/samba/diruserdc.conf\nin smb.conf exists\n\nFloders \home\shares and \home\users exists\n\nHave been created " 0 0 )

exit`

@j20003
Copy link

j20003 commented Nov 4, 2021

That will make the output really verbose and because we're using dialog, it will make things quite ugly. But on the plus side, you will see exactly what the error is/was.

Tanks Tomorrow I try it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Domain-Controller - include Juan's Samaba AD config script
2 participants