lnlidawei

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

os:  fedora39  --  配置和脚本

 

 

 

 

一、全局配置信息(/etc/basrc) 

 

  1、PS1配置(/etc/bashrc)

1 PS1="[${PROMPT_BRACKETS:+[}\[\e[${PROMPT_COLOR:-32}m\]\u@\h\[\e[0m\]:\[\e[${PROMPT_DIR_COLOR:-${PROMPT_COLOR:-32}}m\]\W${PROMPT_ERROR:+\[\e[0;31m\]${?#0}}\[\e[0m\]${PROMPT_BRACKETS:+]}]\$ "

 

 

  2、ALL(/etc/bashrc)

 

  1 [laohu@fedora:null]$ cat  /etc/bashrc 
  2 # /etc/bashrc
  3 
  4 # System wide functions and aliases
  5 # Environment stuff goes in /etc/profile
  6 
  7 # It's NOT a good idea to change this file unless you know what you
  8 # are doing. It's much better to create a custom.sh shell script in
  9 # /etc/profile.d/ to make custom changes to your environment, as this
 10 # will prevent the need for merging in future updates.
 11 
 12 # Prevent doublesourcing
 13 if [ -z "$BASHRCSOURCED" ]; then
 14   BASHRCSOURCED="Y"
 15 
 16   # are we an interactive shell?
 17   if [ "$PS1" ]; then
 18     if [ -z "$PROMPT_COMMAND" ]; then
 19       case $TERM in
 20       xterm*)
 21         if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
 22             PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
 23         else
 24             PROMPT_COMMAND='printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}"'
 25         fi
 26         ;;
 27       screen*)
 28         if [ -e /etc/sysconfig/bash-prompt-screen ]; then
 29             PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
 30         else
 31             PROMPT_COMMAND='printf "\033k%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}"'
 32         fi
 33         ;;
 34       *)
 35         [ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default
 36         ;;
 37       esac
 38     fi
 39     # Turn on parallel history
 40     shopt -s histappend
 41     # Turn on checkwinsize
 42     shopt -s checkwinsize
 43  #   [ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "
 44 #    [ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "
 45     [ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "
 46     # You might want to have e.g. tty in prompt (e.g. more virtual machines)
 47     # and console windows
 48     # If you want to do so, just add e.g.
 49     # if [ "$PS1" ]; then
 50     #   PS1="[\u@\h:\l \W]\\$ "
 51     # fi
 52     # to your custom modification shell script in /etc/profile.d/ directory
 53   fi
 54 
 55   if ! shopt -q login_shell ; then # We're not a login shell
 56     # Need to redefine pathmunge, it gets undefined at the end of /etc/profile
 57     pathmunge () {
 58         case ":${PATH}:" in
 59             *:"$1":*)
 60                 ;;
 61             *)
 62                 if [ "$2" = "after" ] ; then
 63                     PATH=$PATH:$1
 64                 else
 65                     PATH=$1:$PATH
 66                 fi
 67         esac
 68     }
 69 
 70     # Set default umask for non-login shell only if it is set to 0
 71     [ `umask` -eq 0 ] && umask 022
 72 
 73     SHELL=/bin/bash
 74     # Only display echos from profile.d scripts if we are no login shell
 75     # and interactive - otherwise just process them to set envvars
 76     for i in /etc/profile.d/*.sh; do
 77         if [ -r "$i" ]; then
 78             if [ "$PS1" ]; then
 79                 . "$i"
 80             else
 81                 . "$i" >/dev/null
 82             fi
 83         fi
 84     done
 85 
 86     unset i
 87     unset -f pathmunge
 88   fi
 89 
 90 fi
 91 # vim:ts=4:sw=4
 92 
 93 
 94 
 95 
 96 
 97 
 98 # 2023-11-21 by david
 99 #
100 
101 
102 #  PS1: /etc/profile.d/bash-color-prompt.sh
103 PS1="[${PROMPT_BRACKETS:+[}\[\e[${PROMPT_COLOR:-32}m\]\u@\h\[\e[0m\]:\[\e[${PROMPT_DIR_COLOR:-${PROMPT_COLOR:-32}}m\]\W${PROMPT_ERROR:+\[\e[0;31m\]${?#0}}\[\e[0m\]${PROMPT_BRACKETS:+]}]\$ "
104 
105 
106 [laohu@fedora:null]$ 
107 [laohu@fedora:null]$ 

 

 

 

 

二、fedora39 - 个人配置信息(~/.bashrc)

 1 [laohu@fedora:null]$ cat  ~/.bashrc 
 2 # .bashrc
 3 
 4 # Source global definitions
 5 if [ -f /etc/bashrc ]; then
 6     . /etc/bashrc
 7 fi
 8 
 9 # User specific environment
10 if ! [[ "$PATH" =~ "$HOME/.local/bin:$HOME/bin:" ]]; then
11     PATH="$HOME/.local/bin:$HOME/bin:$PATH"
12 fi
13 export PATH
14 
15 # Uncomment the following line if you don't like systemctl's auto-paging feature:
16 # export SYSTEMD_PAGER=
17 
18 # User specific aliases and functions
19 if [ -d ~/.bashrc.d ]; then
20     for rc in ~/.bashrc.d/*; do
21         if [ -f "$rc" ]; then
22             . "$rc"
23         fi
24     done
25 fi
26 unset rc
27 
28 
29 
30 
31 # 2023-11-13 by david
32 #
33 
34 
35 # alias
36 alias reboot='echo ROOT_MIMA |sudo -S reboot'
37 alias off='echo ROOT_MIMA |sudo -S shutdown -h now'
38 alias gpp='g++ -g -Wall -o'
39 
40 
41 #path
42 TOOLS='/home/laohu/fedora39/tools'
43 export PATH=${PATH}:${TOOLS}
44 
45 
46 #work directory
47 WORK_DIR='/home/laohu/fedora39/lidawei/tmp/null'
48 cd ${WORK_DIR}
49 
50 
51 [laohu@fedora:null]$ 
52 [laohu@fedora:null]$ 

 

 

 

 

三、基本脚本

 

  1、fedora39  --  系统更新(up 1 [laohu@fedora ~/user/tools]$ cat update

 2 #!/usr/bin/env bash
 3 
 4 
 5 #    os_version = fedora39
 6 #    filename = update
 7 
 8 
 9 echo
10 echo -- update --
11  echo PASSWD | sudo -S date "+%F %T";
12  echo PASSWD | sudo -S dnf clean all -y;
13  echo PASSWD | sudo -S dnf makecache -y;
14  echo PASSWD | sudo -S dnf upgrade -y;
15  echo PASSWD | sudo -S dnf update -y;
16  echo PASSWD | sudo -S dnf upgrade -y;
17  echo PASSWD | sudo -S dnf autoremove -y;
18 echo -- update end --
19 echo
20 
21 
22 [laohu@fedora ~/user/tools]$ 
23 [laohu@fedora ~/user/tools]$ 

 

  2、fedora39  --  移除旧内核(remove-old-kernel)

  1 [laohu@fedora:null]$ cat  ~/fedora39/tools/remove_old_kernel 
  2 #!/usr/bin/env bash
  3 
  4 
  5 
  6 
  7 # os_version = fedora39
  8 # file_name = remove old kernel
  9 
 10 
 11 
 12 
 13 # show all kernel files installed
 14 
 15 function list()
 16 {
 17 
 18 
 19         kf=$(rpm -qa | grep -E "^kernel*")
 20 
 21 
 22         ic=1
 23 
 24         echo
 25         echo '-- List All Kernel Files: start --'
 26         for kf in ${kf}
 27         do
 28                 echo '    SHOW_KERNEL_FILE_'${ic} :     ${kf}
 29                 ic=$((${ic}+1))
 30         done
 31         echo '-- List All Kernel Files: end --'
 32         echo
 33 
 34 
 35 }
 36 
 37 
 38 
 39 
 40 # delete old kernel, $1 is set to delete version
 41 # eg: set $1
 42 #       $1 = 6.0.14-300.fc37.x86_64
 43 
 44 function delete_old_kernel()
 45 {
 46 
 47         echo
 48         echo '-- remove old kernel files: starting --'
 49         echo '  OS->: Delete_Old_Kernel_Version :='     $1
 50         if [ $1 ]
 51         then
 52                 kd=$(rpm -qa | grep -E "^kernel*" | grep -E "^kernel.*$1.*")
 53         else
 54                 echo '  OS->: $1 is NULL, the program is end !'
 55                 exit 3
 56         fi
 57 
 58 
 59         di=1
 60 
 61         for df in ${kd}
 62         do
 63                 echo '    REMOVE_KERNEL_FILE_'${di} :   ${df}
 64                 echo ROOT_MIMA | sudo -S dnf -y remove ${df}
 65                 di=$((${di}+1))
 66         done
 67         echo '-- remove old kernel files: over  --'
 68         echo
 69 }
 70 
 71 
 72 
 73 
 74 function remove_old_kernel_help()
 75 {
 76         echo
 77         echo
 78         echo '  == remove-old-kernel help: start =='
 79         echo '  command                 parameter1              function'
 80         echo '  remove_old_kernel       null                    -- List all kernel files installed.'
 81         echo '  remove_old_kernel       kernel-old-version      -- Remove the kernel files matched with "kernel-old-version" .'
 82         echo
 83         echo '  == examples =='
 84         echo '  remove_old_kernel                               List all kernel files installed. '
 85         echo '  remove_old_kernel       6.0.14-300.fc37.x86_64  remove kernel files matched with "6.0.14-300.fc37.x86_64" .'
 86         echo '  == remove-old-kernel help: end =='
 87         echo
 88         echo
 89 }
 90 
 91 
 92 
 93 
 94 function run()
 95 {
 96 
 97         remove_old_kernel_help
 98 
 99         if [ -z $1 ]
100         then
101         #       echo '**TEST:           $1 is empty.'
102                 list
103         else
104         #       echo '**TEST:           $1 is not empty.'
105                 list
106                 delete_old_kernel $1
107                 list
108         fi
109 }
110 
111 
112 
113 
114 run $1
115 
116 [laohu@fedora:null]$ 
117 [laohu@fedora:null]$ 

 

 

 

四、参考文档

 

  1、os:  fedora38 系统更新脚本 - update - (echo 'PASSWORD' | sudo -S <command>)  https://www.cnblogs.com/lnlidawei/p/17623474.html

 

  2、os:linux移除旧内核的脚本(rockylinux9)  https://www.cnblogs.com/lnlidawei/p/17007191.html

 

posted on 2023-11-13 20:03  lnlidawei  阅读(226)  评论(0编辑  收藏  举报