NULL
};
-static int system_chroot(const char* path, const char* cmd) {
+static int system_chroot(const char* output, const char* path, const char* cmd) {
char chroot_cmd[STRING_SIZE];
snprintf(chroot_cmd, sizeof(chroot_cmd), "/usr/sbin/chroot %s %s", path, cmd);
- return mysystem(chroot_cmd);
+ return mysystem(output, chroot_cmd);
}
struct hw* hw_init() {
return bytes_written;
}
-int hw_create_partitions(struct hw_destination* dest) {
+int hw_create_partitions(struct hw_destination* dest, const char* output) {
// Before we write a new partition table to the disk, we will erase
// the first couple of megabytes at the beginning of the device to
// get rid of all left other things like bootloaders and partition tables.
asprintf(&cmd, "%s disk_set pmbr_boot on", cmd);
}
- r = mysystem(cmd);
+ r = mysystem(output, cmd);
// Wait until the system re-read the partition table
if (r == 0) {
return r;
}
-static int hw_format_filesystem(const char* path, int fs) {
+static int hw_format_filesystem(const char* path, int fs, const char* output) {
char cmd[STRING_SIZE] = "\0";
// Swap
assert(*cmd);
- int r = mysystem(cmd);
+ int r = mysystem(output, cmd);
return r;
}
-int hw_create_filesystems(struct hw_destination* dest) {
+int hw_create_filesystems(struct hw_destination* dest, const char* output) {
int r;
// boot
if (*dest->part_boot) {
- r = hw_format_filesystem(dest->part_boot, dest->filesystem);
+ r = hw_format_filesystem(dest->part_boot, dest->filesystem, output);
if (r)
return r;
}
// swap
if (*dest->part_swap) {
- r = hw_format_filesystem(dest->part_swap, HW_FS_SWAP);
+ r = hw_format_filesystem(dest->part_swap, HW_FS_SWAP, output);
if (r)
return r;
}
// root
- r = hw_format_filesystem(dest->part_root, dest->filesystem);
+ r = hw_format_filesystem(dest->part_root, dest->filesystem, output);
if (r)
return r;
// data
if (*dest->part_data) {
- r = hw_format_filesystem(dest->part_data, dest->filesystem);
+ r = hw_format_filesystem(dest->part_data, dest->filesystem, output);
if (r)
return r;
}
return 0;
}
-static int hw_destroy_raid_superblocks(const struct hw_destination* dest) {
+static int hw_destroy_raid_superblocks(const struct hw_destination* dest, const char* output) {
char cmd[STRING_SIZE];
- hw_stop_all_raid_arrays();
- hw_stop_all_raid_arrays();
+ hw_stop_all_raid_arrays(output);
+ hw_stop_all_raid_arrays(output);
if (dest->disk1) {
- snprintf(cmd, sizeof(cmd), "/sbin/mdadm --zero-superblock %s", dest->disk1);
- mysystem(cmd);
+ snprintf(cmd, sizeof(cmd), "/sbin/mdadm --zero-superblock %s", dest->disk1->path);
+ mysystem(output, cmd);
}
if (dest->disk2) {
- snprintf(cmd, sizeof(cmd), "/sbin/mdadm --zero-superblock %s", dest->disk2);
- mysystem(cmd);
+ snprintf(cmd, sizeof(cmd), "/sbin/mdadm --zero-superblock %s", dest->disk2->path);
+ mysystem(output, cmd);
}
return 0;
}
-int hw_setup_raid(struct hw_destination* dest) {
+int hw_setup_raid(struct hw_destination* dest, const char* output) {
char* cmd = NULL;
int r;
// Stop all RAID arrays that might be around (again).
// It seems that there is some sort of race-condition with udev re-enabling
// the raid arrays and therefore locking the disks.
- r = hw_destroy_raid_superblocks(dest);
+ r = hw_destroy_raid_superblocks(dest, output);
asprintf(&cmd, "echo \"y\" | /sbin/mdadm --create --verbose --metadata=%s --auto=mdp %s",
RAID_METADATA, dest->path);
return r;
}
- r = mysystem(cmd);
+ r = mysystem(output, cmd);
free(cmd);
// Wait a moment until the device has been properly brought up
return r;
}
-int hw_stop_all_raid_arrays() {
- return mysystem("/sbin/mdadm --stop --scan --verbose");
+int hw_stop_all_raid_arrays(const char* output) {
+ return mysystem(output, "/sbin/mdadm --stop --scan --verbose");
}
-int hw_install_bootloader(struct hw_destination* dest) {
+int hw_install_bootloader(struct hw_destination* dest, const char* output) {
char cmd[STRING_SIZE];
int r;
// Generate configuration file
snprintf(cmd, sizeof(cmd), "/usr/sbin/grub-mkconfig -o /boot/grub/grub.cfg");
- r = system_chroot(DESTINATION_MOUNT_PATH, cmd);
+ r = system_chroot(output, DESTINATION_MOUNT_PATH, cmd);
if (r)
return r;
if (dest->is_raid) {
snprintf(cmd, sizeof(cmd), "%s %s", cmd_grub, dest->disk1->path);
- r = system_chroot(DESTINATION_MOUNT_PATH, cmd);
+ r = system_chroot(output, DESTINATION_MOUNT_PATH, cmd);
if (r)
return r;
snprintf(cmd, sizeof(cmd), "%s %s", cmd_grub, dest->disk2->path);
- r = system_chroot(DESTINATION_MOUNT_PATH, cmd);
+ r = system_chroot(output, DESTINATION_MOUNT_PATH, cmd);
} else {
snprintf(cmd, sizeof(cmd), "%s %s", cmd_grub, dest->path);
- r = system_chroot(DESTINATION_MOUNT_PATH, cmd);
+ r = system_chroot(output, DESTINATION_MOUNT_PATH, cmd);
}
return r;
unsigned long long hw_memory();
-int hw_create_partitions(struct hw_destination* dest);
-int hw_create_filesystems(struct hw_destination* dest);
+int hw_create_partitions(struct hw_destination* dest, const char* output);
+int hw_create_filesystems(struct hw_destination* dest, const char* output);
int hw_mount_filesystems(struct hw_destination* dest, const char* prefix);
int hw_umount_filesystems(struct hw_destination* dest, const char* prefix);
-int hw_setup_raid(struct hw_destination* dest);
-int hw_stop_all_raid_arrays();
+int hw_setup_raid(struct hw_destination* dest, const char* output);
+int hw_stop_all_raid_arrays(const char* output);
-int hw_install_bootloader(struct hw_destination* dest);
+int hw_install_bootloader(struct hw_destination* dest, const char* output);
int hw_write_fstab(struct hw_destination* dest);
void hw_sync();
#include <libsmooth.h>
/* unattended.c */
-int unattended_setup(struct keyvalue *unattendedkv);
+int unattended_setup(struct keyvalue *unattendedkv, const char* output);
#define UNATTENDED_CONF "/cdrom/boot/unattended.conf"
#define LICENSE_FILE "/cdrom/COPYING"
-FILE *flog = NULL;
-char *mylog;
-
extern char url[STRING_SIZE];
static int newtChecklist(const char* title, const char* message,
int main(int argc, char *argv[]) {
struct hw* hw = hw_init();
+ const char* logfile = NULL;
// Read /etc/system-release
char* system_release = get_system_release();
sethostname( SNAME , 10);
/* Log file/terminal stuff. */
- if (argc >= 2)
- {
- if (!(flog = fopen(argv[1], "w+")))
+ FILE* flog = NULL;
+ if (argc >= 2) {
+ logfile = argv[1];
+
+ if (!(flog = fopen(logfile, "w+")))
return 0;
- }
- else
+ } else {
return 0;
-
- mylog = argv[1];
-
+ }
+
fprintf(flog, "Install program started.\n");
newtInit();
// check if we have to make an unattended install
if (strstr (line, "unattended") != NULL) {
unattended = 1;
- runcommandwithstatus("/bin/sleep 10", title, "WARNING: Unattended installation will start in 10 seconds...");
+ runcommandwithstatus("/bin/sleep 10", title, "WARNING: Unattended installation will start in 10 seconds...", NULL);
}
// check if we have to patch for serial console
if (strstr (line, "console=ttyS0") != NULL) {
}
// Load common modules
- mysystem("/sbin/modprobe vfat"); // USB key
- hw_stop_all_raid_arrays();
+ mysystem(logfile, "/sbin/modprobe vfat"); // USB key
+ hw_stop_all_raid_arrays(logfile);
if (!unattended) {
// Language selection
fprintf(flog, "Source drive: %s\n", sourcedrive);
if (!sourcedrive) {
newtWinMessage(title, _("OK"), _("No local source media found. Starting download."));
- runcommandwithstatus("/bin/downloadsource.sh", title, _("Downloading installation image ..."));
+ runcommandwithstatus("/bin/downloadsource.sh", title, _("Downloading installation image ..."), logfile);
if ((handle = fopen("/tmp/source_device", "r")) == NULL) {
errorbox(_("Download error"));
goto EXIT;
if (destination->is_raid) {
statuswindow(60, 4, title, _("Building RAID..."));
- rc = hw_setup_raid(destination);
+ rc = hw_setup_raid(destination, logfile);
if (rc) {
errorbox(_("Unable to build the RAID."));
goto EXIT;
// Execute the partitioning...
statuswindow(60, 4, title, _("Partitioning disk..."));
- rc = hw_create_partitions(destination);
+ rc = hw_create_partitions(destination, logfile);
if (rc) {
errorbox(_("Unable to partition the disk."));
goto EXIT;
// Execute the formatting...
statuswindow(60, 4, title, _("Creating filesystems..."));
- rc = hw_create_filesystems(destination);
+ rc = hw_create_filesystems(destination, logfile);
if (rc) {
errorbox(_("Unable to create filesystems."));
goto EXIT;
"/bin/tar -C /harddisk -xvf /cdrom/distro.img --lzma 2>/dev/null");
if (runcommandwithprogress(60, 4, title, commandstring, INST_FILECOUNT,
- _("Installing the system..."))) {
+ _("Installing the system..."), logfile)) {
errorbox(_("Unable to install the system."));
goto EXIT;
}
/* Build cache lang file */
snprintf(commandstring, STRING_SIZE, "/usr/sbin/chroot /harddisk /usr/bin/perl -e \"require '" CONFIG_ROOT "/lang.pl'; &Lang::BuildCacheLang\"");
- if (runcommandwithstatus(commandstring, title, _("Installing the language cache..."))) {
+ if (runcommandwithstatus(commandstring, title, _("Installing the language cache..."), logfile)) {
errorbox(_("Unable to install the language cache."));
goto EXIT;
}
// Installing bootloader...
statuswindow(60, 4, title, _("Installing the bootloader..."));
- rc = hw_install_bootloader(destination);
+ rc = hw_install_bootloader(destination, logfile);
if (rc) {
errorbox(_("Unable to install the bootloader."));
goto EXIT;
}
/* Set marker that the user has already accepted the gpl */
- mysystem("/usr/bin/touch /harddisk/var/ipfire/main/gpl_accepted");
+ mysystem(logfile, "/usr/bin/touch /harddisk/var/ipfire/main/gpl_accepted");
/* Copy restore file from cdrom */
if (unattended && (strlen(restore_file) > 0)) {
fprintf(flog, "unattended: Copy restore file\n");
snprintf(commandstring, STRING_SIZE,
"cp /cdrom/%s /harddisk/var/ipfire/backup", restore_file);
- mysystem(commandstring);
+ mysystem(logfile, commandstring);
}
// Umount source drive and eject
hw_umount(SOURCE_MOUNT_PATH);
snprintf(commandstring, STRING_SIZE, "/usr/bin/eject %s", sourcedrive);
- mysystem(commandstring);
+ mysystem(logfile, commandstring);
if (!unattended) {
snprintf(message, sizeof(message), _("%s was successfully installed. "
allok = 1;
EXIT:
- fprintf(flog, "Install program ended.\n");
+ fprintf(flog, "Install program ended.\n");
if (!(allok))
newtWinMessage(title, _("OK"), _("Press Ok to reboot."));
free(destination);
}
- hw_stop_all_raid_arrays();
+ hw_stop_all_raid_arrays(logfile);
if (selected_disks)
hw_free_disks(selected_disks);
*/
#include "install.h"
-extern FILE *flog;
-int unattended_setup(struct keyvalue *unattendedkv) {
+int unattended_setup(struct keyvalue *unattendedkv, const char* output) {
+ FILE* flog = fopen(output, "w+");
struct keyvalue *mainsettings = initkeyvalues();
struct keyvalue *ethernetkv = initkeyvalues();
fprintf(flog, "unattended: setting root password\n");
snprintf(commandstring, STRING_SIZE,
"/usr/sbin/chroot /harddisk /bin/sh -c \"echo 'root:%s' | /usr/sbin/chpasswd\"", root_password);
- if (mysystem(commandstring)) {
+ if (mysystem(NULL, commandstring)) {
errorbox("unattended: ERROR setting root password");
return 0;
}
fprintf(flog, "unattended: setting admin password\n");
snprintf(commandstring, STRING_SIZE,
"/usr/sbin/chroot /harddisk /usr/sbin/htpasswd -c -m -b " CONFIG_ROOT "/auth/users admin '%s'", admin_password);
- if (mysystem(commandstring)) {
+ if (mysystem(NULL, commandstring)) {
errorbox("unattended: ERROR setting admin password");
return 0;
}
fprintf(flog, "unattended: Restoring Backup\n");
snprintf(commandstring, STRING_SIZE,
"/usr/sbin/chroot /harddisk /bin/tar -xvzp -f /var/ipfire/backup/%s -C /", restore_file);
- if (mysystem(commandstring)) {
+ if (mysystem(NULL, commandstring)) {
errorbox("unattended: ERROR restoring backup");
}
}
fprintf(flog, "unattended: Setup ended\n");
+ fclose(flog);
+
return 1;
}
/* libsmooth.c */
void stripnl(char *s);
-int mysystem(const char *command);
+int mysystem(const char* output, const char *command);
void errorbox(char *message);
int statuswindowscroll(int width, int height, const char *title, const char *text, ...);
int disclaimerbox(char *message);
void statuswindow(int width, int height, const char *title, const char *text, ...);
int runcommandwithprogress(int width, int height, const char *title, const char *command,
int lines, char *text, ...);
-int runcommandwithstatus(const char *command, const char* title, const char *message);
-int runhiddencommandwithstatus(const char *command, const char* title, const char *message);
+int runcommandwithstatus(const char *command, const char* title, const char *message, const char* output);
+int runhiddencommandwithstatus(const char *command, const char* title, const char *message, const char* output);
int checkformodule(const char *module);
int replace(char filename1[], char *from, char *to);
char* get_version(void);
#include <libintl.h>
#define _(x) dgettext("libsmooth", x)
-extern FILE *flog;
-extern char *mylog;
-
-extern char **ctr;
-
/* stripnl(). Replaces \n with \0 */
void stripnl(char *s) {
char *t = strchr(s, '\n');
}
/* Little wrapper. */
-int mysystem(const char *command) {
+int mysystem(const char* output, const char *command) {
char mycommand[STRING_SIZE];
- snprintf(mycommand, STRING_SIZE, "%s >>%s 2>>%s", command, mylog, mylog);
- fprintf(flog, "Running command: %s\n", command);
+ if (output == NULL)
+ output = "/dev/null";
+
+ snprintf(mycommand, sizeof(mycommand), "%s >>%s 2>&1", command, output);
+
+ FILE* f = fopen(output, "w+");
+ fprintf(f, "Running command: %s\n", command);
+ fclose(f);
return system(mycommand);
}
newtFormDestroy(f);
}
-int runcommandwithstatus(const char *command, const char* title, const char *message) {
+int runcommandwithstatus(const char *command, const char* title, const char *message, const char* output) {
statuswindow(60, 4, title, message);
- int rc = mysystem(command);
+ int rc = mysystem(output, command);
newtPopWindow();
return rc;
}
-int runhiddencommandwithstatus(const char *command, const char* title, const char *message) {
+int runhiddencommandwithstatus(const char *command, const char* title, const char *message, const char* output) {
statuswindow(60, 4, title, message);
- char mycommand[STRING_SIZE];
- snprintf(mycommand, STRING_SIZE, "%s >>%s 2>>%s", command, mylog, mylog);
- fprintf(flog, "Running command: ***** HIDDEN *****\n");
-
- int rc = system(mycommand);
+ int rc = mysystem(output, command);
newtPopWindow();
return rc;
newtDrawForm(f);
newtRefresh();
-
- snprintf(mycommand, STRING_SIZE, "%s 2>>%s", command, mylog);
- fprintf(flog, "Running command: %s\n", command);
-
+
if (!(p = popen(command, "r")))
{
rc = 1;
}
setvbuf(p, NULL, _IOLBF, 255);
- while (fgets(buffer, STRING_SIZE, p))
- {
+ while (fgets(buffer, STRING_SIZE, p)) {
newtScaleSet(s, ++progress);
newtRefresh();
- fprintf(flog, "%s", buffer);
}
-
+
rc = pclose(p);
EXIT:
if (!(file = fopen("/proc/modules", "r")))
{
- fprintf(flog, "Unable to open /proc/modules in checkformodule()\n");
+ fprintf(stderr, "Unable to open /proc/modules in checkformodule()\n");
return 0;
}
replacekeyvalue(dhcpkv, "ENABLE_GREEN", "on");
fclose(fopen(CONFIG_ROOT "/dhcp/enable_green", "w"));
chown(CONFIG_ROOT "/dhcp/enable_green", 99, 99);
- mysystem("/usr/local/bin/dhcpctrl enable");
+ mysystem(NULL, "/usr/local/bin/dhcpctrl enable");
}
else
{
replacekeyvalue(dhcpkv, "ENABLE_GREEN", "off");
unlink(CONFIG_ROOT "/dhcp/enable_green");
- mysystem("/usr/local/bin/dhcpctrl disable");
+ mysystem(NULL, "/usr/local/bin/dhcpctrl disable");
}
replacekeyvalue(dhcpkv, "VALID", "yes");
writekeyvalues(dhcpkv, CONFIG_ROOT "/dhcp/settings");
fclose(file);
chown(CONFIG_ROOT "/dhcp/dhcpd.conf", 99, 99);
if (automode == 0)
- mysystem("/usr/local/bin/dhcpctrl enable");
+ mysystem(NULL, "/usr/local/bin/dhcpctrl enable");
}
result = 1;
}
replacekeyvalue(kv, "KEYMAP", keymap);
writekeyvalues(kv, CONFIG_ROOT "/main/settings");
sprintf(commandstring, "/bin/loadkeys %s", keymap);
- mysystem(commandstring);
+ mysystem(NULL, commandstring);
result = 1;
}
else
fclose(file);
sprintf(commandstring, "/bin/hostname %s.%s", hostname, domainname);
- if (mysystem(commandstring))
+ if (mysystem(NULL, commandstring))
{
errorbox(_("Unable to set hostname."));
return 0;
{
char command[STRING_SIZE];
sprintf(command, "/etc/rc.d/init.d/mISDN config");
- if (runcommandwithstatus(command, _("ISDN"), _("Scanning and configuring ISDN devices.")))
+ if (runcommandwithstatus(command, _("ISDN"), _("Scanning and configuring ISDN devices."), NULL))
errorbox(_("Unable to scan for ISDN devices."));
// Need to write some lines that count the cards and say the names...
return 1;
char temp[STRING_SIZE];
sprintf(temp,"ip link show dev %s | grep -q UP", card);
- if (mysystem(temp)) return 0; else return 1;
+ if (mysystem(NULL, temp)) return 0; else return 1;
}
int rename_device(char *old_name, char *new_name) {
return 0;
}
sprintf(temp,"/sbin/ip link set dev %s name %s",old_name ,new_name );
- mysystem(temp);
+ mysystem(NULL, temp);
return 1;
}
char temp[STRING_SIZE];
sprintf(temp,"ip link set %s down", nic);
- mysystem(temp);
+ mysystem(NULL, temp);
}
int nic_startup(char *nic) {
char temp[STRING_SIZE];
sprintf(temp,"ip link set %s up", nic);
- mysystem(temp);
+ mysystem(NULL, temp);
}
if (!(scanned_nics_read_done))
{
- mysystem("/usr/bin/probenic.sh");
+ mysystem(NULL, "/usr/bin/probenic.sh");
if( (fp = fopen(SCANNED_NICS, "r")) == NULL )
{
fprintf(stderr,"Couldn't open "SCANNED_NICS);
_("Select"), _("Identify"), _("Cancel"), NULL);
if ( rc == 2 ) {
sprintf(temp, "/sbin/ip link set %s up", nics[found_NIC_as_Card[choise]].nic);
- mysystem(temp);
+ mysystem(NULL, temp);
sprintf(temp, "/usr/sbin/ethtool -p %s 10", nics[found_NIC_as_Card[choise]].nic);
- if (runcommandwithstatus(temp, _("Device Identification"), _("The lights on the selected port should flash now for 10 seconds...")) != 0) {
+ if (runcommandwithstatus(temp, _("Device Identification"), _("The lights on the selected port should flash now for 10 seconds..."), NULL) != 0) {
errorbox(_("Identification is not supported by this interface."));
sprintf(temp, "/sbin/ip link set %s down", nics[found_NIC_as_Card[choise]].nic);
- mysystem(temp);
+ mysystem(NULL, temp);
}
}
}
if (strlen(values[0]))
{
sprintf(commandstring, "/sbin/modprobe %s", values[0]);
- if (runcommandwithstatus(commandstring, _("Loading module..."), _("Loading module...")) == 0)
+ if (runcommandwithstatus(commandstring, _("Loading module..."), _("Loading module..."), NULL) == 0)
{
if ((driverend = strchr(values[0], ' ')))
{
if (netaddresschange)
{
runcommandwithstatus("/etc/rc.d/init.d/network stop",
- _("Networking"), _("Stopping network..."));
+ _("Networking"), _("Stopping network..."), NULL);
rename_nics();
runcommandwithstatus("/etc/rc.d/init.d/network start",
- _("Networking"), _("Restarting network..."));
+ _("Networking"), _("Restarting network..."), NULL);
}
} else {
rename_nics();
}
if (automode == 0)
runcommandwithstatus("/etc/rc.d/init.d/network stop red blue orange",
- _("Networking"), _("Restarting non-local network..."));
+ _("Networking"), _("Restarting non-local network..."), NULL);
findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp);
if (configtype == 1)
snprintf(commandstring, STRING_SIZE,
"/bin/echo 'root:%s' | /usr/sbin/chpasswd", password);
- if (runhiddencommandwithstatus(commandstring, _("Setting password"), _("Setting 'root' password...."))) {
+ if (runhiddencommandwithstatus(commandstring, _("Setting password"), _("Setting 'root' password...."), NULL)) {
errorbox(_("Problem setting 'root' password."));
return 0;
}
snprintf(commandstring, STRING_SIZE,
"/usr/sbin/htpasswd -c -m -b " CONFIG_ROOT "/auth/users admin '%s'", password);
sprintf(message, _("Setting %s 'admin' user password..."), NAME);
- if (runhiddencommandwithstatus(commandstring, _("Setting password"), message)) {
+ if (runhiddencommandwithstatus(commandstring, _("Setting password"), message, NULL)) {
sprintf(message, _("Problem setting %s 'admin' user password."), NAME);
errorbox(message);
return 0;