speg03の雑記帳

主に未来の自分のために試したことなどを記録しています

Jenkinsでプロキシ認証を越えてyum update

プロキシ認証を含んだ処理のジョブ設定を行う話。共有サーバなどを利用しており認証情報が他人から見えないようにしたい場合に有効。

プロキシ認証情報の入力

Jenkinsジョブ設定のビルドパラメータで以下を設定する。

  • PROXY_USER ユーザID
  • PROXY_PASS パスワード

f:id:speg03:20200327214113p:plain

自動ビルド時にはここで入力されたデフォルト値が使用され、手動ビルドの場合はパラメータの入力欄が画面に表示される。

jenkinsユーザのsudo設定

yum updateはroot権限がないと実行できないので、jenkinsユーザが実行できるようsudoの設定を行う。

visudo (/etc/sudoers)で、jenkinsユーザがsudoで実行できる権限について以下を設定する。

# localhost上でのyum update -yのみパスワードなしで実行できる
# "localhost"の個所は`uname -n`で表示されるマシン名を使うこと
jenkins localhost=NOPASSWD: /usr/bin/yum update -y

# 通常の端末上でなくても実行できる
Defaults:jenkins !requiretty

# プロキシ環境変数を引き継ぐ
Defaults:jenkins env_keep += "http_proxy https_proxy"

ビルドスクリプト

以下のようなyum-update.shをSCMからチェックアウトするなどして、ジョブ設定のビルドのシェルスクリプト欄ではこのシェルスクリプトを実行するようにする。

#!/bin/bash

# コマンドのechoを止めてパスワードがログ出力されるのを防ぐ
set +x

# プロキシ認証
export http_proxy=http://$PROXY_USER:$PROXY_PASS@proxy.example.com:8080
export https_proxy=$http_proxy

# プロキシ認証の通信テスト
/usr/bin/curl -I http://www.google.co.jp 2>&1 | /bin/grep '200 OK'
if [ $? -ne 0 ]; then
  echo "Proxy Authentication Failed"
  exit 1
fi

# コマンドのechoを元に戻す
set -x

sudo /usr/bin/yum update -y

f:id:speg03:20200327214250p:plain

この例からもわかるようにビルドパラメータで設定した変数はビルド設定から呼び出された子プロセスのシェルでも有効になっている。

Chefのプロキシ設定

Chef 10.16.2時点の話。

Chefのプロキシ設定は複数箇所あってそれぞれ利用される場面が異なる。知っている範囲で以下の3種類。

  • package
  • remote_file
  • knife cookbook upload

package

packageリソースで実際に実行されるパッケージマネージャ(yumとか)が使うプロキシ設定はTarget Node上のOSで定義されたhttp_proxy環境変数になる。

これはChefに関係なく以下のような感じ。

export http_proxy=http://USER:PASSWORD@HOST:PORT
export https_proxy=$http_proxy

remote_file

remote_fileリソースは特定のコマンドを経由するのではなくてRubyのコードとして実装されている? Chefで実行される部分なのでChefのプロキシ設定が見られる。client.rbとかsolo.rbに書く。

http_proxy http://HOST:PORT
http_proxy_user USER
http_proxy_pass PASSWORD

https_proxy http://HOST:PORT
https_proxy_user USER
https_proxy_pass PASSWORD

no_proxy "192.168.*"

参考: http://wiki.opscode.com/display/chef/Chef+Configuration+Settings#ChefConfigurationSettings-httpproxy%2Chttpsproxy%2Cnoproxy

knife cookbook upload

CookbookをアップロードするChef Serverにアクセスするときにプロキシが必要な場合。Hosted Chefとか使っていると必要だったりする。これはknife.rbに書く。

require 'rest-client'
RestClient.proxy = "http://USER:PASSWORD@HOST:PORT"

参考: http://tickets.opscode.com/browse/CHEF-2232

まとめ

http_proxy環境変数さえ定義されていれば他の設定に伝搬するようにした。knife.rbとかclient.rbとかsolo.rbとかに書いたら良いと思う。

if ENV["http_proxy"]
  require 'rest-client'
  RestClient.proxy = ENV["http_proxy"]

  require 'uri'
  proxy_env = URI.parse(ENV["http_proxy"])
  proxy_user, proxy_pass = proxy_env.userinfo.split(":")

  http_proxy "http://#{proxy_env.host}:#{proxy_env.port}"
  https_proxy "http://#{proxy_env.host}:#{proxy_env.port}"
  http_proxy_user proxy_user
  http_proxy_pass proxy_pass
  https_proxy_user proxy_user
  https_proxy_pass proxy_pass
  no_proxy "192.168.*"
end

smali/baksmaliでAndroidのコードを編集してみる

Xperia mini proのCyanogenMod 9.1でセルスタンバイ問題について調べたときにやったことをメモしとく。

CyanogenMod

http://download.cyanogenmod.org/?type=stable&device=mango

cm-9.1.0-mango.zipを使った。

smali/baksmali

http://code.google.com/p/smali/

smali, baksmaliとも1.4.1を使った。jarファイルと起動用スクリプトをダウンロード。

スクリプトとjarを同じディレクトリに置いておけば良いみたいだった。jarのファイル名からバージョンを消しておく。以下みたいな感じになっていたら良さそう。

$ ls
baksmali  baksmali.jar  smali  smali.jar

やったこと

framework.jarからclasses.dexを抽出する

$ unzip -d cm-9.1.0-mango cm-9.1.0-mango.zip
$ cp cm-9.1.0-mango/system/framework/framework.jar .
$ unzip -l framework.jar
Archive:  framework.jar
  Length     Date   Time    Name
 --------    ----   ----    ----
        0  08-28-12 16:40   META-INF/
       71  08-28-12 16:40   META-INF/MANIFEST.MF
  9581924  08-28-12 16:40   classes.dex
    84385  04-18-12 08:48   preloaded-classes
 --------                   -------
  9666380                   4 files
$ unzip framework.jar classes.dex

baksmaliでディスアセンブルする

$ baksmali -o classes classes.dex

ごにょごにょ編集

$ $EDITOR classes/com/android/internal/telephony/gsm/GsmServiceStateTracker.smali

smaliでアセンブルしなおしてframework.jarに戻す

$ smali -o classes.dex classes
$ zip framework.jar classes.dex
$ unzip -l framework.jar
Archive:  framework.jar
  Length     Date   Time    Name
 --------    ----   ----    ----
        0  08-28-12 16:40   META-INF/
       71  08-28-12 16:40   META-INF/MANIFEST.MF
  9581888  12-14-12 21:35   classes.dex
    84385  04-18-12 08:48   preloaded-classes
 --------                   -------
  9666344                   4 files

Fedora17インストールメモ

OSインストール

Fedora Project

Fedora-17-x86_64-Live-Desktop.isoを使ってThinkPad X200sにインストールした。

sudo yum update

cat /etc/redhat-release
# Fedora release 17 (Beefy Miracle)
uname -a
# Linux altair 3.4.4-3.fc17.x86_64 #1 SMP Tue Jun 26 20:54:56 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

altairはホスト名

ThinkPadトラックポイント対応

sudo yum install gpointing-device-settings
gpointing-device-settings
  • 「ホイールエミュレーションを使用する」にチェック
  • 「ボタン」で「2」を選択
  • 「縦スクロールを有効にする」がチェックされていることを確認
  • 「横スクロールを有効にする」にチェック

sshd有効化

sudo systemctl enable sshd.service
sudo systemctl start sshd.service

iptables無効化

sudo systemctl stop iptables.service
sudo systemctl disable iptables.service

SELinux無効化

sudo setenforce 0
sudo vi /etc/selinux/config

SELINUXをpermissiveに変更。

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=permissive
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

Macで開発版GNU Screenをビルドする

事前準備

m4, autoconf, automakeあたりが必要っぽい。m4は入っていたから他をbrewでインストールした。

$ brew install autoconf
$ brew install automake

バージョン確認しとく。

$ autoconf --version
autoconf (GNU Autoconf) 2.69
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+/Autoconf: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>, <http://gnu.org/licenses/exceptions.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by David J. MacKenzie and Akim Demaille.

$ automake --version
automake (GNU automake) 1.12.1
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl-2.0.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Tom Tromey <tromey@redhat.com>
       and Alexandre Duret-Lutz <adl@gnu.org>.

$ m4 --version
GNU M4 1.4.6
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Written by Rene' Seindal.
開発版GNU Screenの取得とビルド

なんか出てるけどスルーした。

$ git clone git://git.savannah.gnu.org/screen.git
$ cd screen/src
$ ./autogen.sh
autoheader: WARNING: Using auxiliary files such as `acconfig.h', `config.h.bot'
autoheader: WARNING: and `config.h.top', to define templates for `config.h.in'
autoheader: WARNING: is deprecated and discouraged.
autoheader:
autoheader: WARNING: Using the third argument of `AC_DEFINE' and
autoheader: WARNING: `AC_DEFINE_UNQUOTED' allows one to define a template without
autoheader: WARNING: `acconfig.h':
autoheader:
autoheader: WARNING:   AC_DEFINE([NEED_FUNC_MAIN], 1,
autoheader:             [Define if a function `main' is needed.])
autoheader:
autoheader: WARNING: More sophisticated templates can also be produced, see the
autoheader: WARNING: documentation.

インストール

自分のホームディレクトリにインストールする。オプションは参考からそのまま頂いてきたのでよくわかってない。

$ ./configure --prefix=$HOME/local --enable-pam --enable-colors256 --enable-rxvt_osc --enable-use-locale --enable-telnet
$ make
$ make install

バージョン確認。

$ cd $HOME/local/bin
$ ./screen --version
Screen version 4.01.00devel (GNUdb59704) 2-May-06

MacのZshはシェル起動時にPATHをリセットする

zprofileに書いていたPATH設定だけが有効になっていなかったので調べたという話。zprofileに書いていたPATH以外の環境変数は有効になっていたのでzprofileが呼ばれていないわけではなかった。

path_helper

Macにはpath_helperというやつがあって、PATH環境変数を/etc/pathsや/etc/paths.dに書かれているパスで設定しなおす。で、こいつがまたいたるところで呼ばれる。

zshで呼ばれる設定ファイル

ログイン(ログインシェルとして起動)時にはzshenvとzprofile、対話シェルとして起動時にはzshenvが呼ばれる。PATHの設定は既存のPATHに追加していくので、ログイン時の一度だけ呼ばれて欲しい。そのためzprofileに書いていた。

件のzshenvは以下のようになっていた。

/etc/zshenv
# system-wide environment settings for zsh(1)
if [ -x /usr/libexec/path_helper ]; then
       eval `/usr/libexec/path_helper -s`
fi

zshenvでpath_helperが呼ばれているということは、対話シェルが起動する度にPATHがリセットされることになる。

対処

結局、/etc/zshenvの全行をコメントアウトすることにした。これでzprofileに書いていたPATH設定が有効になった。

追記 6/25 2:15

コメントいただきまして、brew info zshに情報がありました。これに沿ってやった方が良さそう。やはり/etc以下はあまり変えたくないので。

$ brew info zsh
To use this build of Zsh as your login shell, add it to /etc/shells.

If you have administrator privileges, you must fix an Apple miss
configuration in Mac OS X 10.7 Lion by renaming /etc/zshenv to
/etc/zprofile, or Zsh will have the wrong PATH when executed
non-interactively by scripts.

Alternatively, install Zsh with /etc disabled:

  brew install --disable-etcdir zsh

ということなので、

$ brew install --disable-etcdir zsh
$ sudo vi /etc/shells
(/usr/local/bin/zshを追加)
$ chsh
(Shellを/usr/local/bin/zshに変更)

IBusのアイコンが出なくなってた

なんかのタイミングでIBusのアイコンが出なくなってたので困っていた。IBusのトラブルよくある気がする。

Japanese packages for testersのパッケージで更新したら直った。

環境

Japanese packages for testers

ibus、mozc関連のパッケージが更新される。

sudo add-apt-repository ppa:japanese-testers/ppa
sudo apt-get update
sudo apt-get upgrade