Commit d35a940a authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

optimized

parent d26cadbb
...@@ -4,6 +4,8 @@ REMOTE_USER ??= "root" ...@@ -4,6 +4,8 @@ REMOTE_USER ??= "root"
REMOTE_IP ??= "192.168.0.9" REMOTE_IP ??= "192.168.0.9"
IDENTITY_FILE ??= "~/.ssh/id_rsa" IDENTITY_FILE ??= "~/.ssh/id_rsa"
inherit elphel-ssh
#do_target_scp () { #do_target_scp () {
# #Without next echo - no trace of the scp in the log! # #Without next echo - no trace of the scp in the log!
# SSH_COMMAND='tar -C / -xzpf /image.tar.gz; rm -f /image.tar.gz; sync' # SSH_COMMAND='tar -C / -xzpf /image.tar.gz; rm -f /image.tar.gz; sync'
...@@ -17,19 +19,22 @@ IDENTITY_FILE ??= "~/.ssh/id_rsa" ...@@ -17,19 +19,22 @@ IDENTITY_FILE ??= "~/.ssh/id_rsa"
python do_target_scp () { python do_target_scp () {
import subprocess import subprocess
WORKDIR = d.getVar('WORKDIR', True) WORKDIR = d.getVar('WORKDIR' , True)
IDENTITY_FILE = d.getVar('IDENTITY_FILE', True) IDENTITY_FILE = d.getVar('IDENTITY_FILE', True)
REMOTE_USER = d.getVar('REMOTE_USER', True) REMOTE_USER = d.getVar('REMOTE_USER' , True)
REMOTE_IP = d.getVar('REMOTE_IP', True) REMOTE_IP = d.getVar('REMOTE_IP' , True)
COPY_TO_NAND = d.getVar('COPY_TO_NAND', True) COPY_TO_NAND = d.getVar('COPY_TO_NAND' , True)
MMC2 = "/dev/mmcblk0p2" # hardcodign for now
MMC2 = "/dev/mmcblk0p2"
MMC2MNT = "/mnt/mmc2" MMC2MNT = "/mnt/mmc2"
cmd = "tar -czvf "+WORKDIR+"/image.tar.gz -C "+WORKDIR+"/image ." cmd = "tar -czvf "+WORKDIR+"/image.tar.gz -C "+WORKDIR+"/image ."
print("cmd: "+cmd)
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
cmd = "ping "+REMOTE_IP+" -c 1" cmd = "ping "+REMOTE_IP+" -c 1"
print("cmd: "+cmd)
try: try:
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
...@@ -44,6 +49,7 @@ python do_target_scp () { ...@@ -44,6 +49,7 @@ python do_target_scp () {
if nandboot=="1": if nandboot=="1":
#copy archive #copy archive
cmd = "scp -i "+IDENTITY_FILE+" -p "+WORKDIR+"/image.tar.gz "+REMOTE_USER+"@"+REMOTE_IP+":/" cmd = "scp -i "+IDENTITY_FILE+" -p "+WORKDIR+"/image.tar.gz "+REMOTE_USER+"@"+REMOTE_IP+":/"
print("cmd: "+cmd)
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
#unpack archive to / #unpack archive to /
command_over_ssh(d,"'tar -C / -xzpf /image.tar.gz; sync'") command_over_ssh(d,"'tar -C / -xzpf /image.tar.gz; sync'")
...@@ -95,25 +101,13 @@ python do_target_scp () { ...@@ -95,25 +101,13 @@ python do_target_scp () {
command_over_ssh(d,"'tar -C / -xzpf /image.tar.gz; rm -f /image.tar.gz; sync'") command_over_ssh(d,"'tar -C / -xzpf /image.tar.gz; rm -f /image.tar.gz; sync'")
} }
def command_over_ssh(d,command):
import subprocess
user = d.getVar('REMOTE_USER', True)
id = d.getVar('IDENTITY_FILE', True)
ip = d.getVar('REMOTE_IP', True)
cmd = "ssh -i "+id+" "+user+"@"+ip+" "+command
try:
ret = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
except subprocess.CalledProcessError:
raise Exception("Copying to target requires access by public key. Run: \033[1;37mssh-copy-id "+REMOTE_USER+"@"+REMOTE_IP+"\033[0m")
return ret.strip()
addtask do_target_scp after do_install addtask do_target_scp after do_install
do_target_scp[doc] = "scp installed files to the target. TARGET_USER and TARGET_IP should be defined (ssh-copy-id -i KEY.pub TARGET_USER@TARGET_IP should be issued once)" do_target_scp[doc] = "scp installed files to the target. TARGET_USER and TARGET_IP should be defined (ssh-copy-id -i KEY.pub TARGET_USER@TARGET_IP should be issued once)"
EXPORT_FUNCTIONS do_target_scp #EXPORT_FUNCTIONS do_target_scp
#EXPORT_FUNCTIONS command_over_ssh
#REMOTE_USER=root #REMOTE_USER=root
#REMOTE_IP=192.168.0.7 #REMOTE_IP=192.168.0.7
......
# Need this function in another reipe
def command_over_ssh(d,command):
import subprocess
user = d.getVar('REMOTE_USER', True)
id = d.getVar('IDENTITY_FILE', True)
ip = d.getVar('REMOTE_IP', True)
cmd = "ssh -i "+id+" "+user+"@"+ip+" "+command
print("cmd: "+cmd)
try:
ret = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
except subprocess.CalledProcessError:
raise Exception("Copying to target requires access by public key. Run: \033[1;37mssh-copy-id "+REMOTE_USER+"@"+REMOTE_IP+"\033[0m")
return ret.strip()
...@@ -20,6 +20,11 @@ deltask do_rm_work ...@@ -20,6 +20,11 @@ deltask do_rm_work
inherit nopackages inherit nopackages
inherit elphel-ssh elphel-misc
PE = "1"
PV = "0"
PR = "0"
INHIBIT_DEFAULT_DEPS = "1" INHIBIT_DEFAULT_DEPS = "1"
DEPENDS = "" DEPENDS = ""
PACKAGES = "" PACKAGES = ""
...@@ -27,13 +32,13 @@ PACKAGES = "" ...@@ -27,13 +32,13 @@ PACKAGES = ""
python do_run(){ python do_run(){
user = d.getVar('REMOTE_USER', True) user = d.getVar('REMOTE_USER', True)
ip = d.getVar('REMOTE_IP', True) ip = d.getVar('REMOTE_IP', True)
# all hardcoded
pdir = "/etc/elphel393/packages" pdir = "/etc/elphel393/packages"
localpdir = "rootfs-elphel" localpdir = "rootfs-elphel"
imagedir = "image" imagedir = "image"
topdir = d.getVar('TOPDIR', True)+"/../../" topdir = d.getVar('TOPDIR', True)+"/../../"
projects_list = topdir+"projects.json" projects_list = topdir+"projects.json"
print("Checking packages' versions - locally built vs installed on the remote system") print("Checking packages' versions - locally built vs installed on the remote system")
...@@ -102,49 +107,3 @@ python do_run(){ ...@@ -102,49 +107,3 @@ python do_run(){
} }
addtask do_run before do_build addtask do_run before do_build
def version_update(path,file,evr):
import os.path
if not os.path.exists(path+'/'+file):
return 0
f=open(path+'/'+file)
for line in f:
line = line.strip()
if (line[0]!="#"):
break
arr = line.split('.')
try:
arr[evr]
except IndexError:
if (evr==1): res = 0
if (evr==2): res = revision_update(path,file)
else:
res = arr[evr]
f.close()
return res
def revision_update(path,file):
import subprocess
cmd = "cd "+path+"; git rev-list --count $(git log -1 --pretty=format:\"%H\" "+file+")..HEAD"
try:
res = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
except subprocess.CalledProcessError as e:
res = "error_"+e.returncode
res = str(int(res))
res = res.strip(' \t\n\r')
return res
def command_over_ssh(d,command):
import subprocess
user = d.getVar('REMOTE_USER', True)
id = d.getVar('IDENTITY_FILE', True)
ip = d.getVar('REMOTE_IP', True)
cmd = "ssh -i "+id+" "+user+"@"+ip+" "+command
try:
ret = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
except subprocess.CalledProcessError:
raise Exception("Copying to target requires access by public key. Run: \033[1;37mssh-copy-id "+REMOTE_USER+"@"+REMOTE_IP+"\033[0m")
return ret.strip()
inherit elphel-scp inherit elphel-scp
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment