Ubuntu12.04以降に本家TeX Liveの最新版を簡単にインストールする方法

先日、私のシステムをXubuntu 12.04からXubuntu 14.04にアップグレードしました。
私はLaTeXに関しては、本家のTeX Liveを使っています。インストーラーは十分に使いやすいのですが、怠け者なので、より簡単にできないかと方法を探してみました。

なぜかというと、本家を使う場合、リンクにあるように、少し設定が必要だからです。

そのリンクをひとつずつ確認していたところ、ある方が、Ubuntu用の本家TeX Liveのインストールスクリプトを公開しているということを知りました。最新版にリンクされています。

早速トライしてみたら便利だったので、紹介します。

続きを読む

Linuxにおけるハイフンの意味

ときどき、下記のような表現を見ます。

$ wget -O- http://www.example.com/example.gpg.key | \
  sudo apt-key add -

この -Oのあとについているハイフンや、apt-key addのあとについているハイフンの意味をきちんと理解していませんでした。

改めて、調べたら、いろいろな方が解説してくれていました。

結論からいうと、

Linuxにおけるハイフンは、標準入出力をさす

のですね。

上記の例の場合、wget -O は本当はファイル名を引数にもつはずで、

wget -O file となるはずなんです。

でも、今の場合、-を指定することで、

wget -O- はその内容を、標準出力に表示するんですね。
今の場合は、example.gpg.keyが表示されるわけです。

で、上記の場合、さらにパイプがつながっていて、apt-key add -と続きます。
今回のハイフンは、今度は標準入力になるわけですね。

つまり、example.gpg.keyの内容が標準出力に出力され、
それがパイプで今度は標準入力になって、apt-key addの引数として使われるわけです。

となると、次と同じということですね。

$ wget -O tmpfile http://www.example.com/example.gpg.key
$ sudo apt-key add tmpfile
$ rm tmpfile

ハイフンを上手に使うことで一時ファイルを作ることなくパイプを使うことができるわけです。
スマートですね。

Xubuntu 14.04にNVIDIAの最新ドライバーをインストールする方法(Xubuntuをテキストモードで起動させる方法)

先日、新しいデスクトップマシンが職場に到着しました。
早速、Lin4Neuro-14.04をインストールしたところ、画面解像度が1280×1024までしかでなく、悲しいことに…。

グラフィックボードはNVIDIA GeForce GTX 750 Tiが搭載されています。

Ubuntuのnvidia-currentではまだ未対応であることから、本家のサイトからドライバーをインストールすることとしましたが、ひと手間だったので、その経過をまとめます。

続きを読む

Lin4Neuro based on Xubuntu 14.04LTS was released

I managed to customize Xubuntu 14.04LTS to be Lin4Neuro-14.04.

L4N-trusty-screenshot

For this customization I did the following;

  • .desktop files for neuroimaging analysis packages are stored in .local/share/applications
  • Neuroimaging.directory is stored in .local/share/desktop-directories.
  • Custom icons are stored in ~/.icons

If you look at these files, you will see how you can add your entries to menu.

I keep maintaining Xubuntu 12.04 because I am not certain Connectome mapper works in Xubuntu 14.04. If you want to use Connectome mapper, I recommend to use Lin4Neuro 12.04.

Grubで困った時にまずすること

先日、デュアルブートのマシンでXubuntuのアップデートをした時にGrubがアップデートされ、質問に適当に答えていたら、Grubのエントリーが消えてしまうという事件がありました。

Grubの設定をいろいろするのはめんどくさい、何かいい方法がないかなと探していました。
そうしたら、ありました。めんどくさがりにぴったりなコマンドが。

$ sudo update-grub

これで、システムに入っているOSを探し出し、自動でメニューにエントリーしてくれます。

ということで、Grubで困ったら、焦らず、まずはupdate-grubをタイプしてみてはどうでしょうか。

Making 2-up pdf files using pdfnup included in Tex Live 2014

I needed to make a 2-up pdf out of slide pdfs. That is, original slide pdf is landscape, and I wanted to put 2 slides in one page.

Googling led me “pdfnup”. Since I installed Tex Live 2014 on my machine, pdfnup was already installed.

So, I tried the following

$ pdfnup --orient portrait --nup 1x2 input.pdf

This resulted in error, which said

  pdfnup ERROR: the --orient option is not allowed,
  use --landscape or --no-landscape to specify
  the output page orientation

so I used –no-landscape option

$ pdfnup --no-landscape --nup 1x2 input.pdf

This made input-nup.pdf and that is 2-up pdf!

This tool is so useful for preparing handouts for presentation.

In addition to the above example, the author shows a nice example of how to produce a handout from a file of presentation slides.
For slides made with the standard 4:3 aspect ratio a nice 6-up handout on A4 paper can be made by

$ pdfjam --nup 2x3 --frame true --noautoscale false \
  --delta "0.2cm 0.3cm" --scale 0.95 myslides.pdf \
  --outfile myhandout.pdf

Linuxでfind, sedを使いながら文字列を再利用してファイル名の途中に文字列を挿入する方法

最近、以下のようなことをやる必要がありました。

ファイル名が

201105_ID.jpg
20120608_ID.jpg
20130704_ID.jpg
201409_ID.jpg

となっているファイル(年月が必ずあり、日が時についている)に対して、
年の後にアンダースコアを入れたい、つまり、

2011_05_ID.jpg
2012_0608_ID.jpg
2013_0704_ID.jpg
2014_09_ID.jpg

としたいわけです。

続きを読む

Update of Lin4Neuro (10 Aug 2014)

Lin4Neuro was updated. This time the change was limited to kernel update and security updates.

  • Kernel was updated to 3.13.0-32-generic.
  • All security updates were applied.

I’m working on Xubuntu 14.04, but it seems to have several problems with neuroimaging software packages. So for now I keep updating Lin4Neuro based on Xubuntu 12.04.

You can download the latest Lin4Neuro from here.

Workaround for Remastersys on Xubuntu 14.04

Remastersys is a very useful remastering tool though developing has ceased now.
Many reported that they could make Remastersys work on Ubuntu 14.04, but I encountered an error with Xubuntu 14.04.

I found workaround for this error.

Short answer: Comment out the line 245 of “/usr/bin/remastersys” beginning with [ “grep lightdm /etc/X11/default-display-manager” != “” ]

Below is the long answer.

  • Installation
  • Installation is simple.

    1. Import GPG key
    2. $ wget -O- http://www.remastersys.com/ubuntu/remastersys.gpg.key | sudo apt-key add -
      
    3. Add sources
    4. Add the line to /etc/apt/sources.list

      deb http://www.remastersys.com/ubuntu precise main

      Please note that you don’t have to replace “precise” with “trusty.”

    5. Installation
    6. $ sudo apt-get update; sudo apt-get install remastersys
      
  • Error with “remastersys dist”
  • “sudo remastersys dist” terminated with error. The below is error message;

    $ sudo remastersys dist
    Distribution Mode Selected
    Enabling remastersys-firstboot
    Adding system startup for /etc/init.d/remastersys-firstboot …
    /etc/rc0.d/K20remastersys-firstboot -> ../init.d/remastersys-firstboot
    ……
    /etc/rc5.d/S20remastersys-firstboot -> ../init.d/remastersys-firstboot
    Checking filesystem type of the Working Folder
    /home/remastersys/remastersys is on a ext4 filesystem
    Making sure popularity contest is not installed
    Installing the Ubiquity GTK frontend
    Lightdm not setup properly. You must set your default desktop with lightdm prior to remastering

    I examined the script /usr/bin/remastersys with the keyword “Lightdm.” Then I found the description below in the line 245

    [ “`grep lightdm /etc/X11/default-display-manager`” != “” ] && [ ! -f /etc/lightdm/lightdm.conf ] && [ ! -f /usr/share/xsessions/ubuntu.desktop ] && echo “Lightdm not setup properly. You must set your default desktop with lightdm prior to remastering” && echo “Lightdm not setup properly. You must set your default desktop with lightdm prior to remastering” >> $WORKDIR/remastersys.log && exit 1

    Though this line checks if the file “/etc/lightdm/lightdm.conf” exists, The latest Xubuntu 14.04 doesn’t have that lightdm.conf file in /etc/lightdm.

    So I commented out this line, just adding “#” to the beginning of the line.

    Then I tried sudo remastersys dist again, with success!

    If you want to use Remastersys in Xubuntu 14.04, it’s worth trying it.

Update of Lin4Neuro (12 Jun 2014)

Lin4Neuro was updated. The changes of this version were as follows;

  • Kernel was updated to 3.13.0-29-generic.
  • ITK-SNAP was updated to 3.0.0.
  • MITK was updated to 2014.03.00.
  • MITK Diffusion was updated to 2014.03.
  • All security updates were applied.

Lin4Neuro is still based on Xubuntu 12.04. Now I’m working on Xubuntu 14.04, so hopefully the next version will be based on Xubuntu 14.04.

You can download the latest Lin4Neuro from here.

Linuxでファイル名の前後に文字を追加したい時の簡単な方法

ある方に、

「ファイル名の最初に一括でzとつけたいのだけれども、どうしたらよいだろうか?」

と質問されました。

たとえば、

001.jpg 002.jpg 003.jpg 004.jpg

をすべて

z001.jpg z002.jpg z003.jpg z004.jpg

としたいというような時です。

ここで、Linuxではrenameというコマンドを使います。

renameは以下の書式を知っていれば応用が効きます。

rename 's/置換前文字列/置換後文字列/' ファイル名

この、’s/before/after/’はsedでの置換と同じ書式です。sはsubstituteの略です。

でも、今は置換ではなく、文字列を追加したいわけです。

こういう時、Linuxはたいしたもんだなと思うのですが、ファイルの頭は^という特殊文字で表現されます。
そして、ファイルの最後は$で表現されます。(正規表現ですね)

なので、今、ファイル名にzを追加したい時は、

「^をzに置換」してあげると考えるわけです。

したがって、以下のようになります。

rename 's/^/z/' 00*.jpg

もし、ファイル名の最後に.oldをつけたかったら以下のようになります。

rename 's/$/.old/' 00*.jpg

^と$についての知識がちょっとあるだけで、ずいぶん楽になりますね。

Xubuntu12.04で問題なく動く無線LAN子機WN-G300U

Linuxでつまずきのひとつになるものに無線LAN子機があげられると思います。ネットを探しても情報は限られている印象があります。
動作するものとしないものとあり、動作しないといろいろ設定に苦しんでしまうというところがあります。私自身も以前かなり苦しんでいましたがうまくいかずにあきらめてしまっていました。

今回、オフィスの引越しに伴って自分の机がルーターから離れてしまったため、必要に駆られてXubuntuでも動作する無線LAN子機を探すことにしました。

ググったところ、こちらの記事を見つけました。Linux MintにI-O DATAのWN-G300Uシリーズが「何もせず」に動作したとのこと。

早速入手しました。

製品ホームページはこちら。2014年4月現在Amazonでは1763円で入手可能です。

それで、結果はどうかというと、

【何もせずに】動作しました!

USBにWN-G300を挿した状態でXubuntuを起動し、ネットワークのアイコンをクリックしたところ、普通にWi-fiのSSIDの一覧が表示され、自分がつなげたいSSIDを選択し、パスフレーズを入力するとあっさり接続です。

発売が2010年の機種ですが、現行で販売されていますので、Xubuntuで無駄な労力なくデスクトップで無線LAN環境を構築したい方にはおすすめの一品です。

Update of Lin4Neuro (13 March 2014)

I updated Lin4Neuro.
This time quite a few changes were made.

  • Many unnecessary software packages and fonts were uninstalled.
  • Connectome mapper was introduced. However, due to filesize and their licenses, freesurfer and Diffusion toolkit are not installed. I wrote a step-by-step guide how to install freesurfer and Diffusion toolkit on Lin4Neuro (the PDF file is found on the desktop), so afer you install these two software packages, you are ready to run Connectome mapper.
  • Kernel was updated to 3.5.

You can download the latest Lin4Neuro from here.

ファイル/ディレクトリ名に空白が入っているファイル/ディレクトリの空白を下線_に置換するワンライナー

ある方とやりとりしているなかで、Linuxにおいて、ファイル名に空白が入っているときにその空白を_に変換するスクリプトを紹介していただきました。

そういうのを知っているのは大事だなと思いまして、シンプルな方法がないかなと考えました。

そうしたら、renameを使えば比較的簡単に達成できることに気づきました。

以下は、カレントディレクトリ内にあるファイル/サブディレクトリ名に空白が入っているものを探し出し、空白を_に変換します。

$ find . -name "* *" | rename 's/ /_/g'

これを使えば空白の問題からおさらばできますね。

ちなみにrenameはsedと同じフォーマットでファイル名の一部を変更できます。

‘s/変換前の文字列/変換後の文字列/g’ で最後のgがあるとそのファイル名で合致するパターンすべてに対して変換してくれます。gがないと最初のパターンだけで置換を行います。

いろいろ教えてくれる方がいるのはとてもありがたいですね。

How to enable users to automount CD-ROM or USB in XFCE

I’m trying to install XFCE with ubuntu minimal iso (mini.iso).

With default settings, users are not able to mount CD-ROM or USB.

In order to change this, edit the following;

/usr/share/polkit-1/actions/org.freedesktop.udisks.policy

In the section “Mount a device”, change “allowed_any” and “allow_inactive” to “yes”.

<xmp>
  <action id="org.freedesktop.udisks.filesystem-mount">
    <description>Mount a device</description>
    <defaults>
      <allow_any><strong>yes</allow_any>
      <allow_inactive>yes</allow_inactive>
      <allow_active>yes</allow_active>
    </defaults>
  </action>
</xmp>

XubuntuでPlayOnLinux経由でMS Office 2010をインストールし、日本語入力を問題なくする方法

Ubuntuにしてたいていは満足なのですが、職場で利用となると足かせになるのがOfficeの問題です。LibreOfficeでたいていは間に合うのですが、Wordの校閲機能やPowerpointのレイアウトの問題などはいかんともしがたい問題です。これは少しずつストレスになっていきます。

Wine経由でMS Office 2010をインストールできると聞いていましたが、試してみてもエラーが多い状態でした。

その後、調べていたら、PlayOnLinuxを使うとあっさりいけるよという書き込みを複数見ました。やってみたらすんなりできました。

しかし、日本語を入力すると、入力しているのに消えてしまうという問題がありました。これもいろいろ調べて、対処をしてみたのですが、うまく動かず…。
でも、よく考えてみたら、PlayOnLinux経由なのだから、設定ファイルが別なのではないか?と思ったところ、それがあたりでした。

以下に方法をまとめます。

  1. ベースのOS
  2. Xubuntu 12.04です。

  3. MS Officeのバージョン
  4. Office 2010の32bitを準備します。Office 2013は動作しません。また、Office 2010の64bit版も動作しません。

  5. Wineのインストール
  6. PlayOnLinuxはWineのフロントエンドなのでWineが必要です。オフィシャルのWineはバージョンが若干古いので、私は下記でWine-teamのPPAからWineをインストールしました。これでwine 1.6がインストールされます。これを書いている時点での最新版は1.7ですが、1.6で一連の流れに問題はありませんでした。

    sudo add-apt-repository ppa:ubuntu-wine/ppa
    sudo apt-get update
    sudo apt-get install wine
    
  7. PlayOnLinuxのインストール
  8. PlayOnLinux(POL)もUbuntuのデフォルト(4.0.14)では、Office 2010のインストールに対応していません。なので、POLのサイトから、最新版(4.2.2)をダウンロードします。
    詳細はhttp://www.playonlinux.com/en/download.htmlに記載してありますが、とりあえず、12.04の場合は下記のとおりです。

    wget -q "http://deb.playonlinux.com/public.gpg" -O- | sudo apt-key add -
    sudo wget http://deb.playonlinux.com/playonlinux_precise.list -O /etc/apt/sources.list.d/playonlinux.list
    sudo apt-get update
    sudo apt-get install playonlinux
    
  9. PlayOnLinuxの起動
  10. メニューのゲーム→PlayOnLinuxでPlayOnLinuxが起動します。
    そこで、「インストール」をクリックします。

    そうすると、下図のようになりますので、SearchからOffice 2010と入れると候補が出てきますので、選択し、右下の「インストール」をクリックします。

    POL_install01

    その後は私は既にインストールしてしまったので、スクリーンショットは示せませんが、指示された通りに従っていけば、必要なファイルなどを全部ダウンロードしてくれます。なお、インストールする場所は変更するとうまくいかないということですので、とりあえずデフォルトのまま入れてしまうのが無難なようです。

    ひと通り終わると、以下のようになります。

    POL_install02

    これでインストールは完了です。これまでの苦労は何だったんだろうと思うぐらい簡単でした。

  11. 日本語入力の設定
  12. しかし、このままだと、日本語入力の問題があります。様々なサイトが、

    ~/.wine/user.regに

    [Software\\Wine\\X11 Driver]
    “Inputstyle”=”offthespot”

    のように記載しなさい

    と書いてあります。しかし、POLを使用した場合は、それではうまくいきません。

    Officeの日本語設定は、ホームディレクトリの下の以下の場所にあります。

    ~/.PlayOnLinux/wineprefix/Office2010/user.reg

    したがって、適当なエディタでこのファイルを開けます。今はLeafpadにしましょう。(なんでもいいですが)

    leafpad ~/.PlayOnLinux/wineprefix/Office2010/user.reg
    

    そして、このファイルの一番下に以下の記述を追加します。

    [Software\\Wine\\X11 Driver]
    "InputStyle"="root"
    

    (環境によってはバックスラッシュは¥に見えると思います)

    その後、その後、POLを再起動すると、ファイルの設定を読み込み直します。

    これで日本語をうつと、インライン変換まではいかないのですが、日本語変換が画面の左下の方にあらわれ、確定した文字がきちんと表示されます。

これでさらによい環境ができあがりました。

Make battery-life of Ubuntu 12.04 longer on ThinkPad T430s

It’s been months since I swithed completely to Xubuntu 12.04 from MS Windows on my ThinkPad T430s. Basically I’m satisfied with Xubuntu 12.04, but there are some points which need tweaks. They are…

  • Battery Life
  • Somehow battery on ThinkPad T430s lasts only around 2hours on Xubuntu, which is much shorter than Windows.

  • Projector
  • XFCE is not so good at dealing with projectors or external monitors. I’m still struggling with this matter, so I don’t make any comments now.

As of battery life, I found a very good tool, which is TLP.

By installing TLP, the battery life gets longer by one hour without any modification, which is great.

You can find how to install TLP here.

Update of Lin4Neuro (28 Dec 2013)

Lin4Neuro was updated. Some changes are…

  • Kernel was updated to 3.5.0-44-generic.
  • FSL was updated to 5.0.6.
  • Ginkgo CADx was updated to 3.6.0.
  • MINC toolkit was updated to 1.0.01
  • MITK was updated to 2013.12.00.
  • Slicer was updated to 4.3.1.
  • LibreOffice was updated to 4.1.4.2

You can download the latest Lin4Neuro from here.

Now I’m focusing on the 64bit version of Lin4Neuro, so I suspend updating 32bit version. One of the task is to make the UEFI-compatible L4N. I hope it will be possible to boot from UEFI on the next update.

JBL Flip on Xubuntu 12.04

Xubuntu 12.04からJBL FlipをBluetoothで接続しようとしたところ、すぐにはつながりませんでした。
ググったところ、このサイトが参考になりました。

pulseaudio-module-bluetoothがキモでした。

sudo apt-get install pulseaudio-module-bluetooth

これでPulseaudioの設定で音がきちんと出るようになりました。

Thinkpad T430sでUbuntu 12.04ファミリーがフリーズする時

Thinkpad T430sにXubuntu 12.04を入れました。インストール自体は何の問題もなかったのですが、入れてから1日の間に10回以上システムがフリーズしました。マウスもキーボードも何の操作も受け付けなくなってしまうのです。

これでは、信頼できないマシンになってしまいます…。

いろいろ調べたところ、カーネルを3.4にアップデートしたところ、問題が解決したという記事をみつけました。

実際にやってみました。

  1. http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.4-precise/にアクセスします。
  2. 64bitの場合ここから3つのファイルをダウンロードします。
    • linux-headers-3.4.0-030400-generic_3.4.0-030400.201205210521_amd64.deb
    • linux-headers-3.4.0-030400_3.4.0-030400.201205210521_all.deb
    • linux-image-3.4.0-030400-generic_3.4.0-030400.201205210521_amd64.deb

    つまり、後ろにamd64.debとあるものとall.debとあるものです。32bitの場合でしたらi386.debとall.debになります。

  3. ダウンロードしたあとで、次のコマンドでカーネルをインストールします。
    sudo dpkg -i linux-*
    
  4. カーネルがインストールされたあと、古いカーネルを削除します。そのためには、apt-get autoremoveがよいと思います。
    sudo apt-get update
    sudo apt-get upgrade
    sudo apt-get autoremove
    
  5. マシンを再起動します。
  6. ターミナルを立ち上げ、次のようにタイプします。
    uname -r
    

    これで3.4.0-030400-genericと表示されれば新しいカーネルになったことを確認できます。

こうしたところ、私のThinkpad T430sは全くフリーズしなくなりました。カーネルの問題だったということですね。これで安心して解析ができます。