(Linux用) gitのbranchの情報をプロンプトに出す方法メモ

  1. git-prompt.shをダウンロード

    wget https://raw.github.com/git/git/master/contrib/completion/git-prompt.sh

  2. .bashrcを編集する

    1. PS1を設定している箇所を変更。最後の\$の前に$(__git_ps1 " (%s)")を入れる
      PS1='${debian_chroot:+($debian_chroot)}[\033[01;32m]\u@\h[\033[00m]:[\033[01;34m]\w[\033[00m]$(__git_ps1 " (%s)")\$ '
      debian 10での設定
    2. 末尾にダウンロードしたgit-prompt.shの読み込みを追加(PS1の設定の後でも動作するらしい)
      source /path/to/git-prompt.sh

これでOKのはず

参考サイト: git :: bash プロンプトにブランチ名と作業ツリーの状態を表示する [Tipsというかメモ]

Gitでよく使うコマンドメモ


1. ブランチ作成
  git branch (branchname)
  
2. ブランチ切替
 git checkout (branchnname)  

3. 現在のブランチ確認
 git branch
 
4. 作成したブランチのPush
  git push -u origin (branchname)


5. ブランチの削除(ローカル)
  git branch -d (branchname)

6. ブランチの削除(リモート)
  git push origin --delete (branchname)

7. タグ付け
 git tag -a (tag) -m (tag comments)
 
 ex) git tag -a v0.1.3 -m "File IO implemented."
 
8. タグのPush
  git push origin (tag)
  
  git push origin v0.1.3
  

VS Codeで5がbackspaceになるときの対応方法

以下の環境でVisual Studio Codeを使うとなぜかキーボードの"5"キーがBackspaceの動きになってしまう。

settings.jsonに以下の対処で解決できた

{
    "keyboard.dispatch": "keyCode"
}

参考URL

linux同士のsamba覚書

サーバー側

  1.  # apt install samba
  2.  # smbpasswd -a (user)
    このあと、パスワードを聞かれるので入力

これで、userのホームディレクトリにアクセスできるようになる

※/etc/samba/smb.confは触らなくてもOKのはず

 

クライアント側

  1. # apt install gvfs-backends
    Thnar(ファイルマネージャー)でアクセスできるようする
  2. # apt install smbclient
  3. # apt install cifs-utils
  4. /etc/fstabにエントリをこんな感じで追加
    //(server)/(user) /mnt/dir01 cifs user,noauto 0 0
  5. 一般ユーザーでmount /mnt/dir01とすると、パスワードを聞かれてくるので、入力するとマウントされる

実際は3, 4, 5の手順だけで十分かもしれない

 

GCPのdebianでansibleを動かすまで

ansibleサーバでansibleを使って、ターゲットサーバにapache2を入れるまでの手順

環境:Google Compute Engine上のdebian10

  • deb01: ansibleサーバ
  • deb02: ターゲットサーバ

1. ansibleサーバの作業(1)

1) GCPVMインスタンスの画面からSSH接続でログイン

2) rootになる

$ sudo su - 

3) ユーザー作成

# adduser dev01

4) /etc/sudoers.d/配下にdev01を作成する

# cd /etc/sudoers.d
# vi dev01

dev01の内容

dev01   ALL=(ALL:ALL) NOPASSWD:ALL

5) dev01ファイルをリードオンリーにする

# chmod 0440 dev01

6) 一旦rootからログアウト

# exit

7) ユーザdev01からrootにパスワード無しでsuできるか確認

$ su - dev01
(パスワードを入力)
$ sudo su - 
(パスワード入力なしでrootになるはず)

ここまでできれば、一旦終了。exitしてdev01に戻る

2.ターゲットサーバの作業

1) 1. ansibleサーバの作業の1)~5)までを実施

2) sshでのパスワードログインを(一時的に)有効にする /etc/ssh/sshd_configを編集し、PasswordAuthentication noを yes に変更

# vi /etc/ssh/sshd_config
(内容の編集)
PasswordAuthentication no (変更前)
↓
PasswordAuthentication yes (変更後)

3) sshdを再起動

# systemctl restart sshd

4) ターゲットサーバーの作業はここで一旦終了。ログアウトする

3. ansibleサーバの作業(2)

1) sshでターゲットサーバーにパスワードを使ってログインできるか確かめる。
ユーザdev01になってsshでターゲットサーバにログイン

$ su- dev01
$ ssh deb02         #deb02はターゲットサーバー

2) exitしてansibleサーバに戻った後、sshの鍵ペアを作成する。パスフレーズを聞かれたら、何も入力せずにエンター

$ ssh-keygen -t rsa -b 4096

3) ターゲットサーバに公開鍵をコピーする。ターゲットサーバ側のパスワードを聞かれるので入力する

$ ssh-copy-id deb02

4) 再度sshでターゲットサーバーにログイン。パスワードを聞かれないことを確認

(ここからansibleインストール)

 5) /etc/apt/sources.list に以下を追加

deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main

6) 以下のコマンドを実行して、ansibleをインストール

$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367
$ sudo apt update
$ sudo apt install ansible

参考) Ansible のインストール — Ansible Documentation

7) /etc/ansible/hostsを編集

(末尾に以下を追加)
[svrs]
10.128.0.3      #ターゲットサーバのIPアドレスを設定する

8) ansibleのpingモジュールで動作テスト(参考として実行結果も掲載)

$ ansible svrs -m ping
[WARNING]: Platform linux on host 10.128.0.3 is using the discovered Python interpreter at /usr/bin/python3.7,
but future installation of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information.
10.128.0.3 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3.7"
    }, 
    "changed": false, 
    "ping": "pong"
}

(WARNINGが出ているが、今は何が問題でどうやって消すのかは不明)

9) apacheをインストールするansibleのplaybookを作成する。以下の内容でapache2.ymlを作成 (ファイルの作成場所は任意でOK)

- hosts: svrs
  remote_user: dev01
  become: yes
  tasks:
  - name: Install the package "apache2"
    apt:
      name: apache2

10) apache2.ymlを実行

$ ansible-playbook apache2.yml

11) ターゲットサーバーにアクセスし、Webサイトが見えたら成功!

参考サイト:

Angular: ng serveでシステムをサブディレクトリで動かす方法

angular.jsonのserveのブロックにbaseHrefとdeployUrlを追加する

こんな感じで

(略)
"serve": {
    "builder": "@angular-devkit/build-angular:dev-server", 
    "options": {
        "browserTarget": "wrio:build", 
        "baseHref": "/subdir/", 
        "deployUrl": "/subdir/" 
    }, 
    "configurations": {
        "production": {
            "browserTarget": "wrio:build:production" 
        } 
    }
},
(略)

GCE上でのAngularのng serveを外部からアクセスする

Google Compute Engineの仮想マシン上でAngularの開発をするとき、ng serveしても外からアクセスできない。

プロジェクト直下のangular.jsonをいじることで外から見えるようになる。

  • "serve"の"options"の中に"port"と"host"の項目をつける。
  • portで指定するポート番号は、GCEのファイアーウォール設定で穴をあけるのを忘れずに。
  • さらに"host"については、外部IPではなく、内部IPにしないとうまくいかない。
(省略)
"serve": {
    "options": {
        (省略),
        "port": 8080,
        "host": "10.142.0.6"

         }
(省略)

参考サイト:https://qiita.com/shirokuman/items/6491815836e2c6004315