Skip to content
This repository has been archived by the owner on Jan 1, 2025. It is now read-only.

Making the update process use the repo's upstream and branch #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ VERSION = -DVERSION_MAJ=$(VERSION_MAJ) -DVERSION_MIN=$(VERSION_MIN)
VER = v$(VERSION_MAJ).$(VERSION_MIN)
FLAGS += $(I) $(VERSION) -DKIWI -DARCH_$(ARCH) -DPLATFORM_$(PLATFORM)
FLAGS += -DKIWI_UI_LIST=$(UI_LIST) -DDIR_CFG=\"$(DIR_CFG)\" -DCFG_PREFIX=\"$(CFG_PREFIX)\"
FLAGS += -DREPO=\"$(REPO)\" -DREPO_NAME=\"$(REPO_NAME)\"
FLAGS += -DREPO=\"$(REPO)\" -DREPO_NAME=\"$(REPO_NAME)\" -DBRANCH=\"$(BRANCH)\"
CSRC = $(notdir $(CFILES))
CSRC_O3 = $(notdir $(CFILES_O3))
OBJECTS1 = $(CSRC:%.c=$(OBJ_DIR)/%.o)
Expand Down Expand Up @@ -224,6 +224,8 @@ kiwid.bin: c_ctr_reset $(OBJ_DIR) $(OBJ_DIR_O3) $(KEEP_DIR) $(OBJECTS) $(O3_OBJE

debug:
@echo version $(VER)
@echo Upstream $(REPO)
@echo Branch $(BRANCH)
@echo DEPS = $(OBJECTS:.o=.d)
@echo KIWI_UI_LIST = $(UI_LIST)
@echo DEBIAN_DEVSYS = $(DEBIAN_DEVSYS)
Expand Down Expand Up @@ -440,8 +442,10 @@ update_check:
diff Makefile Makefile.1

DIST = kiwi
REPO_NAME = Beagle_SDR_GPS
REPO = https://github.com/jks-prv/$(REPO_NAME).git
# Use the git upstream of the current directory to determine the git repo & name
REPO = $(shell git config --get remote.origin.url)
REPO_NAME=$(notdir $(REPO))
BRANCH = $(shell git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
V_DIR = ~/shared/shared

# selectively transfer files to the target so everything isn't compiled each time
Expand Down
5 changes: 4 additions & 1 deletion tools/kiwiSDR-customize-Debian-distro-with-KiwiSDR-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ echo "--- install git"
apt-get -y install git

# Beagle_SDR_GPS sources need to be a git clone so update scheme works
# This is hardcoded to jks's repo until a better plan for how forks/branches
# _should_ interact as part of a managed install.
echo "--- clone KiwiSDR from github"
echo -n hit enter when ready: ; read
git clone https://github.com/jks-prv/Beagle_SDR_GPS.git || true
#repo="https://github.com/TomGaussiran/Beagle_SDR_GPS"
git clone $repo || true

echo "--- install tools"
apt-get -y install man
Expand Down
4 changes: 3 additions & 1 deletion unix_env/bashrc
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ alias db="systemctl reload-or-restart dropbear.socket"
alias dk="diff -r . merge"

# KiwiSDR

alias kd="cdp; m stop; touch ~root/.kiwi_down; m start"
alias ku="cdp; m stop; rm -f ~root/.kiwi_down; m start"
alias kuf="cdp; echo force build; m stop; rm -f ~root/.kiwi_down; touch ~root/.force_build; m start"
Expand All @@ -111,5 +112,6 @@ alias vg="valgrind -v --track-origins=yes --leak-check=full kiwi.bin -gps"
alias vggps="valgrind -v --track-origins=yes --leak-check=full kiwi.bin"
alias vggdb="valgrind -v --track-origins=yes --leak-check=full --vgdb-error=0 kiwi.bin -gps"
alias vggdbgps="valgrind -v --track-origins=yes --leak-check=full --vgdb-error=0 kiwi.bin"
alias scD="git clone https://github.com/jks-prv/Beagle_SDR_GPS.git"
repo=`(cd ~/Beagle_SDR_GPS; git config --get remote.origin.url)`
alias scD="git clone $repo"
alias wk="json_pp -t dumper <~root/kiwi.config/kiwi.json | grep rx_name"
150 changes: 87 additions & 63 deletions update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Boston, MA 02110-1301, USA.
#include "web.h"
#include "cfg.h"
#include "coroutines.h"
#include <string>

#include <types.h>
#include <unistd.h>
Expand Down Expand Up @@ -52,76 +53,99 @@ static void update_build(void *param)
exit(0);
}


static void update_task(void *param)
{
int status;
bool check_only = (bool) param;

lprintf("UPDATE: checking for updates\n");
status = system("cd /root/" REPO_NAME "; wget --no-check-certificate https://raw.githubusercontent.com/jks-prv/Beagle_SDR_GPS/master/Makefile -O Makefile.1");
using std::string;

if (status < 0 || WEXITSTATUS(status) != 0) {
lprintf("UPDATE: wget Makefile, no Internet access?\n");
update_pending = update_in_progress = false;
return;
}
int status;
bool check_only = (bool) param;

FILE *fp;
scallz("fopen Makefile.1", (fp = fopen("/root/" REPO_NAME "/Makefile.1", "r")));
int n1, n2;
n1 = fscanf(fp, "VERSION_MAJ = %d\n", &pending_maj);
n2 = fscanf(fp, "VERSION_MIN = %d\n", &pending_min);
fclose(fp);

bool ver_changed = (n1 == 1 && n2 == 1 && (pending_maj > VERSION_MAJ || (pending_maj == VERSION_MAJ && pending_min > VERSION_MIN)));
bool update_install = (cfg_bool("update_install", NULL, CFG_REQUIRED) == true);

if (check_only && !force_build) {
if (ver_changed)
lprintf("UPDATE: version changed (current %d.%d, new %d.%d), but check only\n",
VERSION_MAJ, VERSION_MIN, pending_maj, pending_min);
else
lprintf("UPDATE: running most current version\n");
update_pending = update_in_progress = false;
return;
} else
lprintf("UPDATE: checking for updates from " REPO "\n");
using namespace std;
string repo(REPO);
string repo_name(REPO_NAME);
string branch(BRANCH);

if (repo.find("https://github.com/") != 0) {
lprintf("UPDATE: Upstream (%s) must be at github to continue with update\n", repo.substr(0,19).c_str());
update_pending = update_in_progress = false;
return;
}
// Remove any trailing ".git"
size_t p = repo_name.rfind(".git");
if (p != string::npos)
repo_name.erase(p);
p = repo.rfind(".git");
if (p != string::npos)
repo.erase(p);

if (ver_changed && !update_install && !force_build) {
lprintf("UPDATE: version changed (current %d.%d, new %d.%d), but update install not enabled\n",
VERSION_MAJ, VERSION_MIN, pending_maj, pending_min);
} else
string repo_dir = "/root/" + repo_name;
string mfn = repo_dir + "/Makefile.1";

string cmd = "wget -q --no-check-certificate https://raw.githubusercontent.com/" +
repo.substr(19) + "/" + branch + "/Makefile -O " + mfn;
lprintf("UPDATE: %s\n", cmd.c_str());
status = system(cmd.c_str());

if (status < 0 || WEXITSTATUS(status) != 0) {
lprintf("UPDATE: cmd failed\n");
update_pending = update_in_progress = false;
return;
}

if (ver_changed || force_build) {
lprintf("UPDATE: version changed%s, current %d.%d, new %d.%d\n",
force_build? " (forced)":"",
VERSION_MAJ, VERSION_MIN, pending_maj, pending_min);
lprintf("UPDATE: building new version..\n");

// Run build in a Linux child process so the server can continue to respond to connection requests
// and display a "software update in progress" message.
// This is because the calls to system() in update_build() block for the duration of the build.
status = child_task(SEC_TO_MSEC(1), update_build, (void *) (long) force_build);
int exited = WIFEXITED(status);
int exit_status = WEXITSTATUS(status);

if (! (exited && exit_status == 0)) {
if (exited) {
lprintf("UPDATE: git pull, no Internet access?\n");
//lprintf("UPDATE: error in build, exit status %d, aborting\n", exit_status);
} else {
lprintf("UPDATE: error in build, non-normal exit, aborting\n");
}
update_pending = update_in_progress = false;
return;
}
FILE *fp;
scallz("fopen Makefile.1", (fp = fopen(mfn.c_str(), "r")));
int n1, n2;
n1 = fscanf(fp, "VERSION_MAJ = %d\n", &pending_maj);
n2 = fscanf(fp, "VERSION_MIN = %d\n", &pending_min);
fclose(fp);

bool ver_changed = (n1 == 1 && n2 == 1 && (pending_maj > VERSION_MAJ || (pending_maj == VERSION_MAJ && pending_min > VERSION_MIN)));
bool update_install = (cfg_bool("update_install", NULL, CFG_REQUIRED) == true);

if (check_only && !force_build) {
if (ver_changed)
lprintf("UPDATE: version changed (current %d.%d, new %d.%d), but check only\n",
VERSION_MAJ, VERSION_MIN, pending_maj, pending_min);
update_pending = update_in_progress = false;
return;
} else

if (ver_changed && !update_install && !force_build) {
lprintf("UPDATE: version changed (current %d.%d, new %d.%d), but update install not enabled\n",
VERSION_MAJ, VERSION_MIN, pending_maj, pending_min);
} else if (ver_changed || force_build) {
lprintf("UPDATE: version changed%s, current %d.%d, new %d.%d\n",
force_build? " (forced)":"",
VERSION_MAJ, VERSION_MIN, pending_maj, pending_min);
lprintf("UPDATE: building new version..\n");

// Run build in a Linux child process so the server can continue to respond to connection requests
// and display a "software update in progress" message.
// This is because the calls to system() in update_build() block for the duration of the build.
status = child_task(SEC_TO_MSEC(1), update_build, (void *) (long) force_build);
int exited = WIFEXITED(status);
int exit_status = WEXITSTATUS(status);

if (! (exited && exit_status == 0)) {
if (exited) {
lprintf("UPDATE: git pull, no Internet access?\n");
//lprintf("UPDATE: error in build, exit status %d, aborting\n", exit_status);
} else {
lprintf("UPDATE: error in build, non-normal exit, aborting\n");
}
update_pending = update_in_progress = false;
return;
}

lprintf("UPDATE: switching to new version %d.%d\n", pending_maj, pending_min);
xit(0);
} else {
lprintf("UPDATE: version %d.%d is current\n", VERSION_MAJ, VERSION_MIN);
}
update_pending = update_in_progress = false;
lprintf("UPDATE: switching to new version %d.%d\n", pending_maj, pending_min);
xit(0);
} else {
lprintf("UPDATE: version %d.%d is current\n", VERSION_MAJ, VERSION_MIN);
}
update_pending = update_in_progress = false;
}

// called on each user logout or on demand by UI
Expand Down