Configuration file pulled from S3 segfaults OpenSwan - vim

I'm trying to configure OpenSwan, an open source IPsec solution written in C.
I have a script to download a configuration file ipsec.conf on an Amazon Linux EC2 that was created on my Macbook and uploaded to S3.
When I start the ipsec service, it segfaults.
Curiously, if I open the configuration file with VIM, make no changes, and simply write/quit, it works. This lends me to believe somehow the file has some weird characters/formatting.
I know of dos2unix, which I ran on the configuration file but that did not prevent the segfault.
I'm wondering what exactly VIM is doing when I write/quit. I could script that operation on my configuration file after pulling it. Or anything else that would help me understand what's going on.

First, try to open the file with vim, then exit vim (:q) without having saved the file before. If vim says File modified since last complete write; write or use ! to override., this means that this is not something that vim does when write/quit that changes your file, but that this is something that vim does when it opens the file. And this is the most common case.
Vim parses the input file depending on the locale, and if some characters can not be understood according to the locale, vim may forget them. So, when saving the file, those characters will be removed.
Now, use vim to save your file as ipsec-ok.conf.
And run the following command:
bash -c 'diff <(od -xa ipsec.conf) <(od -xa ipsec-ok.conf)'
This will display the differences between the original file and the one that works with OpenSwan. In ascii and hexadecimal formats. This way, you will find the unsupported characters that make OpenSwan dump a core.

Related

Modify some text of a file in a zip file

On linux, I would like to modify a file that is inside a zip without having to extract it. The file is in any possible extension.
Here's an exemple.
test.zip
|---hello.someextension
|---bye.someextension
The file hello.someextension contains following text: Hello, this is a test.
What I would like to do
Modify the word test in the hello.someextension file to be "gift" instead, for instance.
Modifying the text is not really a big deal, but the issue I'm facing is that I cannot edit a file that is inside a .zip. I tried via VIM and here's an exemple output:
ÅÍ.PE¥&ö$kpì`w_OËŽ=“XÖ¸m† 86=šoÔRw«Õºxÿ¯Ûiö²X
Vim supports editing zipped files out-of-the-box. If it doesn't work for you then you have a local problem of some sort.
Check if it helps to bypass your faulty vimrc (e.g. vim -u NORC -N), or to re-install the whole Vim package etc.

process a file remotely using ssh

I have this report.tex file which I convert to pdf as follows:
latex report.tex
dvips report.dvi -o report.ps
ps2pdfwr report.ps report.pdf
These commands are placed in a file called linux_build
This works great. However, this works on my Linux machine and most of my work I do on my Mac
I checked out MacTex which is enormous (> 4GB) so I decided to process the latex file remotely (so working on my Mac, and building on my Linux computer). Like this:
ssh latex#192.168.2.8 "cd build && ./linux_build" < report.tex
scp latex#192.168.2.8:build/report.pdf .
All this works, except for one thing:
latex report.tex
That command simply looks on disk, not for some input stream/pipe of whatever. It is at this point I'm not sure anymore how to fix this. Any suggestions ?
scp report.tex latex#192.168.2.8:/home/Jeanluca/build
ssh latex#192.168.2.8 "cd build && ./linux_build" < report.tex
scp latex#192.168.2.8:build/report.pdf
Try sending your tex file over first. To the full path for the build directory.
I know your frustration. It grew so big that I put together a small script which efficiently runs LaTeX on a remote server.
It prestarts LaTeX on the remote end with the preamble of the previous run such that LaTeX has already loaded the required packages and is ready to go when changed contents arrives, and starts streaming the resulting PDF file immediately (before LaTeX has finished writing to it). Also dependencies (images, included source files etc.) are transparently handled.
Maybe you too find it useful: https://github.com/iblech/sshlatex
No installation is necessary. Execution is simple:
$ sshlatex ssh.example.org foo.tex
If latex supports reading from standard input then you can do it that way.
Possibly just latex or maybe latex - or possibly latex /dev/stdin to fake it as a local file.
If that doesn't work then you need to transfer the file over first.

Vim 7.4 on Windows 8.1 Creates Program and Files Folders Every Time I Open a File

When I open a file from Windows Explorer using right-click -> Edit with Vim, Vim creates a "Program" folder on the root, and a "Files" folder in the directory of the file I've opened. The Files folder includes Vim/vimfiles/doc. There are no files anywhere, just the directory tree.
This also happens when I run Vim without a file name as an argument.
A DOS Box flashes just before Vim opens, but it goes away too fast for me to read what it's saying.
I've used Vim for years and have never seen this behavior. This is the first time, however, that I've used it on Windows 8.1.
Any suggestions or ideas? I'm getting really tired of deleting Program and Files folders all over the place. Lol!
You could follow the steps on Vim-FAQ 2.5. Some relevant parts follows:
2.5. I have a "xyz" (some) problem with Vim. How do I determine it is a
problem with my setup or with Vim? / Have I found a bug in Vim?
First, you need to find out, whether the error is in the actual
runtime files or any plugin that is distributed with Vim or whether it
is a simple side effect of any configuration option from your .vimrc
or .gvimrc. So first, start vim like this:
vim -u NONE -U NONE -N -i NONE
this starts Vim in nocompatible mode (-N), without reading your
viminfo file (-i NONE), without reading any configuration file (-u
NONE for not reading .vimrc file and -U NONE for not reading a .gvimrc
file) or even plugin.
If the error does not occur when starting Vim this way, then the
problem is either related to some plugin of yours or some setting in
one of your local setup files. You need to find out, what triggers the
error, you try starting Vim this way:
vim -u NONE -U NONE -N
If the error occurs, the problem is your .viminfo file. Simply delete
the viminfo file then. If the error does not occur, try:
vim -u ~/.vimrc --noplugin -N -i NONE
This will simply use your .vimrc as configuration file, but not load
any plugins. If the error occurs this time, the error is possibly
caused by some configuration option inside your .vimrc file. Depending
on the length of your vimrc file, it can be quite hard to trace the
origin within that file.
The best way is to add :finish command in the middle of your .vimrc.
Then restart again using the same command line. If the error still
occurs, the bug must be caused because of a setting in the first half
of your .vimrc. If it doesn't happen, the problematic setting must be
in the second half of your .vimrc. So move the :finish command to the
middle of that half, of which you know that triggers the error and
move your way along, until you find the problematic option. If your
.vimrc is 350 lines long, you need at a maximum 9 tries to find the
offending line (in practise, this can often be further reduced, since
often lines depend on each other).
If the problem does not occur, when only loading your .vimrc file, the
error must be caused by a plugin or another runtime file (indent
autoload or syntax script). Check the output of the :scriptnames
command to see what files have been loaded and for each one try to
disable each one by one and see which one triggers the bug. Often
files that are loaded by vim, have a simple configuration variable to
disable them, but you need to check inside each file separately.
There is additional information on the link if the steps above doesn't solves the problem.

Perforce changing the default editor

I use perforce for my revision control, when I hit 'p4 change' it always opens up the list on emacs, and we all know the pain of deleting text in it. How do i change it to gedit or vim or anything else? My default text editor is gedit.
On the command line, set P4EDITOR either as an environment variable or in the P4CONFIG file.
From the command line,
p4 set P4EDITOR="C:\File Editor\editor.exe"
You can test that this was successfull by running the following command after, which should launch your desired editor.
p4 workspace
I had similar problem on my Windows system.
It always used to open clumsy notepad.
I am more comfortable with TextPad, so to change default perforce editor, I made following changes:
I opened System Properties and added new environment variable as following:
Name: `P4EDITOR`
Value: `C:\Program Files (x86)\TextPad 4\TextPad.exe`
After that open a new CMD and there you go !!!
For Notepad++ I needed to use this command -multiInst to trigger edits.
p4 set P4EDITOR="C:\Program Files (x86)\Notepad++\notepad++.exe -multiInst"
Try setting the EDITOR environment variable. Also, the command line p4 should have an option to specify an editor. Also, the .p4config file might have something as well.
Also need to check if EDITOR/P4EDITOR path is correct. If path is wrong, perforce will choose previously working editor.
In the case of WSL, likely your p4 binary is provided for Windows platform as the path and operations are most compatible there, so it's p4.exe most likely. Then simple wawy of setting editor in P4EDITOR is not just enough, we have to convert input argument of filepath which is provided in Windows-based into Linux path.
This solution dated back 19 years ago still works
The concept is to
Create a bash/shell script that accept the argument.
Then in the script we can use wslpath $1 to convert Windows path into Linux path.
The script can be just
#!/bin/bash
vim `wslpath $1`
I thought I might not be able to use Vim to edit change, or client spec of perforce and have to end up using whatever provided like Notepad (not against it, but I just want to use Vim). This solution works for me.

SVN incosistent eol when adding file

Quiet simply I am trying to add new files to my repository, my command goes like this:
svn add * --force
but this produces:
svn: File 'install/config.xml.php' has inconsistent newlines svn:
Inconsistent line ending style
The thing is that this file is not yet under version control, so when I try to propdel or anything similar it doesn't work.
I am sure this file is not under version control because svn status shows this:
? install/version
? install/config.xml.php
I have already enabled the autoprops in svn default config but this did not help.
Any ideas?
Btw: this is a server, so no GUI.
vim makes it easy to force line endings to entirely CRLF or entirely CR.
:set ff=unix
:wq
d2u, dtox, dos2unix, are some names for simple utilities that are often installed on systems to do this task. You could also use the standard tr(1) utility:
tr -d '\r' < input > output
While working on Windows OS use Notepad ++:
Edit -> EOL Conversion.
- Windows Format
- UNIX/OSX Format
- Old Mac Format
You have current format information in the status bar.

Resources