Return to Level1Techs.com

The small linux problem thread

linux
helpdesk

#633

It is, all files are copied into one directory though.

Let me make changes so the copy structure looks like this:

to_burn
    base
        Packages
            *.rpm
    updates
        Packages
            *.rpm

and so on.


#634

Alright, this is working on my end, @KenPC

import json
import hashlib
import sys
import os
import shutil
from subprocess import call


def loadjson():
	try:
		with open('/srv/wrapper.json', 'r') as wrapperjson:
			fileconfig = json.loads(wrapperjson.read())
	except:
		print("Error loading file, defaulting to empty")
		fileconfig = {}
	return fileconfig

def savejson(fileconfig):
	try:
		with open('/srv/wrapper.json', 'w') as wrapperjson:
			wrapperjson.write(json.dumps(fileconfig))
	except:
		print("error writing file...")
		

def getcsum(filepath):
	with open(filepath,'r') as fileobj:
		return hashlib.sha256(fileobj.read()).hexdigest()

def validatejson(fileconfig):
	# walks through all the dirs:
	for root, subdirs, files in os.walk(repodir):
		for item in files:
			# Can't use "file" here because it's a reserved name
			fpath = root + '/' + item
			csumval = getcsum(fpath)
			if not fpath in fileconfig:
				print("file not in array, ading to list")
				fileconfig[fpath] = csumval
			elif fileconfig[fpath] == csumval: 
				print("shasum matched")
			else:
				fileconfig[fpath] = csumval
	savejson(fileconfig)
	return fileconfig

def postcompare(fileconfig):
	movelist = []
	for root, subdirs, files in os.walk(repodir):
		for item in files:
			fpath = root + '/' + item
			csumval = getcsum(fpath)
			if not fpath in fileconfig:
				print("file not in array, adding to list")
				fileconfig[fpath] = csumval
				movelist.append(fpath)
			elif fileconfig[fpath] == csumval:
				print("shasum matched, skipping")
			else:
				fileconfig[fpath] = csumval
				print("shasum didn't match, moving to target dir")
				movelist.append(fpath)
	return movelist, fileconfig

def movefiles(movelist,destdir, repodir):
	if not os.path.exists(destdir):
		os.makedirs(destdir)
	for fpath in movelist:
		relpath = fpath.split(repodir)[1]
		destpath = destdir+destpath
		print("Copying " + fpath + " To " + destdir)
		shutil.copy(fpath, destpath)

def buildreposynccommand(repodir, repos):
	com = "reposync"
	for item in repos:
		com += " -r " + item
	com += " -p " +repodir
	return com

# Main entrypoint:
if __name__ == "__main__":
	print("Starting script")
	# Variables here, change me:
	destdir = '/root/test'
	repodir = '/var/ftp/pub/centos-7-rpms'
	repos = ['base','updates']
	reposync_command = buildreposynccommand(repodir, repos)
	fc = loadjson()
	fc = validatejson(fc)
	print(reposync_command)
	call(reposync_command.split(' '))
	movelist, fc = postcompare(fc)
	movefiles(movelist,destdir, repodir)
	savejson(fc)

Just so we’re clear, the directory structure I have looks like this:

/var/ftp/pub/centos-7-rpms
    base
        Packages
            *.rpm
    updates
        Packages
            *.rpm

#635

Alright! I’ll give it a whirl on one I haven’t syncd yet


#636

Hang on, I messed up again.


#637

Alright, try now. I’ve edited the script in the previous post.


#638

got it


#639

Is there a way to add the -d and -n switch to the reposync command?

I added it into here, I hope that works.

def buildreposynccommand(repodir, repos):
com = "reposync"
for item in repos:
com += " -d -n -r " + item
com += " -p " +repodir
return com

Haha it printed reposync -d -n -r base -d -n -r updates -p /path/to/folder

I guess bash doesn’t care since it’s still going

I’m bad at py


#640

If you add another line, just above the for loop, com += " -d -n", that should take care of it.

This is how you learn.


#641

so It looks like it worked, but at the end of the script, printed this to stdout

shasum matched, skipping
shasum matched, skipping
shasum matched, skipping
shasum matched, skipping
Traceback (most recent call last):
File “pythonscript.py”, line 94, in
movefiles(movelist,destdir)
TypeError: movefiles() takes exactly 3 arguments (2 given)

Are there issues with python2 and Centos 6.9? It seems to not want to work when I take the same script over to that and run it.


#642

I have all but forgotten that this thread even exists.

I’m having game problems, specifically source games, but not limited to them either.

First up, counter strike source fails to recognize my filesystem, xfs. Fails to load textures because somehow theres too many textures for my 8gb card to handle. And lastly it crashes on render.

Next, tf2, filesystem thing again, hangs at main menu, or crashes X to tty. Thats pretty fuckin stupid.

Next, garrys mod. Can’t load. Doesn’t try.

Next cs 1.6, can’t load, doesn’t try.

Last, csgo randomly hangs for a second, crashes when I die, and freezes at buy menu.

Why is this here? One, filesystem libs, two, I think its an opengl handling problem. I understand I can launch the games in terminal and all that and I have yet to do that. I’m currently forcing myself into ubuntu. What are some things I should check on? Mesa? Are there some libs that are broken by default? All games were fine on antergos but broke when I changed os, though when I went to manjaro to test because I had a disk handy it gave a different just of errors but they are still listed above.


#643

I was told it would probably be a good idea to link this here as well. I’m very tired. Little slow today ^^


#644

Fixed. Steam had fucked libs. Apparently theres package difference between xubuntu and antergos, to the point that it breaks games.


#645

I am a Manjaro user since yesterday and so far I am pretty happy that all went well. There is only one thing that bothers me and that is the question if I want Chrome to be the standard browser every single time I open it. Shouldn’t it be enough to ask that question once? Can I turn it off somehow? When I click links in emails or other non browser apps it opens FireFox instead of Chrome too.


#646

that is controlled by your default app settings, which getting to depends on which desktop environment your running. (gnome, kde, xfce, or so on)

in Gnome you go into settings and the details section is where you can set your defaults. I don’t remember KDE’s exact location, and I have never used xfce, but most desktops have settings menus that will have what you are looking for.


#647

Just a heads up, I had problems with the script :confused: I really appreciate your time. but after much digging and practicing my Google-Fu, I came across an obscure Github with a python program called PakRat that does EXACTLY what I wanted. It even can download the latest packages and put them into a folder tree with the date appended to the folder name in which it was downloaded. Pretty cool shit. Even provides a progress meter.


#648

I did that but Chrome is still asking everytime I open the browser :frowning:


#649

sorry, I miss read your post. to stop chrome from asking, that should be in chrome’s settings, under the default browser section, should be a slider to stop if from asking you. probably named something like “check default browser” or “check at startup”


#650

Yeah, I’m a shitty programmer. :confused:

Glad you were able to find a solution!


#651

solved my issue, wierdly arch had update that solved the issue.

originally I had reinstalled antergos with the LTS version to see if that would help. Reinstalling the system solved my bluetooth issues, but not the shutdown errors.

the issue resolved itself in a update(kinda like my scroll wheel


#652

I need some pointers on virtual networking in virt-manager / qemu. No matter how much I read about it I just can’t get the VM on the same network as the host (and everything else).

The goal (for the VM) is to mount an NFS share, be accessible from other systems on the internal network, and also have internet access. Through some bastardization voodoo I was able to get it to mount the NFS share, but it didn’t have internet access and I probably couldn’t access it from another system.

Any suggestions?