force unattended install php apt debian squeeze

Posted by user1258619 on Server Fault See other posts from Server Fault or by user1258619
Published on 2012-11-19T16:53:46Z Indexed on 2012/11/19 17:02 UTC
Read the original article Hit count: 228

Filed under:
|
|
|
|

i am trying to do an unattended install via php for several packages but every time when the dependencies come up it aborts instead of forcing the answer to be yes. (i have broken apt a few times...) each time though i start off re-imaging my vps(testing server) so there isn't an issue of something still being hung or crashed.can someone tell me what i am doing wrong? keep in mind this is the 12th version of this script to get nowhere.

fwrite(STDOUT, "Root Password:\n");
$root_pass = chop(fgets(STDIN));
$file_apt = '/etc/apt/apt.conf.d/70debconf';
// Open the file to get existing content
$current_apt = file_get_contents($file_apt);
// Append a new person to the file
$current_apt .= "Dpkg::Options {\"--force-confold\";};\n";
// Write the contents back to the file
file_put_contents($file_apt, $current_apt);
$update = shell_exec('echo '.$root_pass.' | DEBIAN_FRONTEND=noninteractive sudo -S apt-get update');
echo $update;
$update_upgrade = shell_exec('echo '.$root_pass.' | DEBIAN_FRONTEND=noninteractive sudo -s apt-get upgrade');
echo $update_upgrade;
$install_unattended_mysql = shell_exec('echo '.$root_pass.' | DEBIAN_FRONTEND=noninteractive apt-get install --yes --force-yes mysql-server');
echo $install_unattended_mysql;
$install_mysql_set_password = shell_exec('mysql -u root -e "UPDATE mysql.user SET password=PASSWORD("'.$root_pass.'") WHERE user="root"; FLUSH PRIVILEGES;');
echo $install_mysql_set_password;

i have read a few places that i needed to edit the apt.conf file so i am doing so here and doing an update and an upgrade. also the upgrade does abort when it actually has to install something.

The following packages will be upgraded:
  apache2 apache2-doc apache2-mpm-prefork apache2-utils apache2.2-bin
  apache2.2-common base-files bind9 bind9-host bind9utils
  debian-archive-keyring dpkg dselect libbind9-60 libc-bin libc6 libdns69
  libisc62 libisccc60 libisccfg62 liblwres60 locales
22 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 18.4 MB of archives.
After this operation, 8192 B of additional disk space will be used.
Do you want to continue [Y/n]? Abort.

I also should note that only a few pieces of software are going to be installed from the apt repo's as i will include some binaries to go along with it.

© Server Fault or respective owner

Related posts about php

Related posts about apt