📢 Webサイト閉鎖と移転のお知らせ
このWebサイトは2026年9月に閉鎖いたします。
新しい記事は移転先で追加しております。(旧サイトでは記事を追加しておりません)
| (同じ利用者による、間の22版が非表示) | |||
| 4行目: | 4行目: | ||
Linuxにてターミナルでコマンドを実行することが多々あるが、zshに切り替えることで、作業効率を上げることができる。<br> | Linuxにてターミナルでコマンドを実行することが多々あるが、zshに切り替えることで、作業効率を上げることができる。<br> | ||
<br> | <br> | ||
最新のZshは[http://zsh.sourceforge.net/Arc/source.html Zshの公式Webサイト]で確認できる。<br> | |||
最新のZshは[http://zsh.sourceforge.net/Arc/source.html | |||
<br><br> | <br><br> | ||
== Zshのインストール == | == Zshのインストール == | ||
==== | ==== パッケージ管理システムからインストール ==== | ||
# RHEL | |||
sudo | sudo dnf install zsh | ||
# SUSE | |||
sudo zypper install zsh | |||
# Raspberry Pi | |||
sudo apt install zsh | |||
<br> | <br> | ||
==== ソースコードからインストール ==== | |||
まず、Zshのビルドに必要なライブラリをインストールする。<br> | |||
# RHEL | |||
sudo subscription-manager repos --enable codeready-builder-for-rhel-9-$(arch)-rpms | |||
sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm | |||
sudo dnf install ncurses-devel | |||
# SUSE | |||
sudo zypper install ncurses-devel | |||
# Raspberry Pi | |||
sudo apt install libncurses-dev | |||
<br> | |||
次に、以下に示すZshの公式WebサイトまたはSouceforgeから、Zshのソースコードをダウンロードする。<br> | |||
* https://zsh.sourceforge.io | |||
* http://zsh.sourceforge.net | |||
* Githubのミラー : https://github.com/zsh-users/zsh/ | |||
<br> | |||
<u>Zshのビルドでは、ビルドディレクトリを作成しないこと。</u><br> | |||
wget https://sourceforge.net/projects/zsh/files/zsh/<バージョン名>/zsh-<バージョン名>.tar.xz/download -O zsh-<バージョン名>.tar.xz | wget https://sourceforge.net/projects/zsh/files/zsh/<バージョン名>/zsh-<バージョン名>.tar.xz/download -O zsh-<バージョン名>.tar.xz | ||
tar | tar xf zsh-<バージョン名>.tar.xz | ||
cd zsh- | cd zsh-<バージョン名> | ||
<br> | <br> | ||
次に、Zshをビルドおよびインストールする。<br> | |||
--enable- | ここで、<code>--enable-multibyte</code>オプションは、マルチバイトを有効にするオプションである。<br> | ||
./configure --enable-multibyte --prefix= | ./configure --enable-multibyte --prefix=<Zshのインストールディレクトリ> | ||
make -j | make -j $(nproc) | ||
make install | make install | ||
<br> | <br> | ||
<u>※注意</u><br> | |||
<u>configureスクリプトの実行において、以下に示すエラーが出力される時がある。</u><br> | |||
config.status: error: cannot find input file: `config.h.in' | |||
<br> | <br> | ||
<u>この時、<code>autoheader</code>コマンドを実行して、config.h.inファイルを作成する。</u><br> | |||
autoheader | |||
<br><br> | <br><br> | ||
== | == Zshの使用 == | ||
Zshを利用可能なシェル一覧に追加する。<br> | Zshを利用可能なシェル一覧に追加する。<br> | ||
/etc/shellsファイルにzshのパスを追加することにより、<code>chsh</code>コマンド、または、<code>usermod</code>コマンドでログインシェルの変更が可能となる。<br> | |||
echo "/<zshのインストールディレクトリ>/bin/zsh" | sudo tee -a /etc/shells | |||
<br> | <br> | ||
次に、ユーザのシェルを変更する。(コマンドを実行するとパスワードの入力が必要となる)<br> | 次に、ユーザのシェルを変更する。(コマンドを実行するとパスワードの入力が必要となる)<br> | ||
chsh -s /<zshのインストールディレクトリ>/bin/zsh | chsh -s /<zshのインストールディレクトリ>/bin/zsh $USER | ||
# または | |||
sudo usermod --shell /<zshのインストールディレクトリ>/bin/zsh $USER | |||
<br> | <br> | ||
ログインシェルが変更されているかどうかを確認する。<br> | |||
grep $USER /etc/passwd | |||
<br> | |||
再ログイン、または、PCを再起動する。<br> | |||
<br> | <br> | ||
すると、以下の文言が表示される。これは、Zshに設定ファイルが存在しないために表示される。<br> | すると、以下の文言が表示される。これは、Zshに設定ファイルが存在しないために表示される。<br> | ||
| 62行目: | 86行目: | ||
--- Type one of the keys in parentheses --- | --- Type one of the keys in parentheses --- | ||
<br><br> | |||
== エラー == | |||
Zshを起動した時、以下のようなエラーが発生する場合がある。<br> | |||
stty: invalid integer argument〜 | |||
<br> | |||
Zshでは、^(キャレット)は拡張グロブ文字であり、コマンド処理のファイル名拡張部分で認識される。<br> | |||
<br> | |||
例えば、^Mは、Mにマッチするものを除く全てのファイル名にマッチする。<br> | |||
この時、stty eraseに続き、カレントディレクトリにMという名前のファイルがあれば、それを除く全てのファイル名を展開するということである。<br> | |||
<br> | |||
このエラーを回避するには、^(キャレット)文字を使用している箇所を、引用またはエスケープする必要がある。<br> | |||
'^M' | |||
または | |||
\^M | |||
<br> | |||
または、~/.zshrcファイルにおいて、Zshの拡張グロブを無効にする。<br> | |||
<syntaxhighlight lang="zsh"> | |||
setopt NO_EXTENDED_GLOB | |||
</syntaxhighlight> | |||
<br><br> | <br><br> | ||
| 71行目: | 115行目: | ||
# ~/.zshrcファイル | # ~/.zshrcファイル | ||
# Ctrl + | # Don't logout with Ctrl + D | ||
setopt IGNOREEOF | setopt IGNOREEOF | ||
# | # Don't overwrite with redirect | ||
setopt NOCLOBBER | setopt NOCLOBBER | ||
# | # Use Japanese | ||
# export LANG=ja_JP.UTF-8 | # export LANG=ja_JP.UTF-8 | ||
# | # Use color | ||
autoload -Uz colors | autoload -Uz colors | ||
colors | colors | ||
# | # Enable auto-completion wih [Tab] key | ||
autoload -Uz compinit | autoload -Uz compinit | ||
compinit | compinit | ||
# | # Enable Emacs-like operations | ||
bindkey -e | bindkey -e | ||
bindkey ";5C" emacs-forward-word # Ctrl-Right to move the cursor | |||
bindkey ";5D" emacs-backward-word # Ctrl-Left to move the cursor | |||
bindkey ";5C" emacs-forward-word | |||
bindkey ";5D" emacs-backward-word | |||
# | # Share history with other terminals | ||
setopt share_history | setopt share_history | ||
# | # Don't show duplicates in history | ||
setopt HIST_IGNORE_ALL_DUPS | setopt HIST_IGNORE_ALL_DUPS | ||
# | # Ignore duplicate histories | ||
setopt HIST_IGNORE_DUPS | setopt HIST_IGNORE_DUPS | ||
# | # Delete empty line from history | ||
setopt HIST_REDUCE_BLANKS | setopt HIST_REDUCE_BLANKS | ||
# | # Ignore commands that start with blank space | ||
setopt HIST_IGNORE_SPACE | setopt HIST_IGNORE_SPACE | ||
# | # Don't add history command & fc commands to history | ||
setopt HIST_NO_STORE | setopt HIST_NO_STORE | ||
| 123行目: | 159行目: | ||
SAVEHIST=100 | SAVEHIST=100 | ||
# | # If command you entered doesn't exist and matches the directory name, cd to directory | ||
# | # Ex. Type /usr/bin to go to /usr/bin directory | ||
setopt auto_cd | setopt auto_cd | ||
# cd | # Add directory you cd to to directory stack | ||
# | # "The directory stack" is history of directories you've been to so far | ||
# | # cd + [Tab] will show directory history and take you to it | ||
setopt auto_pushd | setopt auto_pushd | ||
# | # Delete duplicates from pushd | ||
setopt pushd_ignore_dups | setopt pushd_ignore_dups | ||
# | # Fix command error | ||
setopt correct | setopt correct | ||
SPROMPT="correct: $RED%R$DEFAULT -> $GREEN%r$DEFAULT ? [Yes/No/Abort/Edit] => " | |||
# | # Global Alias | ||
alias -g cd=' cd -P' | alias -g cd=' cd -P' | ||
alias -g rm='rm -iv' | alias -g rm='rm -iv' | ||
alias -g cp='cp -i' | alias -g cp='cp -i' | ||
alias -g mv='mv -iv' | alias -g mv='mv -iv' | ||
alias -g | alias -g ll=' ls -hlvF --group-directories-first --color' | ||
alias -g cat=' cat -n' | alias -g cat=' cat -n' | ||
alias -g less=' less -n' | alias -g less=' less -n' | ||
alias -g grep=' grep -i' | alias -g grep=' grep -i' | ||
alias -g usermod='usermod -a' | |||
alias -g en=' LANG=C LANGUAGE=C LC_ALL=C' | alias -g en=' LANG=C LANGUAGE=C LC_ALL=C' | ||
alias -g jp='LANG=ja_JP.UTF-8' | alias -g jp='LANG=ja_JP.UTF-8' | ||
alias -g mount='mount -o ro,noload' | alias -g mount='mount -o ro,noload' | ||
alias -g umount='umount -fl' | alias -g umount='umount -fl' | ||
alias -g L='| less' | alias -g L='| less' | ||
alias -g H='| head' | alias -g H='| head' | ||
| 157行目: | 194行目: | ||
alias -g GI='| grep -ri' | alias -g GI='| grep -ri' | ||
alias -g D='--detail' | alias -g D='--detail' | ||
alias -g | alias -g progress='& progress -mp $!' | ||
alias -g nano='nano -lmS' | |||
alias -g kate='kate 1>&/dev/null 2>&1' | |||
alias -g skate='kdesu /usr/bin/kate 1>&/dev/null 2>&1' | |||
# | # Alias | ||
alias which=' which' | alias which=' which' | ||
alias clear=' clear && echo -en "\e[3J"' | alias clear=' clear && echo -en "\e[3J"' | ||
alias hclear=' rm -rf ~/.zsh_history 1>/dev/null && touch ~/.zsh_history 1>/dev/null' | alias hclear=' rm -rf ~/.zsh_history 1>/dev/null && touch ~/.zsh_history 1>/dev/null' | ||
alias igrep=' sudo zypper search -i' | alias igrep=' sudo zypper search -i' | ||
alias asearch=' sudo zypper search -uv' | |||
alias repoclean=' sudo zypper clean -a' | alias repoclean=' sudo zypper clean -a' | ||
alias skate='kdesu /usr/bin/kate' | alias skate='kdesu /usr/bin/kate' | ||
alias scode='code --user-data-dir=$HOME/Program/VScode_root_project' | alias scode='code --user-data-dir=$HOME/Program/VScode_root_project' | ||
alias suse=' cat /etc/SUSE-brand' | alias suse=' cat /etc/SUSE-brand' | ||
alias mksingless=' sudo snapper create -t single -d' | |||
alias upoweroff=' sudo systemctl poweroff' | alias upoweroff=' sudo systemctl poweroff' | ||
alias ureboot=' sudo systemctl reboot' | alias ureboot=' sudo systemctl reboot' | ||
alias startx=' startx' | alias startx=' startx' | ||
alias exit=' exit' | alias exit=' exit' | ||
alias gexit=' echo <パスワード> | sudo -S systemctl stop graphical.target; echo <パスワード> | sudo -S systemctl | alias gexit=' killall -3 gnome-shell > /dev/null 2>&1; echo <パスワード> | sudo -S systemctl stop graphical.target; echo <パスワード> | sudo -S systemctl isolate multi-user.target' | ||
alias | alias kexit=' killall plasmashell; echo <パスワード> | sudo -S systemctl stop graphical.target; echo <パスワード> | sudo -S systemctl restart multi-user.target' | ||
alias gnome=' sudo systemctl isolate graphical.target' | |||
alias | alias kde=' sudo systemctl isolate graphical.target' | ||
alias ureboot=' | alias uoff=' dbus-send --print-reply=literal --system --dest=org.freedesktop.login1 /org/freedesktop/login1 "org.freedesktop.login1.Manager.PowerOff" boolean:true' | ||
alias ureboot=' dbus-send --print-reply=literal --system --dest=org.freedesktop.login1 /org/freedesktop/login1 "org.freedesktop.login1.Manager.Reboot" boolean:true' | |||
alias fw=' sudo firewall-cmd' | alias fw=' sudo firewall-cmd' | ||
alias fwr='sudo firewall-cmd --reload' | alias fwr='sudo firewall-cmd --reload' | ||
| 184行目: | 227行目: | ||
alias startwicked=' sudo systemctl stop NetworkManager; sudo systemctl start wickedd wicked' | alias startwicked=' sudo systemctl stop NetworkManager; sudo systemctl start wickedd wicked' | ||
alias plasma=' /usr/bin/kquitapp5 plasmashell; plasmashell > /dev/null 2>&1 & disown | alias plasma=' /usr/bin/kquitapp5 plasmashell; plasmashell > /dev/null 2>&1 & disown; exit' # Restart Plasma Shell | ||
alias gshell=' killall -3 gnome-shell > /dev/null 2>&1 & disown; sleep 2; exit' # Restart GNOME Shell | |||
alias udesktop='update-desktop-database $HOME/.local/share/applications' # Update Desktop Entry | |||
alias sshpi='ssh <ユーザ名>@<ホスト名またはIPアドレス> -p <ポート番号> -i <暗号鍵ファイルのフルパス>' | alias sshpi='ssh <ユーザ名>@<ホスト名またはIPアドレス> -p <ポート番号> -i <暗号鍵ファイルのフルパス>' | ||
alias | alias sshpig=' ssh -Y <ユーザ名>@<ホスト名またはIPアドレス> -p <ポート番号> -i <暗号鍵ファイルのフルパス>' # Connect & Execute SSH GUI-Software Raspberry Pi | ||
alias sshpine=' ssh <ユーザ名>@<ホスト名またはIPアドレス> -p <ポート番号> -i <暗号鍵ファイルのフルパス>' # Connect SSH PinePhone | |||
alias sshvalue=' sshpass -p <パスワード> ssh <ユーザ名>@<ホスト名またはIPアドレス>' # Connect SSH Value Server | |||
alias sshxrea=' sshpass -p <パスワード> ssh <ユーザ名>@<ホスト名またはIPアドレス>' # Connect SSH XREA | |||
alias sshsakura=' sshpass -p <パスワード> ssh <ユーザ名>@<ホスト名またはIPアドレス>' # Connect SSH Sakura | |||
# | # If Install FreeRDP and Windows10(VM) with KVM | ||
alias rwin10=' | alias rwin10=' /<FreeRDPのインストールディレクトリ>/bin/xfreerdp /u:<仮想マシンのユーザ名> /p:<パスワード> /w:1600 /h:900 +clipboard /sound:rate:44100,channel:2 /drive:<共有ディレクトリ名>,<共有ディレクトリのフルパス> /v:<仮想マシンのIPアドレス>' | ||
# | # If Install VMware Workstation | ||
alias vmwarefix=' sudo vmware-modconfig --console --install-all' | |||
alias | |||
# If Install Docker | |||
alias startdocker=' sudo systemctl restart docker' | |||
alias stopdocker=' sudo systemctl stop docker' | |||
# backspace | # Allow backspace and delete keys to be used | ||
stty erase ^H | stty erase ^H | ||
bindkey "^[[3~" delete-char | bindkey "^[[3~" delete-char | ||
# | # Run ls command, after cd command | ||
chpwd() | function chpwd() | ||
{ | { | ||
ls -hlFtr --color=auto | ls -hlFtr --color=auto | ||
} | } | ||
# | # Directory paths that can be referenced from anywhere | ||
#cdpath=(~) | #cdpath=(~) | ||
# | # Setting the delimiter | ||
autoload -Uz select-word-style | autoload -Uz select-word-style | ||
select-word-style default | select-word-style default | ||
| 216行目: | 267行目: | ||
zstyle ':zle:*' word-style unspecified | zstyle ':zle:*' word-style unspecified | ||
# Ctrl + | # Disable Ctrl + [s] lock, Ctrl + [q] unlock | ||
setopt no_flow_control | setopt no_flow_control | ||
# | # Dislay custom prompt | ||
PROMPT="%(?.%{${fg[red]}%}.%{${fg[red]}%})%n${reset_color}@${fg[green]}%m${reset_color}(%*%) Using Zsh %{${fg[yellow]}%}[%~]%{${reset_color}%} | |||
> " | > " | ||
# | # Press [Tab] to display path name completion suggestions, and then press [Tab] to select a path name from suggestions | ||
# | # After completion, you will be in menu selection mode, and can use left and right keys to move | ||
zstyle ':completion:*:default' menu select=2 | zstyle ':completion:*:default' menu select=2 | ||
# | # Matches uppercase letters with completion | ||
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' | zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' | ||
# Ctrl+ | # Ctrl + [r] for incremental search of history, Ctrl + [s] for reverse order | ||
bindkey '^r' history-incremental-pattern-search-backward | bindkey '^r' history-incremental-pattern-search-backward | ||
bindkey '^s' history-incremental-pattern-search-forward | bindkey '^s' history-incremental-pattern-search-forward | ||
# | # Type command halfway through, then narrow it down from history | ||
# | # Ex. Type "ls", then Ctrl + [p] to go back through ls commands, Ctrl + [b] to go in reverse order | ||
autoload -Uz history-search-end | autoload -Uz history-search-end | ||
zle -N history-beginning-search-backward-end history-search-end | zle -N history-beginning-search-backward-end history-search-end | ||
| 244行目: | 293行目: | ||
bindkey "^b" history-beginning-search-forward-end | bindkey "^b" history-beginning-search-forward-end | ||
# | # "cdr" command enabled (directory history enabled even after logout) | ||
# cdr | # Show list using "cdr" + [Tab] | ||
autoload -Uz add-zsh-hook | autoload -Uz add-zsh-hook | ||
autoload -Uz chpwd_recent_dirs cdr | autoload -Uz chpwd_recent_dirs cdr | ||
add-zsh-hook chpwd chpwd_recent_dirs | add-zsh-hook chpwd chpwd_recent_dirs | ||
# | # The cdr command can now be used to move to directories that are not in history | ||
zstyle ":chpwd:*" recent-dirs-default true | zstyle ":chpwd:*" recent-dirs-default true | ||
# | # Multiple file mv | ||
# Ex. zmv *.txt *.txt.bk | |||
autoload -Uz zmv | autoload -Uz zmv | ||
alias zmv='noglob zmv -W' | alias zmv='noglob zmv -W' | ||
# | # Prevent prompt from overwriting output with no newlines | ||
unsetopt promptcr | unsetopt promptcr | ||
# | # If Install Git | ||
RPROMPT="%{${fg[blue]}%}%{${reset_color}%}" | |||
autoload -Uz vcs_info | |||
setopt prompt_subst | |||
zstyle ':vcs_info:git:*' check-for-changes true | |||
zstyle ':vcs_info:git:*' stagedstr "%F{yellow}!" | |||
zstyle ':vcs_info:git:*' unstagedstr "%F{red}+" | |||
zstyle ':vcs_info:*' formats "%F{green}%c%u[%b]%f" | |||
zstyle ':vcs_info:*' actionformats '[%b|%a]' | |||
precmd () { vcs_info } | |||
RPROMPT=$RPROMPT'${vcs_info_msg_0_}' | |||
# If Install Docker | |||
export DOCKER_HOST='tcp://localhost:2375' | |||
# Execute mkdir, after cd command | |||
function mkcd() | function mkcd() | ||
{ | { | ||
| 278行目: | 343行目: | ||
} | } | ||
# | # man using Web Browser | ||
function manh() | function manh() | ||
{ | { | ||
| 290行目: | 355行目: | ||
} | } | ||
# | # Search for directories and files that exist in a directory | ||
function lgrep() | function lgrep() | ||
{ | { | ||
| 376行目: | 413行目: | ||
} | } | ||
# | # After searching for a specific file in directory, search the contents that match pattern | ||
function datagrep() | function datagrep() | ||
{ | { | ||
| 458行目: | 495行目: | ||
} | } | ||
# | # Add Environment Variable PATH | ||
function SetPATH() | function SetPATH() | ||
{ | { | ||
BEFORE_HOME='$HOME' | local BEFORE_HOME='$HOME' | ||
AFTER_HOME="$HOME" | local AFTER_HOME="$HOME" | ||
PATH_NAME=$(echo ${1//"$BEFORE_HOME"/"$AFTER_HOME"}) | local PATH_NAME=$(echo "${1//"${BEFORE_HOME}"/"${AFTER_HOME}"}") | ||
SLASH=$(echo ${PATH_NAME: -1:1}) | local SLASH=$(echo "${PATH_NAME: -1:1}") | ||
if [ $SLASH = "/" ]; then | if [ "${SLASH}" = "/" ]; then | ||
local LENGTH="${#PATH_NAME}" | |||
let LENGTH="${LENGTH}"-1 | |||
PATH_NAME=$(echo "${PATH_NAME:0:${LENGTH}}") | |||
fi | fi | ||
| 505行目: | 514行目: | ||
fi | fi | ||
EXIST_FLAG=0 | local EXIST_FLAG=0 | ||
for VALUE in ${(s/:/)PATH} | for VALUE in ${(s/:/)PATH} | ||
do | do | ||
| 514行目: | 523行目: | ||
done | done | ||
if [ "$EXIST_FLAG" -eq 0 ]; then | if [ "${EXIST_FLAG}" -eq 0 ]; then | ||
export PATH="${PATH_NAME}:${PATH}" | |||
elif [ $EXIST_FLAG -eq 1 ]; then | echo "Add ${PATH_NAME} in PATH " 1>&2 | ||
elif [ "${EXIST_FLAG}" -eq 1 ]; then | |||
echo "Already Exist ${PATH_NAME} in PATH " 1>&2 | |||
fi | fi | ||
unset -v SLASH LENGTH BEFORE_HOME AFTER_HOME PATH_NAME EXIST_FLAG VALUE | unset -v SLASH LENGTH BEFORE_HOME AFTER_HOME PATH_NAME EXIST_FLAG VALUE | ||
| 525行目: | 535行目: | ||
} | } | ||
# Add Environment Variable LD_LIBRARY_PATH | |||
function SetLIBRARY() | function SetLIBRARY() | ||
{ | { | ||
BEFORE_HOME='$HOME' | local BEFORE_HOME='$HOME' | ||
AFTER_HOME="$HOME" | local AFTER_HOME="${HOME}" | ||
PATH_NAME=$(echo ${1//"$BEFORE_HOME"/"$AFTER_HOME"}) | local PATH_NAME=$(echo ${1//"${BEFORE_HOME}"/"${AFTER_HOME}"}) | ||
SLASH=$(echo ${PATH_NAME: -1:1}) | local SLASH=$(echo ${PATH_NAME: -1:1}) | ||
if [ $SLASH = "/" ]; then | if [ ${SLASH} = "/" ]; then | ||
LENGTH="${#PATH_NAME}" | local LENGTH="${#PATH_NAME}" | ||
let LENGTH=$LENGTH-1 | let LENGTH=${LENGTH}-1 | ||
PATH_NAME=$(echo ${PATH_NAME:0:$LENGTH}) | PATH_NAME=$(echo ${PATH_NAME:0:${LENGTH}}) | ||
fi | fi | ||
if [ ! -d $PATH_NAME ]; then | if [ ! -d "${PATH_NAME}" ]; then | ||
echo "No Exist Directory $PATH_NAME" | echo "No Exist Directory ${PATH_NAME}" | ||
return 1 | return 1 | ||
fi | fi | ||
EXIST_FLAG=0 | local EXIST_FLAG=0 | ||
for VALUE in ${(s/:/)LD_LIBRARY_PATH} | for VALUE in ${(s/:/)LD_LIBRARY_PATH} | ||
do | do | ||
if [ "$VALUE" = "$PATH_NAME" ]; then | if [ "${VALUE}" = "${PATH_NAME}" ]; then | ||
EXIST_FLAG=1 | EXIST_FLAG=1 | ||
break | break | ||
fi | fi | ||
done | done | ||
if [ "${EXIST_FLAG}" -eq 0 ]; then | |||
export LD_LIBRARY_PATH="${PATH_NAME}:${LD_LIBRARY_PATH}" | |||
echo "Add ${PATH_NAME} in LD_LIBRARY_PATH " 1>&2 | |||
elif [ "${EXIST_FLAG}" -eq 1 ]; then | |||
echo "Already Exist ${PATH_NAME} in LD_LIBRARY_PATH " 1>&2 | |||
fi | |||
unset -v SLASH LENGTH BEFORE_HOME AFTER_HOME PATH_NAME EXIST_FLAG VALUE | |||
return 0 | |||
} | |||
# Change Private IP Address | |||
function chip() | |||
{ | |||
if [ ${#} != 1 ]; then | |||
echo "The argument is wrong." >&2 | |||
return 1 | |||
fi | |||
if [ $ | #sudo ip link set eth0 down | ||
#sudo nmcli connection down Wired | |||
sudo nmcli device disconnect eth0 | |||
sudo systemctl stop NetworkManager | |||
sudo sed -i -e "s/^address1=.*/address1="${1}"\/24,192.168.1.1/g" /etc/NetworkManager/system-connections/Wired.nmconnection | |||
sudo systemctl start NetworkManager | |||
sudo nmcli device connect eth0 | |||
#sudo nmcli connection up Wired | |||
#sudo ip link set eth0 up | |||
return 0 | |||
} | |||
# Start KVM | |||
function startkvm | |||
{ | |||
local KVM_STATUS=$(sudo systemctl status libvirtd | \grep "Active:" | \grep -ie "dead") | |||
if [ -n "KVM_STATUS" ]; then | |||
sudo systemctl start libvirtd | |||
fi | |||
local NETWORK_STATUS=$(LANG=C LANGUAGE=C LC_ALL=C sudo virsh net-info default | \grep -ie "Active:" -ie "Active" | \grep -ie "no") | |||
if [ -n "$NETWORK_STATUS" ]; then | |||
sudo virsh net-start default | |||
fi | |||
# if [ -f /usr/lib/systemd/system/libvirt-nosleep.service ]; then | |||
# local KVM_STATUS=$(sudo systemctl status libvirt-nosleep | grep "Active:" | grep -ie "dead") | |||
# if [ -n "KVM_STATUS" ]; then | |||
# sudo systemctl start libvirt-nosleep | |||
# fi | |||
# else | |||
# echo "Not exist libvirt-nosleep.service file." 1>&2 | |||
# fi | |||
} | |||
# Stop KVM | |||
function stopkvm | |||
{ | |||
local NETWORK_STATUS=$(LANG=C LANGUAGE=C LC_ALL=C sudo virsh net-info default | \grep -ie "Active:" -ie "Active" | \grep -ie "yes") | |||
if [ -n "$NETWORK_STATUS" ]; then | |||
sudo virsh net-destroy default | |||
fi | |||
local KVM_STATUS=$(sudo systemctl status libvirtd | \grep "Active:" | \grep -ie "running") | |||
if [ -n "KVM_STATUS" ]; then | |||
sudo systemctl stop libvirtd libvirtd.socket libvirtd-admin.socket libvirtd-ro.socket | |||
fi | |||
# if [ -f /usr/lib/systemd/system/libvirt-nosleep.service ]; then | |||
# local KVM_STATUS=$(sudo systemctl status libvirt-nosleep | \grep "Active:" | \grep -ie "Active") | |||
# if [ -n "KVM_STATUS" ]; then | |||
# sudo systemctl stop libvirt-nosleep | |||
# fi | |||
# else | |||
# echo "Not exist libvirt-nosleep.service file." 1>&2 | |||
# fi | |||
} | |||
# Start SSH | |||
function startssh | |||
{ | |||
# Get SSH port number | |||
local PORT="" | |||
for VALUE in $(sudo \cat /etc/ssh/sshd_config | \grep -E '^Port ' | \cut -d " " -f2-) | |||
do | |||
if [ -n $(\echo ${VALUE} | \grep -E '[0-9]') ]; then | |||
PORT=${VALUE} | |||
break | |||
fi | |||
done | |||
if [ -n $PORT ]; then | |||
echo "Port Number: ${PORT}" | |||
else | |||
echo "Port Number: 22" | |||
fi | |||
# Start SSH, and then open port Firewalld | |||
local SSH_STATUS=$(LANG=C LANGUAGE=C LC_ALL=C sudo systemctl status sshd | \grep "Active:" | \grep -ie "dead") | |||
if [ -n "$SSH_STATUS" ]; then | |||
sudo systemctl start sshd | |||
echo -n "Open Port Firewalld: " | |||
if [ -z ${PORT} ]; then | |||
sudo firewall-cmd --permanent --zone=public --add-service=ssh | |||
else | |||
sudo firewall-cmd --permanent --zone=public --add-port="${PORT}"/tcp | |||
fi | |||
echo -n "Reload Firewalld: " | |||
sudo firewall-cmd --reload | |||
fi | fi | ||
if [ -f /usr/lib/systemd/system/inhibit-sleep.service ]; then | |||
sudo systemctl enable inhibit-sleep.service | |||
fi | |||
} | |||
# Stop SSH | |||
function stopssh | |||
{ | |||
# Get SSH port number | |||
local PORT="" | |||
for VALUE in $(sudo \cat /etc/ssh/sshd_config | \grep -E '^Port ' | \cut -d " " -f2-) | |||
do | |||
if [ -n $(\echo ${VALUE} | \grep -E '[0-9]') ]; then | |||
PORT=${VALUE} | |||
break | |||
fi | |||
done | |||
if [ -n $PORT ]; then | |||
echo "Port Number: ${PORT}" | |||
else | |||
echo "Port Number: 22" | |||
fi | |||
# Stop SSH, and then, close port Firewalld | |||
local SSH_STATUS=$(LANG=C LANGUAGE=C LC_ALL=C sudo systemctl status sshd | \grep "Active:" | \grep -ie "running") | |||
if [ -n "$SSH_STATUS" ]; then | |||
sudo systemctl stop sshd | |||
echo -n "Close Port Firewalld: " | |||
if [ -z ${PORT} ]; then | |||
sudo firewall-cmd --permanent --zone=public --remove-service=ssh | |||
else | |||
sudo firewall-cmd --permanent --zone=public --remove-port="${PORT}"/tcp | |||
fi | |||
echo -n "Reload Firewalld: " | |||
sudo firewall-cmd --reload | |||
fi | |||
if [ -f /usr/lib/systemd/system/inhibit-sleep.service ]; then | |||
sudo systemctl disable inhibit-sleep.service | |||
fi | |||
} | |||
# Start Apache2 and MySQL8 | |||
function startlamp() | |||
{ | |||
local APACHE2_STATUS=$(sudo systemctl status apache2 | \grep "Active:" | \grep -ie "dead") | |||
if [ -n "APACHE2_STATUS" ]; then | |||
sudo systemctl start apache2 | |||
fi | |||
local MYSQL8_STATUS=$(sudo systemctl status mysql | \grep "Active:" | \grep -ie "dead") | |||
if [ -n "MYSQL8_STATUS" ]; then | |||
sudo systemctl start mysql | |||
fi | |||
} | |||
# Stop Apache2 and MySQL8 | |||
function stoplamp() | |||
{ | |||
local APACHE2_STATUS=$(sudo systemctl status apache2 | \grep "Active:" | \grep -ie "running") | |||
if [ -n "APACHE2_STATUS" ]; then | |||
sudo systemctl stop apache2 | |||
fi | |||
local MYSQL8_STATUS=$(sudo systemctl status mysql | \grep "Active:" | \grep -ie "running") | |||
if [ -n "MYSQL8_STATUS" ]; then | |||
sudo systemctl stop mysql | |||
fi | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<br><br> | <br><br> | ||
__FORCETOC__ | __FORCETOC__ | ||
[[カテゴリ: | [[カテゴリ:RHEL]][[カテゴリ:SUSE]][[カテゴリ:Raspberry_Pi]][[カテゴリ:シェルスクリプト]] | ||