Linux file system skeleton version control - linux

We are doing some embedded Linux project, the vendor provides us a basic filesystem skeleton, and we would like to put it into the version control system (GIT), but there are some special files which GIT does not like, for example, the device file, the pipe files, etc. I wounder if anyone have a better suggestion to put a filesystem under version control? Thanks!

Two choices;
1) either put the script which creates the nodes in /dev and the like under version control, and have your build system execute that script.
or
2) Make a dd of the basic file system to a plain file, and put that dd resulting file under version conntrol

There are some script for keeping dev files with git, eg: EtcKeeper http://kitenet.net/~joey/code/etckeeper/

Related

Export all files included in defconfig

I'd like to have directory tree containing only the files used by a specific Linux build.
For example if I use https://github.com/LineageOS/android_kernel_moto_shamu with make shamu_defconfig; make that'd result in the Makefile system using the includes in the buildconfig to build.
Is there an (easy) way to have the Makefile system save the files it uses to a log, or most preferably to a different directory such that I'm left with a folder that contains only the files that're used for a build.
My goal is to be able to easily determine which code for the peripherals (e.g. touchscreen driver) is used.
Thanks

How to get list of programs which can open a particular file extension in Linux?

Basically I am trying to get list of programs in Linux which are installed and can open particular file extension .jpg for example. If not all, At-least default program should get listed.
Linux (the kernel) has no knowledge on file types to application mapping. If you want to use Gnome programs you can look at https://people.gnome.org/~shaunm/admin-guide/mimetypes-7.html. For KDE there is another mechanism. Each toolkit can define it as it likes. And the programmer can use the defaults or not. So it is simply application specific!
What do you want to achieve?
If you (double) click with a explorer/browser application on an icon or file name, exactly the explorer/browser looks for the file type. Typically this is realized via mime type dictionary. But how a program looks for the file type and maybe execute another program is only related to the programmer who writes that program. The GUI tool-chains like Gnome and KDE have a lot of support for that topic and so you have basic conformity for each family of applications.
If you want to know how a application do the job, start it with strace. But it is quite hard to dig into the huge amount of data.
Also you can take a look for xdg-open. Many programs use this helper to start applications. As an example: If you start Dolphin with strace you will find a line like lstat64("/etc/xdg", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 after clicking on a file.
you can run from command line with:
xdg-open <file-name>
You maybe also want to have a look for applications which registers for file types: /usr/share/applications/*.desktop
Here you can find in each desktop file some mime-types which are registered for the applications. E.g. for audiacity is:
MimeType=application/x-audacity-project;audio/flac;audio/x-flac;audio/basic;audio/x-aiff;audio/x-wav;application/ogg;audio/x-vorbis+ogg;
For your example with jpg:
$ xdg-mime query filetype <any-jpg-file>
image/jpeg
$ grep 'image/jpeg' -R /usr/share/applications/*
...
/usr/share/applications/mimeinfo.cache:image/jpeg2000=kde4-kolourpaint.desktop;gimp.desktop;
So you can see that gimp is one of the default applications for jpg
The place to start looking is at the mailcap (/etc/mailcap) and MIME-types, e.g., in /etc/mime.types in Debian (the filename and path will vary according to who provides it).
The mailcap file gives some rules for opening a file, while MIME-types lists the known filetypes with a tag that allows multiple applications to know about the file types.
Except for embedded or reduced-functionality systems (such as those based on busybox), you would find these files on almost every UNIX-like system.

Checking contents of a file before it was modified in linux

I wanted to know if there was any way to check the contents of a file before it was modified in linux.
As in suppose i have a file called example.cpp where i have a C++ code written in it. Now if i made some changes and saved it, is it possible to check the older example.cpp file without the changes made?
Thanks in advance
No it's not possible. Linux does not store versioned copies of files.
What you can do is store your source files in a source control system such as git, subversion or cvs. These provide full versioning of all files stored within their repositories.
The file system does not make backups or do versioning. However, some editors make backups before saving. At least Gedit saves a backup of example.cpp as example.cpp~.
There are two ways to accomplish your goal:
Use a versioning file system. Then what you want to do happens automatically.
Use a VCS, such as Subversion, Mercurial or Git, and commit after (resp. before) every change.

Linux file utility magic.mgc database get content

I write project where I need to identify certain file formats.
For some formats I have found signatures that I use for identifying easily (mp3, ogg), with another formats I have a big problem (like MPEG ADTS) - I just cannot find what kind of signature can be used for it.
I found out that File utility for Linux environment can do it.
I tried to search it in source code, but I've found nothing.
I found that file utility holds its database in magic.mgc file. But it's hold in binary form.
It looks like:
Does someone perhaps know how to find that database in plain text format?
That utility isn't a Linux-specific utility; it's the version of the UN*X file command originally written by Ian Darwin. The binary .mgc file is generated from a bunch of source files.
Your Linux distribution probably has a source code package for it; where you get that package, and how you install it, depends on which distribution you're using.
The source files from which the .mgc file was generated might also be available on your distribution without installing the source package for file; if so, you could use the file command to generate it, using the -C flag. I don't see them anywhere obvious on my Ubuntu 12.04 virtual machine, so that might require some other package to be installed (file itself is installed). (On OS X, they're in the directory /usr/share/file/magic.)
Alternatively, you could download the standard version of that file (which might have been modified by your distribution, so you might not want that version) and modify and build it.
Note that, on some versions of UN*X systems, the bulk of the work done by the file command is done in library routines in the "libmagic" library; see whether your distribution has that or can install it (try, for example, man libmagic) and whether it can do the job for you.

Software to cd (change directories) into .jar/.ear files?

Is there any software/script that will allow me to cd (change directories) into .jar/.ear/.zip files and edit the contents of the files it contains? I'm working on a large EJB project (yuck), and I frequently find myself in situations like the following:
something.ear/
|-- something.jar/
| `-- fileINeedToEdit.xml
I work primarily via the command line (Mac/Linux), so I find myself decompressing the files with jar -xvf, editing the file I need to edit, and then recompressing with jar -cvf. Obviously, this becomes a major headache after the first few times.
I'd like to be able to treat the compressed files as directories, and simply cd (or some alternate command) to the file I want to edit.
Does anyone know how I can accomplish this?
I agree with the comments to your question, an automated build should allow you to make this kind of changes easily and is the right way to go. But if you insist in this direction, check fuse-zip, it provides the ability for zip files to be mounted on any directory mount point.
There are two general strategies. Either use software that can mount the jars as pseudo file systems. That allows you to work exactly like you are used to, but I'm uncertain how well Mac OS supports user-space filesystems. Or use a tool that already has in-place editing support, like the Windows explorer or a more powerful editor (e.g. emacs).
I use one of this application If I want to check something in jar or ear file
Krusader (file manager from KDE) - it allows to investigate jar, ear or war file, but unfortunatelly doesn't work well with nested jars files
mc (Midnight Commander) - it works pretty well with ear, jar or war, event with nested jars

Resources