]> git.rkrishnan.org Git - pihpsdr.git/commitdiff
start of code update
authorJohn Melton - G0ORX/N6LYT <john.d.melton@googlemail.com>
Sun, 11 Dec 2016 20:11:11 +0000 (20:11 +0000)
committerJohn Melton - G0ORX/N6LYT <john.d.melton@googlemail.com>
Sun, 11 Dec 2016 20:11:11 +0000 (20:11 +0000)
Makefile
new_menu.c
test_menu.c
update.c [new file with mode: 0644]
update.h [new file with mode: 0644]

index 8383099a254b3d51a1cfd1a0305ec80ec8f1b730..a67664c90a7e9eca82c53773824455fff8c9a5fa 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -192,7 +192,8 @@ vfo.c \
 waterfall.c \
 wdsp_init.c \
 button_text.c \
-vox.c
+vox.c \
+update.c
 
 
 HEADERS= \
@@ -251,7 +252,8 @@ vfo.h \
 waterfall.h \
 wdsp_init.h \
 button_text.h \
-vox.h
+vox.h \
+update.h
 
 
 OBJS= \
@@ -308,7 +310,8 @@ vfo.o \
 waterfall.o \
 wdsp_init.o \
 button_text.o \
-vox.o
+vox.o \
+update.o
 
 all: prebuild $(PROGRAM) $(HEADERS) $(LIMESDR_HEADERS) $(FREEDV_HEADERS) $(LOCALCW_HEADERS) $(GPIO_HEADERS) $(PSK_HEADERS) $(SOURCES) $(LIMESDR_SOURCES) $(FREEDV_SOURCES) $(GPIO_SOURCES) $(PSK_SOURCES)
 
@@ -331,4 +334,5 @@ install:
        cp pihpsdr ./release/pihpsdr
        cd release; tar cvf pihpsdr_$(GIT_VERSION).tar pihpsdr
        cd release; tar cvf pihpsdr.tar pihpsdr
+       cd release; echo $(GIT_VERSION) > pihpsdr/latest
 
index dc65b2ab0c0a2aa15974c8ad1a1aee547fb7ea10..1509f71a4beac406ec3604a6f51384e37cf98844 100644 (file)
@@ -417,11 +417,9 @@ static gboolean new_menu_pressed_event_cb (GtkWidget *widget,
     g_signal_connect (agc_b, "button-press-event", G_CALLBACK(agc_cb), NULL);
     gtk_grid_attach(GTK_GRID(grid),agc_b,5,4,1,1);
 
-/*
     GtkWidget *test_b=gtk_button_new_with_label("Test");
     g_signal_connect (test_b, "button-press-event", G_CALLBACK(test_cb), NULL);
     gtk_grid_attach(GTK_GRID(grid),test_b,0,5,1,1);
-*/
 
     gtk_container_add(GTK_CONTAINER(content),grid);
 
index 2b0191a62d2122984a33495696bc870f693a2c16..197f28ad4c6bc01497b34f9c02a9ba6840c71afd 100644 (file)
@@ -22,6 +22,7 @@
 #include <string.h>
 
 #include "new_menu.h"
+#include "update.h"
 
 static GtkWidget *parent_window=NULL;
 
@@ -37,7 +38,15 @@ static gboolean close_cb (GtkWidget *widget, GdkEventButton *event, gpointer dat
 }
 
 static gboolean test_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
-  gtk_window_iconify(GTK_WINDOW(parent_window));
+  
+  int result=check_update();
+  fprintf(stderr,"check_update returned %d\n",result);
+
+  if(result>0) {
+    result=load_update();
+    fprintf(stderr,"load_update returned %d\n",result);
+  }
+
   return TRUE;
 }
 
diff --git a/update.c b/update.c
new file mode 100644 (file)
index 0000000..59de7ff
--- /dev/null
+++ b/update.c
@@ -0,0 +1,64 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <errno.h>
+
+#include "update.h"
+#include "version.h"
+
+char new_version[128];
+
+int check_update() {
+
+  int rc=system("/usr/bin/wget -N https://github.com/g0orx/pihpsdr/raw/master/release/pihpsdr/latest");
+  fprintf(stderr,"rc=%d\n", rc);
+  if(rc==-1) {
+    fprintf(stderr,"wget: errno=%d\n", errno);
+  }
+
+  fprintf(stderr,"check_version: current version is %s\n",version);
+  strcpy(new_version,"");
+
+  FILE* f=fopen("latest","r");
+  if(f) {
+    fgets(new_version,sizeof(new_version),f);
+    fclose(f);
+  } else {
+    fprintf(stderr,"check_update: could not read latest version\n");
+    return -1;
+  }
+
+  if(strlen(new_version)==0) {
+    return -2;
+  }
+
+  if(strlen(new_version)>0) {
+    if(new_version[strlen(new_version)-1]=='\n') {
+      new_version[strlen(new_version)-1]='\0';
+    }
+  }
+
+  fprintf(stderr,"check_version: latest version is %s\n",new_version);
+
+  fprintf(stderr,"check_version: length of version=%d length of new_version=%d\n", strlen(version), strlen(new_version));
+  rc=strcmp(version,new_version);
+
+  return rc;
+}
+
+int load_update() {
+  char command[1024];
+  sprintf(command,"/usr/sbin/wget -N https://github.com/g0orx/pihpsdr/raw/master/release/pihpsdr_%s.tar",new_version);
+
+fprintf(stderr,"load_update: %s\n",command);
+  int rc=system(command);
+  fprintf(stderr,"rc=%d\n", rc);
+  if(rc==-1) {
+    fprintf(stderr,"wget: errnoc=%d\n", errno);
+  } else {
+    fprintf(stderr,"load_update: %s loaded\n", new_version);
+  }
+  return rc;
+}
diff --git a/update.h b/update.h
new file mode 100644 (file)
index 0000000..ef4a5ed
--- /dev/null
+++ b/update.h
@@ -0,0 +1,4 @@
+char new_version[];
+
+extern int check_update();
+extern int load_update();