cPanel -> DirectAdmin script development

nick-a

Verified User
Joined
Feb 23, 2007
Messages
49
Following on from lots of offers of help here:

http://www.webhostingtalk.com/showthread.php?t=1770337

I'm starting to think no one person is going to do it regardless of $$, so it'll have to be a community effort.

Basic concept is this:

1) Do a yum update and reboot, make sure cPanel is up to v80 (if systems are all on the same version it'll be easier), get system as clean, up to date and error free as possible. Assume but check for v80 cPanel, EA4 etc.
2) Create a working directory (which will be /da), copy /var/cpanel, /etc and any other required files to it
3) Perform some sanity checks, for example, make sure there's no +i files in /home that'll ruin later steps.
4) Generate the /usr/local/directadmin/data/users folders for each user in our working directory
5) Seek final confirmation from the user that they want to proceed
6) Stop cPanel services, remove cPanel, or sufficiently kill it. This will also have variations depending if you're using centos 6 or 7. A lot of cPanel is now RPM based, remove those RPM's
7) Install DA
8) Move user files around in home directories to match DA layouts (fairly easy once you get the data required from cPanel user data for domain configs, webroots etc)
9) Some attempt to scan commonly found files in public_html's for old paths and update
10) Restore things like mail configs (should be easy, depends on any differences in file formats), things like this will help https://www.directadmin.com/paths.php. Copy the /da/users folder we made earlier to /usr/local/directadmin/data/users
11) Re-write DA confs
12) Restart DA services and hope for the best

13) Optional steps for later, re-install cagefs, connect back to cPanel DNS cluster, etc.

First things we need to think about is, what sort of sanity checks are we going to do, do we do things like remove cagefs (try uninstalling ea-php* on a cagefs system with lots of accounts and you'll see what I mean).

Are there any more steps you'd recommend?

The way I see this working is that we break the task up and if those who can, contribute, then we'll get there. For example, someone's already told me they can strip a server of cPanel quite easily, that's step 6 done if they can do so.
 
Last edited:
Steps 1-5 can be done in PHP so I'm going to start on that now.
Step 6 needs to be a bash script as PHP will be removed
Step 7 is just run the DA installer
Step 8 shouldn't be hard, it's just logic
Step 9 = simple
Step 10 = fairly simple, things like valiases is just 'copy a file' from our working dir to /etc/whatever
Step 11 = DA can already do this through custombuild, just run the command
 
I'll help by saving some time

About centos 6 it has 16 months life left, EOL is November 2020 so providers that use it has to migrate manually any way to centos 7 for them improved migration tool to just pull the accounts may be sufficient

9) Some attempt to scan commonly found files in public_html's for old paths and update

old cpanel pahts can be sim linked to the new one so files that include files just work (same way when you migrate customers from one disk array /home to another /home2) it will be a bit messy but should work :)
 
I'll help by saving some time

About centos 6 it has 16 months life left, EOL is November 2020 so providers that use it has to migrate manually any way to centos 7 for them improved migration tool to just pull the accounts may be sufficient

9) Some attempt to scan commonly found files in public_html's for old paths and update

old cpanel pahts can be sim linked to the new one so files that include files just work (same way when you migrate customers from one disk array /home to another /home2) it will be a bit messy but should work :)

There's too many centos 6 systems out there that people would want to convert I think, so will have to do it.

I'm hoping to be be almost finished on step 4 tonight, and have found quite a bit of info online on how to properly remove cPanel, so hopefully might have a demo script in a week or so.
 
Last edited:
Right, here's a rough first version of a script that ON CENTOS 7 ONLY will:

- backup cpanel accounts, then remove them (removeacct)
- Remove cPanel (almost completely, still a few bits to tidy up)
- Pull in a sensible custombuild options.conf
- Install Directadmin
- Convert the backups

You must be running EA4, and I've only tested it on cPanel v80.

DO NOT run this on a production system yet, there's a lot more sanity checking I want to put in. If you want to test it on something you can revert (like a cloud server with snapshots). The coding is a bit lazy and needs tidying up.

Code:
wget https://files.netnerd.com/directadmin/cpanel-to-da.sh

Then edit the directadmin licence details at the top with your valid licence details. This is really important, and will be sanity checked in a future version. If you don't do this, you'll then have to run the DA installer manually.

Code:
DACLIENTID=12345
DALICENSEID=123456
HOSTNAME=server.domainname.com
ETHERNET_DEV=eth0
IP=1.1.1.1

Then

Code:
chmod a+x cpanel-to-da.sh
./cpanel-to-da.sh

It takes quite a while.

Then login to DA gui and restore your backups.

To do:
- Much more sanity checking
- Auto restore of backups after installing DA
- Ability to specify things like PHP and DA licence details on the command line to make it a 1 liner
- Remove a few remaining traces of cPanel
- Centos 6 cPanel removal (need an openstack image for testing, anyone?)
- Backup-less version which moves data rather than having to create backups
 
Last edited:
dns

in your script where you do the
Code:
# so we can skip the step in DA installer and still have custombuild
touch /root/.preinstall
echo 2.0 > /root/.custombuild

From this help file https://help.directadmin.com/item.php?id=578

[h=3]Custom Email and ns1/ns2[/h]You can override the internal defaults by creating files before running the setup.sh[FONT=&quot]/root/.email.txt
/root/.ns1.txt
/root/.ns2.txt[/FONT]

With a one-line entry for those values, which will set them into the setup.txt via the setup.sh, instead of the default values that match the hostname.you can add some way to put in the Admin Email and the Main Nameserver like

Code:
echo 2.0 > /root/.custombuild

        touch /root/.email.txt

        touch /root/.ns1.txt

        touch /root/.ns2.txt

echo [email protected] > /root/.email.txt

echo dns1.volermortpanel.com > /root/.ns1.txt

echo dns2.volermortpanel.com > /root/.ns2.txt

You could even set variables at the top... of course set the to what you need.

does the
touch /root/.preinstall

skip the questions about preinstall packages?
 
This is perfect timing for those who are switching control panels. Glad the op built this.
 
Code:
echo [email protected] > /root/.email.txt

echo dns1.volermortpanel.com > /root/.ns1.txt

echo dns2.volermortpanel.com > /root/.ns2.txt

You could even set variables at the top... of course set the to what you need.

Ok will add this in shortly :)

does the

skip the questions about preinstall packages?

It does indeed, the idea was to make it a single run script, run it, and the end result is a working DA install with no further action required.
 
the end result is a working DA install with no further action required.

Ok great.

While you are at it might add in

echo [email protected] > /root/.forward

but since you are doing in place might already be there.. just a thought.

You could check like this

Code:
if [ ! -f /root/.forward ]; then
        echo $rootemail > /root/.forward
    fi
 
Last edited:
Code:
#Set ip on whitlist
    echo your "whats My IP address" > /usr/local/directadmin/data/admin/ip_whitelist
If you need to make sure you don't get locked out at your desk, dc and or the place you are... related to this https://help.directadmin.com/item.php?id=306

Code:
#shutdown the non csf firewall
    systemctl disable firewalld
    systemctl stop firewalld
I assume this is off already because most everyone uses CSF in the other panel.. never hurt to be sure..
 
It does indeed, the idea was to make it a single run script, run it, and the end result is a working DA install with no further action required.

I assume it just auto installs the correct packages? I have not used this so cool..
 
I assume it just auto installs the correct packages? I have not used this so cool..

The DA installer will just try a "yum -y install list of packages it requires" if the /root/.preinstall file is there, otherwise the script would stop and ask you if you want to install them, hence why creating that file.

firewalld is already disabled on cPanel servers by default, I'll stick in a line to make sure though.

For anyone else reading this, if you have the ability to snapshot your cPanel VPS (and a DA licence of course) and want to have a go, please do try it and let me know if you have any problems, in particular where it stopped. It should theoretically work, it has for me.

I'll get a version 0.2 out over the weekend with a few more features and some more checks.
 
You might want something like this if you don't "buy" a cert or have a wildcard for all your servers.

Code:
function creatLetsEncrypt(){
    echo 'Creating add sni. adding...'
echo "enable_ssl_sni=1" >> /usr/local/directadmin/conf/directadmin.conf
systemctl restart directadmin
printf "Installing Lets encrypt.\n"
cd /usr/local/directadmin/custombuild
./build rewrite_confs
cd /usr/local/directadmin/custombuild
./build update
./build letsencrypt
systemctl restart directadmin
#set ssl on server
printf "Installing SSL to server.\n"
LNE_HOSTNAME="$( hostnamectl --static )"
cd /usr/local/directadmin/scripts
./letsencrypt.sh request_single ${LNE_HOSTNAME} 4096

cd /usr/local/directadmin/conf
perl -pi -e 's/SSL=0/SSL=1/' directadmin.conf
echo "carootcert=/usr/local/directadmin/conf/carootcert.pem" >> directadmin.conf
echo "force_hostname=${LNE_HOSTNAME}" >> directadmin.conf
echo "ssl_redirect_host=${LNE_HOSTNAME}" >> directadmin.conf
systemctl restart directadmin

printf "Fingers crossed..if you server resolves to the name it should have worked.\n"
}

Its just a hacked version of this
https://help.directadmin.com/item.php?id=648
and
https://help.directadmin.com/item.php?id=629

It works for me.:cool:
 
Back
Top