Affichage des articles dont le libellé est linux. Afficher tous les articles
Affichage des articles dont le libellé est linux. Afficher tous les articles

jeudi 18 janvier 2024

LInux/Debian : removing unnecessary network bridges

Lately, I've been fooling aroung a lot with containers  (docker) and virtual machines (Vagrant, VirtualBox, ...)
Lots of fun, but an unexpected consequence is that this created a lot of network bridges on my machine.

Thus, this output:

$ nmcli device status
DEVICE             TYPE      STATE         CONNECTION      
wlo1               wifi      connected     eduroam         
br-16841f4ab5b3    bridge    connected     br-16841f4ab5b3 
br-6d277fff70af    bridge    connected     br-6d277fff70af 
br-70abc1ec9d13    bridge    connected     br-70abc1ec9d13 
br-7866640acd2f    bridge    connected     br-7866640acd2f 
br-804db4145aa9    bridge    connected     br-804db4145aa9 
br-989ab8bd5062    bridge    connected     br-989ab8bd5062 
br-c393b3577508    bridge    connected     br-c393b3577508 
br-c4e437f7076a    bridge    connected     br-c4e437f7076a 
docker0            bridge    connected     docker0         
virbr0             bridge    connected     virbr0  

Those "br-" network interfaces are actually "bridges", used to connect an interface to another (see here for details).

Not really bad, but things are getting a bit crowded here, so I wanted to get rid of these at once. Here we go: 

 * To get only the names of the bridges:

$ nmcli device status | grep br- | awk -e '{print $1}'
br-16841f4ab5b3
br-6d277fff70af
br-70abc1ec9d13
br-7866640acd2f
br-804db4145aa9
br-989ab8bd5062
br-c393b3577508
br-c4e437f7076a
To remove them, the command is $ nmcli device delete <device>
So, as a oneliner:
$ for a in $(nmcli device status | grep br- | awk -e '{print $1}'); do nmcli device delete $a; done

Et voila ! 

 

Other related commands:

samedi 30 mars 2013

Octave/Ubuntu: problems installing additional packages

This post started out as a question on SO, but as I finally found the answer, I though it might interest other people.

Consider the following situation: you need to do some function data-fitting, you don't {wan't to use / have access to} Matlab, and think that Octave might be an alternative.

First problem: your version of Octave on you current Ubuntu 12.04 is slightly outdated, and sudo apt-get install doesn't seem to have a more recent version.

You can upgrade using an unofficial ppa, as described on this page.


Then, Octave actually doesn't have data-fitting material. It is provided as additional packages (see here). And according to this page, it is the optim package that you need.

Once downloaded, running the following line in the Octave shell
pkg install optim-1.2.2.tar.gz
tells you that there are additional packages required (`miscellaneous`, `struct` and `general`). And at one point you might hit the following error (or something near), complaining about something called mkoctfile:

make: /usr/bin/mkoctfile: Command not found
    make: *** [__exit__.oct] Error 127
    'make' returned the following error: make: Entering directory `/tmp/oct-P11IKL/general/src'
    /usr/bin/mkoctfile __exit__.cc
    make: Leaving directory `/tmp/oct-P11IKL/general/src'
    error: called from `pkg>configure_make' in file /usr/share/octave/3.6.2/m/pkg/pkg.m         near line 1391, column 9
    error: called from:
    error:   /usr/share/octave/3.6.2/m/pkg/pkg.m at line 834, column 5
    error:   /usr/share/octave/3.6.2/m/pkg/pkg.m at line 383, column 9


If you search about this, you might find this question, where the answer (unaccepted) says that you should sudo apt-get install octave-signal

Don't ! Depending on your ppa settings, this might revert your Octave installation to 3.2, which is not desirable.

The solution requires to install the Octave development packages with :
sudo apt-get install octave-pkg-dev

Finally, It seems that installation of some (?) packages writes stuff in /usr/share/octave/, which can't be done by user (and 'sudo' can't be run from Octave 's shell).
So the easiest it to switch as root before starting Octave (with su), then install the packages, then quit Octave.



vendredi 17 février 2012

Changing the monitor on which the GNOME panels are placed

In my job, it is quite common these days to have a dual display setup on your laptop. Either your are at the office and have a larger LDC monitor, either your are teaching or doing some presentation and you have a beamer projector connected.

With the GNOME 2 desktop, the UI is based on 2 toolbars (called "panels") on top and bottom of the screen, that are very handy for launching common apps. With two screens, what happens is that these panels are usually placed on one screen, where you would rather have them on the other one.

The desktop provides a graphical way to move them around with the mouse, by holding the "alt" key down, and moving them around. But this is rather difficult in some lighting situations, when the projector image is bad and you hardly see your mouse pointer. Worse, you might end up with a vertical panel, and then, due to the lack of free space in the panel to click on, you're doomed to use either the graphical editor, either the command line tool.

The other solution is to edit this item directly in the gnome registry. Oh, sorry, I know, GNOME has no registry, only Windows has... Although it can look quite similar as viewed from the corresponding graphical editors, the implementation beneath is completely different. While Windows stores all its configuration information in two HUGE files, on Linux the information is spread over many many files, usually under /etc. It's only the way the information is displayed that makes it look like Windows registry (a tree of pairs key/values). And it is called GConf repository instead of registry.

For the desktops panels, the items to consider are stored under the keys /apps/panel/toplevels/ keys, one is called bottom_panel_screen0, the other top_panel_screen0 (at least on my computer, check on yours).

This can be done graphically with the gconf-editor tool, but when you have the audience waiting, it can be complicated finding and clicking on correct items... The best idea is to use the command-line tool provided, and to have somewhere two scripts, one for switching panels to monitor 0, one for switching to monitor 1.

So just copy/paste these lines in two files that you store whereyouwant, and add two symlinks on them on your desktop. Then, once you are in front of the audience and you have trouble with the panels, just reduce all the opened windows and double-click on one of the links. Changes should apply in less than a second.

file switch_panel_0.sh
#! /bin/bash
# switch top/bottom panels to screen 0
gconftool-2 --set "/apps/panel/toplevels/bottom_panel_screen0/monitor" --type int 0
gconftool-2 --set "/apps/panel/toplevels/top_panel_screen0/monitor" --type int 0

file switch_panel_1.sh:
#! /bin/bash
# switch top/bottom panels to screen 1
gconftool-2 --set "/apps/panel/toplevels/bottom_panel_screen0/monitor" --type int 1
gconftool-2 --set "/apps/panel/toplevels/top_panel_screen0/monitor" --type int 1

To create the symlinks (remember to adjust the path to where you put the files), just "cd" to your desktop folder ($HOME/Desktop usually) and type:
>ln -s $HOME/scripts/screen/switch_panel_0.sh panel_0
>ln -s $HOME/scripts/screen/switch_panel_1.sh panel_1

And don't forget to make your files executable! (chmod)

jeudi 3 mars 2011

Two scripts for packaging a source tree from a local repository

I'm currently maintaining a double build of some software projects, on both Windows and Linux. Svn is of course a great help, because it allows me to easily switch from one machine to another and finding my whole tree unchanged (with a network-hosted repository, of course). I could also use some virtual machine, but I happen to have enough machines available: my main laptop recently switched (more on this later!), and I still have Windows at work and at home. So it is kind of easier to work on separate machines, not to mention that virtual machines can have some specific trouble that you need to deal with, instead of focusing on your project.

Part of the job is letting the users try your code, users that don't necessarily have access to the svn repository, nor have/use the same dev tools you do. So the classical way is to upload somewhere the whole tree as a single archive, and let them fool around with the app.

A well-known post from Joel Spolsky (here in french) covers a list of what is required in dev teams to achieve a high quality level. And point n°2 is "Can you make a build in one step?". Besides the build process, this implies an efficient source tree release step, and that's what I'll talk about here. But what exactly does "release" mean ?

"Releasing" means here going from a source tree, with all binaries compiled and unit-tests done, to a single file uploaded somewhere, so users can download it the next morning. We do not cover here producing the more complex "self-installing" files, (linux .deb or .rpm, or windows .msi or .exe), only a regular archive, containing the whole source tree along with the needed binaries.

You can find below the two scripts, one for windows (.bat), and one for Linux (.sh). The Linux version only needs regular tools that should be available on every distribution, while the Windows versions needs 2 additional tools, the archiver and the svn command-line client. Yes, I know what you think: if you are using svn, then you have the command-line svn client ! Well, no, not necessarily. On windows, I use TortoiseSvn,  really nice and with a perfect shell integration. This gui software is not just a wrapper around the svn command-line client, it has its own binaries. So you need to install some other svn client if you're a TortoiseSvn user (they are available here).
For the archiver, I highly recommend 7-zip: has both GUI and CLI, high performance, good documentation, shell integration... and LGPL'ed ! Can't wait to have it on Linux.

The interesting point is that the two scripts here are project-independent: you just drop them in your root folder... and there you go! A simple double-clic will generate an archive (.zip or .tar.gz), containing a copy of the local repository, with the name like:

XXXXX_YYYYMMDD-HHMM_win32.zip for the windows version
XXXXX_YYYYMMDD-HHMM_linux.tar.gz for the linux version
with XXXXX being the project name, simply extracted from the root folder name. You can also run them from the command-line.

The only tweaking you need to do is edit the additional "upload" scripts, where the ftp command is issued: this is the only part that can not be automatic, as there is no way to automatically determine what the host is.

Inside the scripts, nothing really complicated, but I'm quite happy to achieve some bash scripting as well as I am used to do with windows scripting. I miss the 'goto' command, but I must say that bash is more efficient, even though I am more used to cmd.exe. The scripts mainly do an svn export, add the binaries (that shoudn't be versioned), and compress the whole thing, renaming it with the current date/time. Has been tested on XP-SP3 and Ubuntu 10.10, let me know if you experience some trouble.

Download link

Linux/bash version:

#!/bin/bash
echo Packaging linux archive

curpath=$(pwd)
name=$(basename $curpath)
#echo name=$name

now=$(date +%Y%m%d-%H%M)
fn=${name}_${now}_linux

echo "step 1 : export tree to temp path"
svn export . $HOME/tmp/$name

echo "step 2 : add binaries (not versioned)"
cp bin/* /tmp/$name/bin
cp lib/* /tmp/$name/lib

echo "step 3 : archive and compress"
cd /tmp
tar cfz $curpath/$fn.tar.gz $name
cd $curpath

echo "step 4 : cleanup"
rm -r $HOME/tmp/$name

echo "step 5 : upload"
./upload.sh

echo "done, file $fn.tar.gz available !"
read -p "press a key"


Windows version

@echo off
title Packaging windows archive

:: here, little trick to get the folder's name
set curr_path=%cd%
call :sp %curr_path%
::echo name=%name%

set archiver=C:\Program Files\7-Zip\7z.exe
set svnclient=C:\Program Files\Subversion\bin\svn.exe

:: step 0 : make sure all the tools are available
if not exist "%archiver%" goto err1
if not exist "%svnclient%" goto err2

echo step 1 : export tree to temp path
svn export . %temp%\%name% --native-eol CRLF

echo step 2 : add binaries (not versioned)
copy bin %temp%\%name%\bin > nul
copy lib %temp%\%name%\lib > nul

echo step 3 : compress
set year=%date:~6,4%
set month=%date:~3,2%
set day=%date:~0,2%
set hour=%time:~0,2%
if /I %hour% LSS 10 set hour=0%hour:~1,1%
set mn=%time:~3,2%
set now=%year%%month%%day%-%hour%%mn%
echo now=%now%
pause
"%archiver%" a "%name%_%now%_win32.zip" %temp%\%name% > nul

echo step 4 : cleanup
del /Q /S %temp%\%name%\* >nul
rd /S /Q %temp%\%name%

echo step 5 : upload
call upload.bat

echo done, file %name%_%now%_win32.zip available !
pause
goto :eof
============================================================
:err1
echo FAIL: archiver %archiver% not present !
pause
goto :eof
============================================================
:err2
echo FAIL: svnclient %svnclient% not present !
pause
goto :eof
============================================================
:sp
::echo sp, arg1=%1
set name=%~n1
goto :eof
============================================================