version 1.1.2.3, 2009/11/13 23:19:23
|
version 1.1.2.7, 2010/03/24 16:46:39
|
Line 1
|
Line 1
|
|
/************************************************************************* |
|
* (C) 2010 AITNET - Sofia/Bulgaria - <office@aitbg.com> |
|
* by Michael Pounov <misho@aitbg.com> |
|
* |
|
* $Author$ |
|
* $Id$ |
|
* |
|
*************************************************************************/ |
#include "global.h" |
#include "global.h" |
#include "upd.h" |
#include "upd.h" |
|
#include "tftp.h" |
|
|
|
|
sl_config cfg; |
sl_config cfg; |
Line 13 static void Usage()
|
Line 22 static void Usage()
|
"=== %s === %s@%s ===\n\n" |
"=== %s === %s@%s ===\n\n" |
" Syntax: updimg [-v] <modes> <image_name> [operate_dir]\n\n" |
" Syntax: updimg [-v] <modes> <image_name> [operate_dir]\n\n" |
"\t-v\t\tVerbose ...\n\n" |
"\t-v\t\tVerbose ...\n\n" |
|
"\t-D\t\tRun tftp server and watch for updates (image_name==ip:port)\n" |
"\t-a\t\tMake image active for next boot\n" |
"\t-a\t\tMake image active for next boot\n" |
"\t-i\t\tInstall new image\n" | "\t-i <tftp_dir>\tInstall new image\n" |
"\t-r\t\tRollback old backuped image\n" |
"\t-r\t\tRollback old backuped image\n" |
"\t-t <tftp_dir>\tExport for TFTP download\n" |
"\t-t <tftp_dir>\tExport for TFTP download\n" |
"\t-b\t\tBackup image\n" |
"\t-b\t\tBackup image\n" |
Line 26 static void Usage()
|
Line 36 static void Usage()
|
|
|
int main(int argc, char **argv) |
int main(int argc, char **argv) |
{ |
{ |
char ch, szImg[MAXPATHLEN], szTFTP[MAXPATHLEN]; | char ch, *pos, szImg[MAXPATHLEN], szTFTP[MAXPATHLEN]; |
int mode; |
int mode; |
|
struct hostent *host; |
|
struct sockaddr_in sin; |
|
|
while ((ch = getopt(argc, argv, "hvdbt:air")) != -1) | while ((ch = getopt(argc, argv, "hvdbt:ai:rD")) != -1) |
switch (ch) { |
switch (ch) { |
|
case 'D': |
|
Mode |= 0x40; |
|
break; |
case 'a': |
case 'a': |
Mode |= 0x1; |
Mode |= 0x1; |
break; |
break; |
Line 39 int main(int argc, char **argv)
|
Line 54 int main(int argc, char **argv)
|
strlcpy(szTFTP, optarg, MAXPATHLEN); |
strlcpy(szTFTP, optarg, MAXPATHLEN); |
break; |
break; |
case 'r': |
case 'r': |
if (Mode & 0x2) { | if (Mode & 0x10) { |
printf("Error:: can`t set rollback mode because find set install ...\n"); |
printf("Error:: can`t set rollback mode because find set install ...\n"); |
return 1; |
return 1; |
} else |
} else |
Mode |= 0x4; | Mode |= 0x20; |
break; |
break; |
case 'i': |
case 'i': |
if (Mode & 0x4) { | if (Mode & 0x20) { |
printf("Error:: can`t set install mode because find set rollback ...\n"); |
printf("Error:: can`t set install mode because find set rollback ...\n"); |
return 1; |
return 1; |
} else |
} else |
Mode |= 0x2; | Mode |= 0x10; |
| strlcpy(szTFTP, optarg, MAXPATHLEN); |
break; |
break; |
case 'b': |
case 'b': |
if (Mode & 0x20) { | if (Mode & 0x4) { |
printf("Error:: can`t set backup mode because find set clean ...\n"); |
printf("Error:: can`t set backup mode because find set clean ...\n"); |
return 1; |
return 1; |
} else |
} else |
Mode |= 0x10; | Mode |= 0x2; |
break; |
break; |
case 'd': |
case 'd': |
if (Mode & 0x10) { | if (Mode & 0x2) { |
printf("Error:: can`t set clean mode because find set backup ...\n"); |
printf("Error:: can`t set clean mode because find set backup ...\n"); |
return 1; |
return 1; |
} else |
} else |
Mode |= 0x20; | Mode |= 0x4; |
break; |
break; |
case 'v': |
case 'v': |
Verbose++; |
Verbose++; |
Line 87 int main(int argc, char **argv)
|
Line 103 int main(int argc, char **argv)
|
return 1; |
return 1; |
} else |
} else |
basename_r(*argv, szImg); |
basename_r(*argv, szImg); |
if (argc > 1) { | if (0x40 & Mode) { |
| if (0x40 != Mode) { |
| printf("Error:: Daemon mode can`t be specified with others ...\n"); |
| return 1; |
| } |
| |
| pos = strchr(szImg, ':'); |
| if (!pos) |
| sin.sin_port = htons(DEFAULT_TFTP); |
| else { |
| *pos++ = 0; |
| sin.sin_port = htons(atoi(pos)); |
| if (!sin.sin_port) |
| sin.sin_port = htons(DEFAULT_TFTP); |
| } |
| host = gethostbyname(szImg); |
| if (!host) { |
| printf("Error:: in resolv host %s #%d - %s\n", szImg, h_errno, hstrerror(h_errno)); |
| return 1; |
| } else |
| memcpy(&sin.sin_addr.s_addr, host->h_addr, host->h_length); |
| |
| strlcpy(szTFTP, !argv[1] ? DEFAULT_TFTPDIR : argv[1], MAXPATHLEN); |
chdir(argv[1]); |
chdir(argv[1]); |
VERB(5) printf("Info(5):: Change to dir %s\n", argv[1]); | VERB(2) printf("Info(2):: Host %s Port %d in Dir %s\n", |
} | inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), szTFTP); |
| } else |
| if (argc > 1) { |
| chdir(argv[1]); |
| VERB(5) printf("Info(5):: Change to dir %s\n", argv[1]); |
| } |
|
|
openlog("updimg", LOG_CONS, 0); |
openlog("updimg", LOG_CONS, 0); |
|
|
for (mode = 0x20; mode; mode >>= 1) | for (mode = 0x40; mode; mode >>= 1) |
switch (Mode & mode) { |
switch (Mode & mode) { |
case 0x1: |
case 0x1: |
Activate(szImg); |
Activate(szImg); |
break; |
break; |
case 0x2: |
case 0x2: |
Install(); | Backup(szImg); |
break; |
break; |
case 0x4: |
case 0x4: |
Rollback(szImg); | Clean(szImg); |
break; |
break; |
case 0x8: |
case 0x8: |
tFTP(szImg, szTFTP); |
tFTP(szImg, szTFTP); |
break; |
break; |
case 0x10: |
case 0x10: |
Backup(szImg, NULL); | Install(szImg, szTFTP); |
break; |
break; |
case 0x20: |
case 0x20: |
Clean(szImg); | Rollback(szImg); |
| break; |
| case 0x40: |
| Daemonize(sin, szTFTP); |
break; |
break; |
} |
} |
|
|