This is really beyond the scope of this site. We can't give you a howto on how to build RPMs or DEBs. There are many, many resources out there for that. For example, here are Fedora's docs on building RPMs.
What you need to do is read that link, understand how RPMs are built and then simply add package2 as a requirement of package1. That way, if your users install package1
, package2
will automatically be downloaded/installed from the repositories as well.
Specifically, you need to read the details on the SPEC file
format. For example, to make mysql a requirement, you would add this line:
BuildRequires: mysql