13,005
回編集
104行目: | 104行目: | ||
# ~/.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 | ||
156行目: | 148行目: | ||
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] => " | 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' | ||
181行目: | 173行目: | ||
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' | ||
193行目: | 183行目: | ||
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=' killall | 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 kexit=' killall plasmashell; echo <パスワード> | sudo -S systemctl stop graphical.target; echo <パスワード> | sudo -S systemctl restart multi-user.target' | alias kexit=' killall plasmashell; echo <パスワード> | sudo -S systemctl stop graphical.target; echo <パスワード> | sudo -S systemctl restart multi-user.target' | ||
alias | alias gnome=' echo <パスワード> | sudo -S systemctl isolate graphical.target' | ||
alias | alias kde=' echo <パスワード> | sudo -S systemctl isolate graphical.target' | ||
alias uoff=' sudo systemctl poweroff' | alias uoff=' sudo systemctl poweroff' | ||
alias ureboot=' sudo systemctl reboot' | alias ureboot=' sudo systemctl reboot' | ||
221行目: | 216行目: | ||
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=' $HOME/InstallSoftware/FreeRDP/freerdp-nightly/bin/xfreerdp /u:<仮想マシンのユーザ名> /p:<パスワード> /w:1600 /h:900 +clipboard /sound:rate:44100,channel:2 /drive:<共有ディレクトリ名>,<共有ディレクトリのフルパス> /v:<仮想マシンのIPアドレス>' | alias rwin10=' $HOME/InstallSoftware/FreeRDP/freerdp-nightly/bin/xfreerdp /u:<仮想マシンのユーザ名> /p:<パスワード> /w:1600 /h:900 +clipboard /sound:rate:44100,channel:2 /drive:<共有ディレクトリ名>,<共有ディレクトリのフルパス> /v:<仮想マシンのIPアドレス>' | ||
# | # If Install WebStorm | ||
# alias resetWS=' find | # alias resetWS=' find $HOME/.config/JetBrains/WebStorm2020.3/eval -type f -mtime +25 -delete' | ||
alias resetWS=' sh -c $HOME/InstallSoftware/WebStorm/WebStorm_2020_3/Trial_Restart.sh' | alias resetWS=' sh -c $HOME/InstallSoftware/WebStorm/WebStorm_2020_3/Trial_Restart.sh' | ||
# If Install VMware Workstation | |||
alias vmwarefix=' sudo vmware-modconfig --console --install-all' | |||
# 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 | ||
253行目: | 260行目: | ||
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 | ||
281行目: | 286行目: | ||
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() | ||
{ | { | ||
315行目: | 336行目: | ||
} | } | ||
# | # man using Web Browser | ||
function manh() | function manh() | ||
{ | { | ||
327行目: | 348行目: | ||
} | } | ||
# Search for directories and files that exist in a directory | |||
function lgrep() | function lgrep() | ||
{ | { | ||
467行目: | 488行目: | ||
} | } | ||
# | # 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 | ||
486行目: | 507行目: | ||
fi | fi | ||
EXIST_FLAG=0 | local EXIST_FLAG=0 | ||
for VALUE in ${(s/:/)PATH} | for VALUE in ${(s/:/)PATH} | ||
do | do | ||
495行目: | 516行目: | ||
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 | ||
506行目: | 528行目: | ||
} | } | ||
# 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 | if [ "${EXIST_FLAG}" -eq 0 ]; then | ||
export LD_LIBRARY_PATH="$PATH_NAME:$LD_LIBRARY_PATH" | export LD_LIBRARY_PATH="${PATH_NAME}:${LD_LIBRARY_PATH}" | ||
elif [ $EXIST_FLAG -eq 1 ]; then | echo "Add ${PATH_NAME} in LD_LIBRARY_PATH " 1>&2 | ||
echo "Already Exist $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 | 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 | ||
return 0 | return 0 | ||
} | } | ||
547行目: | 571行目: | ||
function chip() | function chip() | ||
{ | { | ||
if [ ${#} != 1 | if [ ${#} != 1 ]; then | ||
echo "The argument is wrong." >&2 | echo "The argument is wrong." >&2 | ||
return 1 | return 1 | ||
fi | fi | ||
#sudo ip link set eth0 down | |||
#sudo nmcli connection down Wired | |||
sudo nmcli device disconnect eth0 | |||
sudo nmcli device disconnect | |||
sudo systemctl stop NetworkManager | sudo systemctl stop NetworkManager | ||
sudo sed -i -e "s/^address1=.*/address1="${1}"\/24, | 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 systemctl start NetworkManager | ||
sudo nmcli device connect | sudo nmcli device connect eth0 | ||
#sudo nmcli connection up Wired | |||
#sudo ip link set eth0 up | |||
return 0 | return 0 | ||
} | } | ||
# | # Start KVM | ||
function startkvm | 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 | fi | ||
# Start SSH, and then open port Firewalld | |||
if [ -n "$ | 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 | |||
if [ - | sudo systemctl enable inhibit-sleep.service | ||
fi | fi | ||
} | } | ||
# | # Stop SSH | ||
function | function stopssh | ||
{ | { | ||
# Get SSH port number | |||
if [ -n | 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 | fi | ||
# Stop SSH, and then, close port Firewalld | |||
if [ -n " | 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 | fi | ||
if [ -f /usr/lib/systemd/system/inhibit-sleep.service ]; then | |||
if [ - | sudo systemctl disable inhibit-sleep.service | ||
fi | fi | ||
} | } | ||
# | # Start Apache2 and MySQL8 | ||
function startlamp() | function startlamp() | ||
{ | { | ||
local APACHE2_STATUS=$(sudo systemctl status apache2 | grep | local APACHE2_STATUS=$(sudo systemctl status apache2 | \grep "Active:" | \grep -ie "dead") | ||
if [ -n "APACHE2_STATUS" ]; then | if [ -n "APACHE2_STATUS" ]; then | ||
sudo systemctl start apache2 | sudo systemctl start apache2 | ||
fi | fi | ||
local MYSQL8_STATUS=$(sudo systemctl status mysql | grep | local MYSQL8_STATUS=$(sudo systemctl status mysql | \grep "Active:" | \grep -ie "dead") | ||
if [ -n "MYSQL8_STATUS" ]; then | if [ -n "MYSQL8_STATUS" ]; then | ||
sudo systemctl start mysql | sudo systemctl start mysql | ||
621行目: | 731行目: | ||
} | } | ||
# | # Stop Apache2 and MySQL8 | ||
function stoplamp() | function stoplamp() | ||
{ | { | ||
local APACHE2_STATUS=$(sudo systemctl status apache2 | grep "Active:" | grep -ie "running") | local APACHE2_STATUS=$(sudo systemctl status apache2 | \grep "Active:" | \grep -ie "running") | ||
if [ -n "APACHE2_STATUS" ]; then | if [ -n "APACHE2_STATUS" ]; then | ||
sudo systemctl stop apache2 | sudo systemctl stop apache2 | ||
fi | fi | ||
local MYSQL8_STATUS=$(sudo systemctl status mysql | grep "Active:" | grep -ie "running") | local MYSQL8_STATUS=$(sudo systemctl status mysql | \grep "Active:" | \grep -ie "running") | ||
if [ -n "MYSQL8_STATUS" ]; then | if [ -n "MYSQL8_STATUS" ]; then | ||
sudo systemctl stop mysql | sudo systemctl stop mysql | ||
fi | fi | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<br><br> | <br><br> |