Control User creation home path in a package.

Enter Your Query:
Use '%' for wildcards and quotes for "exact phrases"

Top Level » DirectAdmin » Custom Scripting

Control User creation home path in a package.Last Modified: Nov 16, 2017, 2:29 pm
new way
DirectAdmin 1.52.2+ will support a new feature that automates this for you:

old way

If you have /home and /home2, and want to be able to create Users to either directory, with the choice in a package, do the following.
Note: Assumes CentOS and /etc/default/useradd for default home control.

1) Create a Custom Packages Item listbox for the homedir.

nano /usr/local/directadmin/data/admin/custom_package_items.conf

and add the following code:

homedir=type=listbox&item1txt=/home&item1val=/home&item2txt=/home2&item2val=/home2&string=Select from List&desc=Select desired home path.&default=/home2

Note the default is set to /home2. Use /home if you wish.
Be sure to re-save all of your User packages so they have the homedir set.

2) Create the script to change the /etc/default/useradd file:

nano /usr/local/directadmin/scripts/custom/

and add the code

if [ ! -e ${DEF_USERADD} ]; then
   echo "cannot find ${DEF_USERADD}";
   exit 0;
if [ "$homedir" = "" ]; then
   echo "homedir is blank";
   exit 0;
perl -pi -e "s#HOME=.*#HOME=$homedir#" ${DEF_USERADD}
exit 0;

and chmod this script to 755.

3) Lastly, use this to set it back after each creation:

nano /usr/local/directadmin/scripts/custom/

and add the code:

perl -pi -e "s#HOME=.*#HOME=/home#" ${DEF_USERADD}
exit 0;

and also set it to 755.

© 2018 JBMC Software, Suite 173  3-11 Bellerose Drive, St Albert, AB  T8N 1P7  Canada.  Mon-Fri 9AM-5PM MST