본문 바로가기
Linux/Pogoplug

포고플러그 시리즈4에 아치리눅스 사용하기 (11) - 웰컴 메시지+컬러 쉘 적용하기

by 달토끼남편 2022. 10. 4.

 
포고플러그E02용 김구스님 한방팩에 적용되어 있는 웰컴메시지 및 컬러쉘 화면 저도 참 좋아하는데요.
한번 적용해 보겠습니다.
 
밋밋했던 SSH 화면이 화려하게 바뀝니다.
 
 
 
먼저 혹시 모를 사고에 대비 bash.bashrc를 다른 이름으로 저장한다
 
mv /etc/bash.bashrc /etc/bash.bashrc.original
nano /etc/bash.bashrc
 
 
그리고 아래의 내용을 그대로 붙여넣는다. (putty 사용자는 마우스 오른쪽 버튼이 붙여넣기, 드래그는 복사.)
 
# /etc/bash.bashrc
#
#
# This file is sourced by all *interactive* bash shells on startup,
# including some apparently interactive shells such as scp and rcp
# that can't tolerate any output. So make sure this doesn't display
# anything or bad things will happen !
 
# Test for an interactive shell. There is no need to set anything
# past this point for scp and rcp, and it's important to refrain from
# outputting anything in those cases.
 
# If not running interactively, don't do anything!
[[ $- != *i* ]] && return
 
# Bash won't get SIGWINCH if another process is in the foreground.
# Enable checkwinsize so that bash will check the terminal size when
# it regains control.
shopt -s checkwinsize
 
# Enable history appending instead of overwriting.
shopt -s histappend
 
case ${TERM} in
        xterm*|rxvt*|Eterm|aterm|kterm|gnome*)
                PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND; }'printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
                ;;
        screen)
                PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND; }'printf "\033_%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
                ;;
esac
 
# fortune is a simple program that displays a pseudorandom message
# from a database of quotations at logon and/or logout.
# Type: "pacman -S fortune-mod" to install it, then uncomment the
# following line:
 
# [[ "$PS1" ]] && /usr/bin/fortune
 
# Welcome Message
# Arch Linux Logo Welcome Message
c1="$(tput sgr0)$(tput setaf 4)"
c2="$(tput bold)$(tput setaf 4)"
c3="$(tput bold)$(tput setaf 7)"
echo
echo "        $c2,$c1                       _     _ _"
echo "       $c2/$c1#$c2\\$c1        __ _ _ __ ___| |__ | (_)_ __  _   ___  __"
echo "      $c2/$c1###$c2\\$c1      / _\` | '__/ __| '_ \\| | | '_ \\| | | \\ \\/ /"
echo "     $c2/$c1#####$c2\\$c1    | (_| | | | (__| | | | | | | | | |_| |>  <"
echo "    $c2/$c1##,-,##$c2\\$c1    \\__,_|_|  \\___|_| |_|_|_|_| |_|\\__,_/_/\\_\\"
echo "   $c2/$c1##(   )##$c2\\$c1"
echo "  $c2/$c1#.--   --.#$c2\\  $c3 A simple, elegant GNU/Linux distribution."
echo " $c2/$c1\`           \`$c2\\$(tput sgr0)"$'\n'
 
# Show date
DATE="$(tput setaf 1)[$(tput setaf 6)$(date)"
DATE="${DATE}$(tput setaf 1)]"
echo $DATE
# Show kernel info
KERNEL="$(tput setaf 1)[$(tput setaf 6)$(uname -srmn)"
KERNEL="${KERNEL}$(tput setaf 1)]"
echo "$KERNEL"$'\n'
# Reset colors
tput sgr0
 
# Set colorful PS1 only on colorful terminals.
# dircolors --print-database uses its own built-in database
# instead of using /etc/DIR_COLORS. Try to use the external file
# first to take advantage of user additions. Use internal bash
# globbing instead of external grep binary.
 
# sanitize TERM:
safe_term=${TERM//[^[:alnum:]]/?}
match_lhs=""
 
[[ -f ~/.dir_colors ]] && match_lhs="${match_lhs}$(<~/.dir_colors)"
[[ -f /etc/DIR_COLORS ]] && match_lhs="${match_lhs}$(</etc/DIR_COLORS)"
[[ -z ${match_lhs} ]] \
        && type -P dircolors >/dev/null \
        && match_lhs=$(dircolors --print-database)
 
if [[ $'\n'${match_lhs} == *$'\n'"TERM "${safe_term}* ]] ; then
 
        # we have colors <img src="http://obihoernchen.net/wordpress/wp-includes/images/smilies/icon_smile.gif" alt=":-)" class="wp-smiley"> 
 
        # Enable colors for ls, etc. Prefer ~/.dir_colors
        if type -P dircolors >/dev/null ; then
                if [[ -f ~/.dir_colors ]] ; then
                        eval $(dircolors -b ~/.dir_colors)
                elif [[ -f /etc/DIR_COLORS ]] ; then
                        eval $(dircolors -b /etc/DIR_COLORS)
                fi
        fi
 
        # -- CUSTOM PS1 String START --
 
        PS1="\[\033[0;37m\]\342\224\214\342\224\200\$([[ \$? != 0 ]] && echo \"[\[\033[0;31m\]\342\234\227\[\033[0;37m\]]\342\224\200\")[$(if [[ ${EUID} == 0 ]]; then echo '\[\033[0;31m\]\u\[\033[0;37m\]@\[\033[0;96m\]\h'; else echo '\[\033[0;33m\]\u\[\033[0;37m\]@\[\033[0;96m\]\h'; fi)\[\033[0;37m\]]\342\224\200[\[\033[0;32m\]\w\[\033[0;37m\]]\n\[\033[0;37m\]\342\224\224\342\224\200\342\224\200\076 \[\033[0m\]"
        # --- Custom PS1 String END ---
 
        # Use this other PS1 string if you want \W for root and \w for all other users:
        # PS1="$(if [[ ${EUID} == 0 ]]; then echo '\[\033[01;31m\]\h\[\033[01;34m\] \W'; else echo '\[\033[01;32m\]\u@\h\[\033[01;34m\] \w'; fi) \$([[ \$? != 0 ]] && echo \"\[\033[01;31m\]:(\[\033[01;34m\] \")\$\[\033[00m\] "
 
        alias ls="ls --color=auto"
        alias dir="dir --color=auto"
        alias grep="grep --colour=auto"
 
else
 
        # show root@ when we do not have colors
 
        PS1="\u@\h \w \$([[ \$? != 0 ]] && echo \":( \")\$ "
 
        # Use this other PS1 string if you want \W for root and \w for all other users:
        # PS1="\u@\h $(if [[ ${EUID} == 0 ]]; then echo '\W'; else echo '\w'; fi) \$([[ \$? != 0 ]] && echo \":( \")\$ "
 
fi
 
PS2="> "
PS3="> "
PS4="+ "
 
# Try to keep environment pollution down, EPA loves us.
unset safe_term match_lhs
 
# Try to enable the auto-completion (type: "pacman -S bash-completion" to install it).
[ -r /usr/share/bash-completion/bash_completion ] && . /usr/share/bash-completion/bash_completion
 
# Try to enable the "Command not found" hook ("pacman -S pkgfile" to install it).
[ -r /usr/share/doc/pkgfile/command-not-found.bash ] && . /usr/share/doc/pkgfile/command-not-found.bash
 
 
 
 
그리고 DIR_COLORS 라는 파일을 하나 만들어 다시 붙여넣는다.
 
nano /etc/DIR_COLORS
 
 
# Configuration file for the color ls utility
# This file goes in the /etc directory, and must be world readable.
# You can copy this file to .dir_colors in your $HOME directory to override
# the system defaults.
 
# COLOR needs one of these arguments: 'tty' colorizes output to ttys, but not
# pipes. 'all' adds color characters to all output. 'none' shuts colorization
# off.
COLOR all
 
# Extra command line options for ls go here.
# Basically these ones are:
#  -F = show '/' for dirs, '*' for executables, etc.
#  -T 0 = don't trust tab spacing when formatting ls output.
OPTIONS -F -T 0
 
# Below, there should be one TERM entry for each termtype that is colorizable
TERM linux
TERM console
TERM con132x25
TERM con132x30
TERM con132x43
TERM con132x60
TERM con80x25
TERM con80x28
TERM con80x30
TERM con80x43
TERM con80x50
TERM con80x60
TERM xterm
TERM vt100
TERM rxvt
TERM rxvt-256color
TERM rxvt-cygwin
TERM rxvt-cygwin-native
TERM rxvt-unicode
TERM rxvt-unicode-256color
TERM rxvt-unicode256
 
# EIGHTBIT, followed by '1' for on, '0' for off. (8-bit output)
EIGHTBIT 1
 
# Below are the color init strings for the basic file types. A color init
# string consists of one or more of the following numeric codes:
# Attribute codes: 
# 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
# Text color codes:
# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
# Background color codes:
# 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
NORMAL 00 # global default, although everything should be something.
FILE 00  # normal file
DIR 01;34  # directory
LINK 01;36  # symbolic link
FIFO 40;33 # pipe
SOCK 01;35 # socket
BLK 40;33;01 # block device driver
CHR 40;33;01  # character device driver
 
# This is for files with execute permission:
EXEC 01;32 
 
# List any file extensions like '.gz' or '.tar' that you would like ls
# to colorize below. Put the extension, a space, and the color init string.
# (and any comments you want to add after a '#')
.cmd 01;32 # executables (bright green)
.exe 01;32
.com 01;32
.btm 01;32
.bat 01;32
.tar 01;31 # archives or compressed (bright red)
.tgz 01;31
.arj 01;31
.taz 01;31
.lzh 01;31
.zip 01;31
.z   01;31
.Z   01;31
.gz  01;31
.jpg 01;35 # image formats
.gif 01;35
.bmp 01;35
.xbm 01;35
.xpm 01;35
.tif 01;35
 
 
 
만약 명령어가 존재하지 않는다거 하는 에러가 발생한다면 (이것 때문에 쉘이 망가져서 고생 좀 했음...)
아래를 실행해서 업데이트해준다.
 
 
pacman -Sy pkgfile
pkgfile --update
 
 
혹시 문제가 생기거나 한다면 일단 로그아웃 한 후에 다시 접속해서 복사해 두었던 원본 bash.bashrc 파일로 대체하고 다시 해본다.
(적용된 웰컴 메시지 화면 등을 보고 싶다면 로그아웃 후에 다시 접속해야 한다.)
 
팁으로 소스에도 있지만 로그인 시마다 어떤 명언같은 인용구가 랜덤으로 보이게 하고 싶다면, 
 
pacman -S fortune-mod
nano /etc/bash.bashrc
 
# [[ "$PS1" ]] && /usr/bin/fortune (이 부분을 찾아 밑에 넣어준다.)
[[ "$PS1" ]] && echo -e "\e[00;33m$(/usr/bin/fortune)\e[00m"
 
위와 같이 수정 후 로그아웃했다가 다시 로그인하면 브라운 색상으로 인용구가 매번 로그인할 때마다 랜덤으로 나온다.
맨 처음의 화면은 root로 로그인했을 때이고, 다른 사용자 계정으로 로그인하게 되면 웰컴 메시지는 동일하지만 쉘 모양이 root와는 다르다.
하지만 컬러는 적용되어 있어 ls 등을 했을 때 구분이 좀더 쉽게 된다.
 
※ 참고 : Windows putty에서 선이 제대로 보이지 않으면 translation -> UTF8로 변경하기 바란다.