Commit 138ea237 authored by Mick Michalski's avatar Mick Michalski
Browse files

Removed preinst code, changed gateway script

parent cbca7174
......@@ -17,7 +17,7 @@ int main(void) {
/* Get the current boot settings */
FILE *f = fopen(devSettings, "r");
fgets(buffer, 5, f);
fread(buffer, 1, 4, f); /* read 4 bytes (4 * 1) from f */
fclose(f);
int doUpdate = 0;
......@@ -29,7 +29,7 @@ int main(void) {
if(doUpdate){
/* Create a temp file */
char tempFile[64];
strcpy(tempFile, "/tmp/swu-prepost-boot.XXXXXX");
strcpy(tempFile, "/tmp/swu-postinst-fs.XXXXXX");
int fd = mkstemp(tempFile);
write(fd, buffer, 4);
......@@ -39,6 +39,8 @@ int main(void) {
unlink(tempFile); /* automatically close and delete when done */
}
system("reboot");
return 0;
}
......@@ -17,7 +17,7 @@ int main(void) {
/* Get the current boot settings */
FILE *f = fopen(devSettings, "r");
fgets(buffer, 5, f);
fread(buffer, 1, 4, f); /* read 4 bytes (4 * 1) from f */
fclose(f);
int doUpdate = 0;
......@@ -29,7 +29,7 @@ int main(void) {
if(doUpdate){
/* Create a temp file */
char tempFile[64];
strcpy(tempFile, "/tmp/swu-prepost-boot.XXXXXX");
strcpy(tempFile, "/tmp/swu-postinst-k.XXXXXX");
int fd = mkstemp(tempFile);
write(fd, buffer, 4);
......@@ -39,6 +39,8 @@ int main(void) {
unlink(tempFile); /* automatically close and delete when done */
}
system("reboot");
return 0;
}
#include <stdlib.h>
#include <stdio.h>
int main(void) {
char *devSettings = getenv("DEVICE_SETTINGS");
char *devFsMain = getenv("DEVICE_FILESYSTEM_MAIN");
char *devFsAlt = getenv("DEVICE_FILESYSTEM_ALT");
char buffer[16];
FILE *f = fopen(devSettings, "r");
fgets(buffer, 5, f);
fclose(f);
char cmd[128];
system("rm /dev/dev-fs > /dev/null"); /* Delete the current link if exists, suppressing output */
if(buffer[3] == '0'){ /* The current filesystem */
snprintf(cmd, 127, "ln -s %s /dev/dev-fs", devFsAlt);
system(cmd); /* Create a new link to alt fs partition */
} else {
snprintf(cmd, 127, "ln -s %s /dev/dev-fs", devFsMain);
system(cmd); /* Create a new link to main fs partition */
}
return 0;
}
#include <stdlib.h>
#include <stdio.h>
int main(void) {
char *devSettings = getenv("DEVICE_SETTINGS");
char *devKMain = getenv("DEVICE_KERNEL_MAIN");
char *devKAlt = getenv("DEVICE_KERNEL_ALT");
char buffer[16];
FILE *f = fopen(devSettings, "r");
fgets(buffer, 5, f);
fclose(f);
char cmd[128];
system("rm /dev/dev-fs > /dev/null"); /* Delete the current link if exists, suppressing output */
if(buffer[2] == '0'){ /* The current filesystem */
snprintf(cmd, 127, "ln -s %s /dev/dev-fs", devKAlt);
system(cmd); /* Create a new link to alt kernel partition */
} else {
snprintf(cmd, 127, "ln -s %s /dev/dev-fs", devKMain);
system(cmd); /* Create a new link to main kernel partition */
}
return 0;
}
......@@ -9,17 +9,22 @@ extern char **environ;
int main(void) {
char *devSettings = getenv("DEVICE_SETTINGS");
char *devFsMain = getenv("DEVICE_FILESYSTEM_MAIN");
char *devFsAlt = getenv("DEVICE_FILESYSTEM_ALT");
char *devKMain = getenv("DEVICE_KERNEL_MAIN");
char *devKAlt = getenv("DEVICE_KERNEL_ALT");
if(!devSettings) {
printf("No settings found");
return 1;
}
char buffer[128];
char buffer[5];
int doUpdate=0;
/* Get the current boot settings */
FILE *f = fopen(devSettings, "r");
fgets(buffer, 5, f);
fread(buffer, 1, 4, f); /* read 4 bytes (4 * 1) from f */
fclose(f);
/* Set the current boot partitions */
......@@ -33,6 +38,8 @@ int main(void) {
doUpdate = 1;
}
char cmd[128];
if(doUpdate){
printf("Updating device settings with new boot partitions\n");
......@@ -43,13 +50,29 @@ int main(void) {
write(fd, buffer, 4);
/* Write temp file to mtd0, then delete temp file */
snprintf(buffer, 127, "flashcp %s %s", tempFile, devSettings);
system(buffer);
snprintf(cmd, 127, "flashcp %s %s", tempFile, devSettings);
system(cmd);
unlink(tempFile); /* automatically close and delete when done */
} else {
printf("Device settings unchanged\n");
}
if(buffer[3] == '0'){ /* The current filesystem */
snprintf(cmd, 127, "ln -sf %s /dev/dev-fs", devFsAlt);
system(cmd); /* Create a new link to alt fs partition */
} else {
snprintf(cmd, 127, "ln -sf %s /dev/dev-fs", devFsMain);
system(cmd); /* Create a new link to main fs partition */
}
if(buffer[2] == '0'){ /* The current filesystem */
snprintf(cmd, 127, "ln -sf %s /dev/dev-k", devKAlt);
system(cmd); /* Create a new link to alt kernel partition */
} else {
snprintf(cmd, 127, "ln -sf %s /dev/dev-k", devKMain);
system(cmd); /* Create a new link to main kernel partition */
}
return 0;
}
source /etc/gateway.conf
/usr/bin/swupdate-prepost-boot
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment