Topic: Bash CLI setup a new company with random values
The Initial Password for the admin user is in the config_db.php file after this is done
Other than
creating a default company folder
the following should be able to create a new company - tested on debian 6 squeeze:
# Script to create a new company with all random credentials in Debian
COA=en_IN_24-new
# To be shown in the login form
COMPANYNICKNAME="My New Company"
FADBCONFIG=/var/www/frontac/config_db.php
UPASSWD=`dd if=/dev/urandom count=200 bs=1 2>/dev/null|tr "\n" " "|sed 's/[^a-zA-Z0-9]//g'|cut -c-12`
RANUSER=`dd if=/dev/urandom count=200 bs=1 2>/dev/null|tr "\n" " "|sed 's/[^a-zA-Z0-9]//g'|cut -c-12`
FADBNAME=`dd if=/dev/urandom count=200 bs=1 2>/dev/null|tr "\n" " "|sed 's/[^a-zA-Z0-9]//g'|cut -c-12`
DEFCOPWD=`dd if=/dev/urandom count=200 bs=1 2>/dev/null|tr "\n" " "|sed 's/[^a-zA-Z0-9]//g'|cut -c-8`
mysql <<EOF
CREATE USER ${RANUSER} IDENTIFIED BY '${UPASSWD}';
DROP USER '${UPASSWD}'@'%';
CREATE DATABASE ${FADBNAME} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci;
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, SHOW VIEW, ALTER ROUTINE, CREATE ROUTINE, CREATE TEMPORARY TABLES, CREATE VIEW, EVENT, EXECUTE, LOCK TABLES, REFERENCES, TRIGGER ON ${FADBNAME}.* TO '${RANUSER}'@'localhost' IDENTIFIED BY '${UPASSWD}';
FLUSH PRIVILEGES;
USE ${FADBNAME};
source /var/www/frontac/sql/${COA}.sql
INSERT INTO `0_users` (`id`,`user_id`,`password`,`real_name`,`role_id`,`phone`,`email`,`language`,`date_format`,`date_sep`,`tho_sep`,`dec_sep`,`theme`,`page_size`,`prices_dec`,`qty_dec`,`rates_dec`,`percent_dec`,`show_gl`,`show_codes`,`show_hints`,`last_visit_date`,`query_size`,`graphic_links`,`pos`,`print_profile`,`rep_popup`,`sticky_doc_date`,`startup_tab`,`transaction_days`,`save_report_selections`,`use_date_picker`,`def_print_destination`,`def_print_orientation`,`inactive`) VALUES
('1', 'admin', MD5('${DEFCOPWD}'), 'Administrator', '2', '', 'admin@example.com', 'C', '1', '2', '0', '0', 'default', 'A4', '2', '2', '4', '1', '1', '1', '1', NOW(), '10', '1', '1', '', '1', '0', 'orders', '30', '0', '1', '0', '0', '0');
QUIT
EOF
# If the ${FADBCONFIG} script ends with "?>"
# Then remove it first with
sed '${/?>/d;}' -i ${FADBCONFIG}
echo "" >> ${FADBCONFIG};
echo "\$db_connections[] = array(" >> ${FADBCONFIG};
echo " 'name' => '${COMPANYNICKNAME}'," >> ${FADBCONFIG};
echo " 'host' => 'localhost'," >> ${FADBCONFIG};
echo " 'port' => ''," >> ${FADBCONFIG};
echo " 'dbuser' => '${RANUSER}'," >> ${FADBCONFIG};
echo " 'dbpassword' => '${UPASSWD}'," >> ${FADBCONFIG};
echo " 'dbname' => '${FADBNAME}'," >> ${FADBCONFIG};
echo " 'collation' => 'utf8_xx'," >> ${FADBCONFIG};
echo " 'tbpref' => '\$tb_pref_counter'.'_'," >> ${FADBCONFIG};
echo " );" >> ${FADBCONFIG};
echo "\$tb_pref_counter++;" >> ${FADBCONFIG};
echo "" >> ${FADBCONFIG};
echo "# Company $tb_pref_counter admin password: " . ${DEFCOPWD} >> ${FADBCONFIG};
echo "" >> ${FADBCONFIG};
Users can extend this script or make one for using with an existing php script.
This can be used with the form in this post to auto create a company from a signup form.