hi guys,
I new to unix im generating a script within c code.
I need to upgrade the software to a newer version and in need su privilege.
what is the correct syntax in running su within the script?
i would greatly appreciate your help
many thanks
rafael
/* Y o u r D e s c r i p t i o n */
/* AppBuilder Photon Code Lib */
/* Version 2.03 */
/* Standard headers */
#include <stdio.h>
#include <unistd.h>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <sstream>
/* Local headers */
#include "ablibs.h"
#include "AppGlobal.h"
#include "abimport.h"
#include "proto.h"
#include "version.h"
#include <sys/stat.h>
#include <sys/reboot.h>
struct stat sb;
using namespace std;
int
Yes( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo )
{
// find where abc/123/version x is located
system("find /fs/*/abc/123/*/ > /root/find.txt");
// only read the first result
std::string line;
std::ifstream stream("/root/find.txt");
getline(stream,line);
// current version
int maj = VERSION_MAJOR;
int min = VERSION_MINOR;
int pat = VERSION_PATCH;
// comparing to
int maj_comp = 0;
int min_comp = 0;
int pat_comp = 0;
// check if it is a valid folder
if (stat(line.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode))
{
unsigned found = line.find_last_of("/");
stringstream line_to_int;
line_to_int << line[found-5];
line_to_int >> maj_comp;
line_to_int.str("");
line_to_int << line[found-3];
line_to_int >> min_comp;
line_to_int.str("");
line_to_int << line[found-1];
line_to_int >> pat_comp;
//if ((maj_comp == maj) || ( min_comp == min) || ( pat_comp == pat))
if ((maj_comp != maj) || ( min_comp != min) || ( pat_comp != pat))
{
std::ofstream installation("/root/upgrade.sh");
if (installation.is_open())
{
installation << "#!/bin/sh\n";
//installation << "su -c \n";
installation << "cd " << line <<"\n";
installation << "sh ./install\n";
//installation << "shutdown";
installation.close();
}
system("chmod 777 /root/upgrade.sh");
system("/root/upgrade.sh");
}
else
{
cout << "current version is up to date" << endl;
}
}
// check path if it exist if it does check
// if current version is greater than upgrade
// perform upgrade
// else display error message cannot find file
// check if usb is properly connected
// check if path is valid
/* eliminate 'unreferenced' warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;
return( Pt_CONTINUE );
}