artichoke
Verified User
I was trying to automatically add default packages whenever a reseller is created, using the suggestions on this (very old) page:
https://help.directadmin.com/item.php?id=190
Below is my final script (placed in /usr/local/directadmin/scripts/custom). The strangeness that I encountered was that if the script directly creates $DIR/$username/packages.list to contain some lines, the file is found to be empty afterwards. So I suspect user_create_post.sh is running during reseller creation, not after. If I added another line to create /tmp/packages.list containing the same lines, that is found intact (not empty). Apparently after DirectAmin has run user_create_post.sh, it then proceeds to zero out the contents of $DIR/$username/packages.list.
My solution was to queue a background job using the 'at' command. This works.
By the way looking through the DirectAdmin knowledgebase, I found a lot of old files that are no longer accurate, but it's hard to tell until you try to follow their hints. A little housecleaning is overdue.
https://help.directadmin.com/item.php?id=190
Below is my final script (placed in /usr/local/directadmin/scripts/custom). The strangeness that I encountered was that if the script directly creates $DIR/$username/packages.list to contain some lines, the file is found to be empty afterwards. So I suspect user_create_post.sh is running during reseller creation, not after. If I added another line to create /tmp/packages.list containing the same lines, that is found intact (not empty). Apparently after DirectAmin has run user_create_post.sh, it then proceeds to zero out the contents of $DIR/$username/packages.list.
My solution was to queue a background job using the 'at' command. This works.
By the way looking through the DirectAdmin knowledgebase, I found a lot of old files that are no longer accurate, but it's hard to tell until you try to follow their hints. A little housecleaning is overdue.
Code:
#!/bin/sh
#
# See: https://help.directadmin.com/item.php?id=190
#
# Whenever a reseller is created, give him a copy of packages
# belonging to the example reseller 'rtemplate'
BASE=rtemplate
if [ "$usertype" = "reseller" ]; then
DIR=/usr/local/directadmin/data/users
cat <<EOF | at now + 2min
cp -fp $DIR/$BASE/packages.list $DIR/$username/packages.list
chown diradmin:diradmin $DIR/$username/packages.list
mkdir -p $DIR/$username/packages
cp -fp $DIR/$BASE/packages/* $DIR/$username/packages
chown -R diradmin:diradmin $DIR/$username/packages
EOF
fi
exit 0;