#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <sys/sysmgr.h>
#include <sys/mount.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "CIC_HU.h"
const char* _target = "/EFS_RO/startl6sss.sh";
const char* _backup = "/EFS_RO/startl6sss.sav";
const char* _script = "/EFS_RO/SWT_enable.sh";
int _remount() {
return mount(NULL,"/mnt/EFS_RO",_MOUNT_REMOUNT,NULL,NULL,NULL);
}
void _reboot() {
sysmgr_reboot();
}
void _deploy_enabler(){
remove(_script);
FILE *f2 = fopen(_script,"ab+");
fwrite(_enabler,sizeof(char),sizeof(_enabler),f2);
fclose(f2);
chmod(_script, S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH);
};
int _modify_startup() {
FILE *f0;
FILE *f1;
int i = 0;
int ctr = 0;
rename(_target, _backup);
f0 = fopen(_backup,"r");
f1 = fopen(_target,"ab+");
if(f0!=NULL) {
while((i=fgetc(f0)) != EOF) {
if(ctr==11) {
fprintf(f1, "%s &\n",_script);
} else {
fputc(i,f1);
}
ctr++;
}
fclose(f0);
fclose(f1);
chmod(_target, S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH);
return 0;
}
return -1;
};
bool _fileexists (const char * _filename) {
if (FILE *file = fopen(_filename, "r")) {
fclose(file);
return true;
} else {
return false;
}
}
int main(int argc, char *argv[]) {
std::cout << "CIC_HU - Script aktivator" << std::endl;
if(_fileexists(_backup)) {
std::cout << "Backup fajl postoji." << std::endl;
return 1;
}
if (_remount() == -1) {
std::cout << "Remount problem" << std::endl;
return 1;
}
if (_modify_startup() != 0) {
std::cout << "problem pri izvrsavanju" << std::endl;
return 1;
}
_deploy_enabler();
std::cout << "Zavrseno" << std::endl;
_reboot();
return 0;
}