<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[FrontAccounting forum — Bash CLI setup a new company with random values]]></title>
	<link rel="self" href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=10563&amp;type=atom" />
	<updated>2024-07-11T18:39:17Z</updated>
	<generator>PunBB</generator>
	<id>https://frontaccounting.com/punbb/viewtopic.php?id=10563</id>
		<entry>
			<title type="html"><![CDATA[Bash CLI setup a new company with random values]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=43246#p43246" />
			<content type="html"><![CDATA[<p>The Initial Password for the admin user is in the config_db.php file after this is done<br />Other than<br />&nbsp; creating a default company folder<br />the following should be able to create a new company - tested on debian 6 squeeze:<br /></p><div class="codebox"><pre><code># 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=&quot;My New Company&quot;

FADBCONFIG=/var/www/frontac/config_db.php

UPASSWD=`dd if=/dev/urandom count=200 bs=1 2&gt;/dev/null|tr &quot;\n&quot; &quot; &quot;|sed &#039;s/[^a-zA-Z0-9]//g&#039;|cut -c-12`
RANUSER=`dd if=/dev/urandom count=200 bs=1 2&gt;/dev/null|tr &quot;\n&quot; &quot; &quot;|sed &#039;s/[^a-zA-Z0-9]//g&#039;|cut -c-12`
FADBNAME=`dd if=/dev/urandom count=200 bs=1 2&gt;/dev/null|tr &quot;\n&quot; &quot; &quot;|sed &#039;s/[^a-zA-Z0-9]//g&#039;|cut -c-12`
DEFCOPWD=`dd if=/dev/urandom count=200 bs=1 2&gt;/dev/null|tr &quot;\n&quot; &quot; &quot;|sed &#039;s/[^a-zA-Z0-9]//g&#039;|cut -c-8`

mysql &lt;&lt;EOF

CREATE USER ${RANUSER} IDENTIFIED BY &#039;${UPASSWD}&#039;;
DROP USER &#039;${UPASSWD}&#039;@&#039;%&#039;;
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 &#039;${RANUSER}&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;${UPASSWD}&#039;;
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
 (&#039;1&#039;, &#039;admin&#039;, MD5(&#039;${DEFCOPWD}&#039;), &#039;Administrator&#039;, &#039;2&#039;, &#039;&#039;, &#039;admin@example.com&#039;, &#039;C&#039;, &#039;1&#039;, &#039;2&#039;, &#039;0&#039;, &#039;0&#039;, &#039;default&#039;, &#039;A4&#039;, &#039;2&#039;, &#039;2&#039;, &#039;4&#039;, &#039;1&#039;, &#039;1&#039;, &#039;1&#039;, &#039;1&#039;, NOW(), &#039;10&#039;, &#039;1&#039;, &#039;1&#039;, &#039;&#039;, &#039;1&#039;, &#039;0&#039;, &#039;orders&#039;, &#039;30&#039;, &#039;0&#039;, &#039;1&#039;, &#039;0&#039;, &#039;0&#039;, &#039;0&#039;);

QUIT
EOF

# If the ${FADBCONFIG} script ends with &quot;?&gt;&quot;
# Then remove it first with
sed &#039;${/?&gt;/d;}&#039; -i ${FADBCONFIG}

echo &quot;&quot; &gt;&gt; ${FADBCONFIG};
echo &quot;\$db_connections[] = array(&quot; &gt;&gt; ${FADBCONFIG};
echo &quot;    &#039;name&#039; =&gt; &#039;${COMPANYNICKNAME}&#039;,&quot; &gt;&gt; ${FADBCONFIG};
echo &quot;    &#039;host&#039; =&gt; &#039;localhost&#039;,&quot; &gt;&gt; ${FADBCONFIG};
echo &quot;    &#039;port&#039; =&gt; &#039;&#039;,&quot; &gt;&gt; ${FADBCONFIG};
echo &quot;    &#039;dbuser&#039; =&gt; &#039;${RANUSER}&#039;,&quot; &gt;&gt; ${FADBCONFIG};
echo &quot;    &#039;dbpassword&#039; =&gt; &#039;${UPASSWD}&#039;,&quot; &gt;&gt; ${FADBCONFIG};
echo &quot;    &#039;dbname&#039; =&gt; &#039;${FADBNAME}&#039;,&quot; &gt;&gt; ${FADBCONFIG};
echo &quot;    &#039;collation&#039; =&gt; &#039;utf8_xx&#039;,&quot; &gt;&gt; ${FADBCONFIG};
echo &quot;    &#039;tbpref&#039; =&gt; &#039;\$tb_pref_counter&#039;.&#039;_&#039;,&quot; &gt;&gt; ${FADBCONFIG};
echo &quot;  );&quot; &gt;&gt; ${FADBCONFIG};
echo &quot;\$tb_pref_counter++;&quot; &gt;&gt; ${FADBCONFIG};
echo &quot;&quot; &gt;&gt; ${FADBCONFIG};
echo &quot;# Company $tb_pref_counter admin password: &quot; .  ${DEFCOPWD}  &gt;&gt; ${FADBCONFIG};
echo &quot;&quot; &gt;&gt; ${FADBCONFIG};</code></pre></div><p>Users can extend this script or make one for using with an existing php script.</p><p>This can be used with the <a href="https://frontaccounting.com/punbb/viewtopic.php?id=10562">form in this post to auto create a company from a signup form</a>.</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2024-07-11T18:39:17Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=43246#p43246</id>
		</entry>
</feed>
