Contents

基于OrangeOS搭建Arm-Debian-i3wm桌面环境

基于OrangeOS搭建Arm-Debian-i3wm桌面环境

注意事项

在执行本教程之前,必须确保已满足以下要求:

  • 用户具有 sudo 权限

  • 网络已连接

  • apt 软件源可用,作者通常使用清华大学开源软件镜像站

    mkdir -p ~/armbianI3wmTheme/bak/etc/apt/sources.list.d/ && \
    sudo cp /etc/apt/sources.list.d/armbian.list ~/armbianI3wmTheme/bak/etc/apt/sources.list.d/ && \
    sudo sed -i.bak 's#http://apt.armbian.com#https://mirrors.tuna.tsinghua.edu.cn/armbian#g' /etc/apt/sources.list.d/armbian.list
    
  • 更新软件源,由于每台设备的情况不同,建议先执行以下命令更新软件源,完成后再执行本教程命令

    sudo apt update
    
  • 建议大家多看官方的i3 用户指南,遇到问题通常都能找到答案

声明与介绍

文章声明

本教程基于以下两篇文章重新编写,并替换了部分软件和配置(如:使用eww替换polybar),共分为三部分:

第一部分:过程讲解。逐步介绍桌面环境搭建的相关工具及配置,与桌面环境无关的工具仅提供安装使用的命令

第二部分:参考文献。有些文章内容适用,有些文章提供了思路但内容不适用

第三部分:脚本代码。可直接拷贝至.sh 文件执行

环境介绍

首先,笔者的观点是:一个好看的桌面,最重要的是有一张好看的壁纸,其他都是次要。

其次,次要的部分是依靠多个软件配置而成。

因此,桌面环境搭建就是一个寻找壁纸和软件配置编写的过程。

如果想得到自己期望的效果,必然要花费时间;即便直接使用别人的主题,也需要花时间了解具体的配置,适配过程中多少都会遇到点困难。

最后,除了基本的环境依赖,笔者将软件分为核心应用、日常应用,本教程涉及软件包括:

  • 环境依赖

    • X 窗口系统:xorg、xserver-xorg
    • 显示管理器:lightdm
    • 窗口管理器:i3
    • i3 配套工具:
    • 状态栏:i3status
    • 锁屏:i3lock-fancy
    • 中文字体:fonts-noto-cjk、fonts-wqy-microhei、fonts-wqy-zenhei、xfonts-wqy
  • 核心应用

    • 电源管理器:xfce4-power-manager
    • 网络连接:network-manager
    • 合成管理器/窗口合成器/特效管理器:picom【推荐】 / compton【picom 前身】
    • 系统菜单栏:polybar
    • 程序启动器:rofi
    • 壁纸管理器:feh
    • Icon Theme:papirus-icon-theme
  • 日常应用

    • 下载工具:wget、curl
    • 解压工具:zip、unzip
    • 字体管理:fontconfig、locales
    • 虚拟终端:xfce4-terminal
    • 文件管理器:
    • 图形:thunar
    • 终端:MidnightCommand(简称 mc)
    • 文本编辑器:
      • 图形:vscode(执行命令:code)
      • 终端:vim / neovim(执行命令:nvim) / spacevim
    • 网页浏览器:
      • 图形:firefox-esr
      • 终端:w3m
    • 屏幕截图:scrot
    • 输入法:
      • fcitx 核心组件:dbus-x11、fcitx、fcitx-sunpinyin、fcitx-table-wubi、im-config、fcitx-config-gtk、fcitx-module-dbus
      • fcitx 适配组件:fcitx-frontend-gtk2、fcitx-frontend-gtk3、fcitx-frontend-qt5
      • fcitx 界面 UI:fcitx-ui-classic
    • pdf 阅读器:zathura
    • 图片格式转换:parallel(PNG/JPG)

脚本代码

# !/bin/bash

# ==============================
# 请勿使用 Windows 下的记事本拷贝
# ==============================

clear

if [ 1 ]
then
sudo apt update

clear
echo "=============================="
echo "基于 OrangeOS 搭建 Arm-Debian-i3wm 桌面环境"
echo "=============================="
echo "桌面搭建即将开始"
echo "请耐心等待"
echo "=============================="
sleep 3s

# ==============================

# 创建配置文件夹

# ==============================

clear

# 存放桌面壁纸

mkdir -p /home/$USER/i3wm/bg

# 存放特殊字体

mkdir -p /home/$USER/i3wm/font

# 存放各个应用配置文件

mkdir -p /home/$USER/.config/polybar
mkdir -p /home/$USER/.config/picom
mkdir -p /home/$USER/.config/thunar

clear
echo "=============================="
echo "已完成 - 创建配置文件夹"
echo "=============================="
sleep 3s

# ==============================

# 安装环境依赖

# ==============================

clear

sudo apt install -y \
xorg \
xserver-xorg \
lightdm \
i3 \
i3status \
i3lock-fancy

clear
echo "=============================="
echo "已完成 - 安装环境依赖"
echo "=============================="
sleep 3s

# ==============================

# 安装核心应用

# ==============================

clear

sudo apt install -y \
xfce4-power-manager \
network-manager \
polybar \
picom \
rofi \
feh \
papirus-icon-theme

clear
echo "=============================="
echo "已完成 - 安装核心应用"
echo "=============================="
sleep 3s

# ==============================

# 安装日常应用

# ==============================

# ------------------------------

# 安装日常应用 - 中文字体

# ------------------------------

clear

sudo apt install -y fonts-noto-cjk fonts-wqy-microhei fonts-wqy-zenhei xfonts-wqy

# ------------------------------

# 安装日常应用 - 中文字体 - 设置地域(locale)

# ------------------------------

if [[$(cat /etc/locale.gen) =~ $'# zh_CN.UTF-8 UTF-8']]
then
sudo sed -i 's/# zh_CN.UTF-8 UTF-8/zh_CN.UTF-8 UTF-8/g' /etc/locale.gen
echo "OK, modified the /etc/locale.gen"
else
echo "Do not need modified the /etc/locale.gen"
fi

# ------------------------------

# 安装日常应用 - 中文字体 - 修改地域配置文件

# ------------------------------

if [[$(cat /etc/default/locale) =~ $'LANG=\"zh_CN.UTF-8\"
LANGUAGE=\"zh_CN:zh\"
LC_NUMERIC=\"zh_CN\"
LC_TIME=\"zh_CN\"
LC_MONETARY=\"zh_CN\"
LC_PAPER=\"zh_CN\"
LC_NAME=\"zh_CN\"
LC_ADDRESS=\"zh_CN\"
LC_TELEPHONE=\"zh_CN\"
LC_MEASUREMENT=\"zh_CN\"
LC_IDENTIFICATION=\"zh_CN\"
LC_ALL=\"zh_CN.UTF-8\"']]
then
echo "Do not need modified the /etc/default/locale"
else
sudo bash -c "cat << EOF > /etc/default/locale
LANG=\"zh_CN.UTF-8\"
LANGUAGE=\"zh_CN:zh\"
LC_NUMERIC=\"zh_CN\"
LC_TIME=\"zh_CN\"
LC_MONETARY=\"zh_CN\"
LC_PAPER=\"zh_CN\"
LC_NAME=\"zh_CN\"
LC_ADDRESS=\"zh_CN\"
LC_TELEPHONE=\"zh_CN\"
LC_MEASUREMENT=\"zh_CN\"
LC_IDENTIFICATION=\"zh_CN\"
LC_ALL=\"zh_CN.UTF-8\"
EOF"
echo "OK, modified the /etc/default/locale"
fi

# ------------------------------

# 安装日常应用 - 中文字体 - 修改环境配置文件

# ------------------------------

if [[$(cat /etc/environment) =~ $'LANG=\"zh_CN.UTF-8\"
LANGUAGE=\"zh_CN:zh\"
LC_NUMERIC=\"zh_CN\"
LC_TIME=\"zh_CN\"
LC_MONETARY=\"zh_CN\"
LC_PAPER=\"zh_CN\"
LC_NAME=\"zh_CN\"
LC_ADDRESS=\"zh_CN\"
LC_TELEPHONE=\"zh_CN\"
LC_MEASUREMENT=\"zh_CN\"
LC_IDENTIFICATION=\"zh_CN\"
LC_ALL=\"zh_CN.UTF-8\"']]
then
echo "Do not need modified the /etc/environment"
else
sudo bash -c "cat << EOF >> /etc/environment
LANG=\"zh_CN.UTF-8\"
LANGUAGE=\"zh_CN:zh\"
LC_NUMERIC=\"zh_CN\"
LC_TIME=\"zh_CN\"
LC_MONETARY=\"zh_CN\"
LC_PAPER=\"zh_CN\"
LC_NAME=\"zh_CN\"
LC_ADDRESS=\"zh_CN\"
LC_TELEPHONE=\"zh_CN\"
LC_MEASUREMENT=\"zh_CN\"
LC_IDENTIFICATION=\"zh_CN\"
LC_ALL=\"zh_CN.UTF-8\"
EOF"
echo "OK, modified the /etc/environment"
fi

clear
echo "=============================="
echo "已完成 - 安装日常应用 - 中文字体"
echo "=============================="
sleep 3s

# ------------------------------

# 安装日常应用

# - 下载工具:wget

# - 解压工具:zip、unzip

# - 字体管理:fontconfig、locales

# - 虚拟终端:xfce4-terminal

# - 文件管理器:thunar

# - 文本编辑器:vim

# - 网页浏览器:firefox-esr

# - 屏幕截图:scrot

# - pdf 阅读器:zathura

# - 图片格式转换:parallel

# ------------------------------

clear

if [[$(apt list wget | grep now)]]
then
sleep 0s
else
sudo apt install -y wget
fi

if [[$(apt list zip | grep now)]]
then
sleep 0s
else
sudo apt install -y zip
fi

if [[$(apt list unzip | grep now)]]
then
sleep 0s
else
sudo apt install -y unzip
fi

if [[$(apt list fontconfig | grep now)]]
then
sleep 0s
else
sudo apt install -y fontconfig
fi

if [[$(apt list locales | grep now)]]
then
sleep 0s
else
sudo apt install -y locales
fi

if [[$(apt list xfce4-terminal | grep now)]]
then
sleep 0s
else
sudo apt install -y xfce4-terminal
fi

if [[$(apt list thunar | grep now)]]
then
sleep 0s
else
sudo apt install -y thunar
fi

if [[$(apt list vim | grep now)]]
then
sleep 0s
else
sudo apt install -y vim
fi

if [[$(apt list firefox-esr | grep now)]]
then
sleep 0s
else
sudo apt install -y firefox-esr
fi

if [[$(apt list scrot | grep now)]]
then
sleep 0s
else
sudo apt install -y scrot
fi

if [[$(apt list zathura | grep now)]]
then
sleep 0s
else
sudo apt install -y zathura
fi

if [[$(apt list parallel | grep now)]]
then
sleep 0s
else
sudo apt install -y parallel
fi

clear
echo "=============================="
echo "已完成 - 安装日常应用"
echo " - 下载工具:wget"
echo " - 解压工具:zip、unzip"
echo " - 字体管理:fontconfig、locales"
echo " - 虚拟终端:xfce4-terminal"
echo " - 文件管理器:thunar"
echo " - 文本编辑器:vim"
echo " - 网页浏览器:firefox-esr"
echo " - 屏幕截图:scrot"
echo " - pdf 阅读器:zathura"
echo "=============================="
sleep 3s

# ------------------------------

# 安装日常应用 - 输入法

# ------------------------------

clear

if [[$(apt list fcitx | grep now)]]
then
sleep 0s
else
sudo apt remove ibus\*
sudo apt install -y \
dbus-x11 fcitx fcitx-sunpinyin fcitx-table-wubi im-config fcitx-config-gtk fcitx-module-dbus \
fcitx-frontend-gtk2 fcitx-frontend-gtk3 fcitx-frontend-qt5 \
fcitx-ui-classic
fi

sudo im-config -n fcitx

if [[$(cat ~/.profile) =~ $"export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export XMODIFIERS=@im=fcitx
export DefaultIMModule=fcitx
fcitx-autostart &>/dev/null"]]
then
echo "Do not need modified the ~/.profile"
else
bash -c "cat << EOF >> ~/.profile
export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export XMODIFIERS=@im=fcitx
export DefaultIMModule=fcitx
fcitx-autostart &>/dev/null
EOF"
echo "OK, modified the ~/.profile"
fi

source ~/.profile

if [[$(cat ~/.xprofile) =~ $"export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export XMODIFIERS=@im=fcitx
export DefaultIMModule=fcitx
fcitx-autostart &>/dev/null"]]
then
echo "Do not need modified the ~/.xprofile"
else
bash -c "cat << EOF >> ~/.xprofile
export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export XMODIFIERS=@im=fcitx
export DefaultIMModule=fcitx
fcitx-autostart &>/dev/null
EOF"
echo "OK, modified the ~/.xprofile"
fi

source ~/.xprofile

if [[$(cat ~/.bashrc) =~ $"export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export XMODIFIERS=@im=fcitx
export DefaultIMModule=fcitx
fcitx-autostart &>/dev/null"]]
then
echo "Do not need modified the ~/.bashrc"
else
bash -c "cat << EOF >> ~/.bashrc
export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export XMODIFIERS=@im=fcitx
export DefaultIMModule=fcitx
fcitx-autostart &>/dev/null
EOF"
echo "OK, modified the ~/.bashrc"
fi

source ~/.bashrc

clear
echo "=============================="
echo "已完成 - 安装日常应用 - 输入法"
echo "=============================="
sleep 3s

# ==============================

# 配置环境依赖

# ==============================

clear

# ------------------------------

# 配置 i3

# ------------------------------

if [[$(cat /home/$USER/.config/i3/config) =~ $'set $mod1 Mod1']]
then
echo "Do not need modified the /home/$USER/.config/i3/config"
else
sed -i 's/set $mod Mod4/set $mod Mod4\nset $mod1 Mod1/g' /home/$USER/.config/i3/config
echo "OK, modified the /home/$USER/.config/i3/config"
fi

# ------------------------------

# 配置 i3lock-fancy

# ------------------------------

if [[! -f /home/$USER/i3wm/bg/bg-lock.png]]
then
convert /home/$USER/i3wm/bg/bg2.jpg /home/$USER/i3wm/bg/bg-lock.png
fi

cat << EOF > /home/$USER/i3wm/i3lock-fancy.sh
feh -F /home/$USER/i3wm/bg/bg-lock.png &
sleep 0.5
i3lock-fancy -g && \
kill -9 \`ps -ef | grep feh -F | awk '{print \$2}'\`
EOF

if [[$(cat /home/$USER/.config/i3/config) =~ $'设置i3wm快捷键 - i3lock-fancy']]
then
echo "Do not need modified the /home/$USER/.config/i3/config"
else
cat << EOF >> /home/$USER/.config/i3/config

# ==============================

# 设置 i3wm 快捷键 - i3lock-fancy

# ==============================

bindsym \$mod+\$mod1+l exec sh /home/$USER/i3wm/i3lock-fancy.sh
EOF
echo "OK, modified the /home/$USER/.config/i3/config"
fi

# ==============================

# 配置核心应用

# ==============================

clear

# ------------------------------

# 配置 polybar

# ------------------------------

cat << EOF > /home/$USER/.config/polybar/config

EOF

# ------------------------------

# 配置 picom

# ------------------------------

cat << EOF > /home/$USER/.config/picom/picom.conf
active-opacity = 1.0;
inactive-opacity = 0.75;
frame-opacity = 1;
inactive-opacity-override = false;
opacity-rule = [
"100:class_g *?= 'thunar'",
"100:class_g *?= 'feh'",
"100:class_g *?= 'i3lock-fancy'",
"100:class_g *?= 'i3lock'",
"90:class_g *?= 'rofi'"
];
EOF

if [[$(cat /home/$USER/.config/i3/config) =~ $'设置随i3wm启动的应用 - picom']]
then
echo "Do not need modified the /home/$USER/.config/i3/config"
else
cat << EOF >> /home/$USER/.config/i3/config

# ==============================

# 设置随 i3wm 启动的应用 - picom

# ==============================

exec --no-startup-id picom -b --config /home/\$USER/.config/picom/picom.conf --experimental-backends
EOF
echo "OK, modified the /home/$USER/.config/i3/config"
fi

# ------------------------------

# 配置 rofi

# ------------------------------

tmpValue=0

while [[! -d /tmp/i3-dotfiles-master/rofi && $tmpValue != 5]]
do
while [[! -f /tmp/master.zip]]
do
cd /tmp
wget <https://github.com/ayamir/i3-dotfiles/archive/refs/heads/master.zip>

        ((tmpValue++)) # tmpValue=$(expr $tmpValue + 1)

        if [[ ! -f /tmp/master.zip && $tmpValue == 5 ]]
        then
            read -p "文件下载失败,是否重新下载:[Y/N]" tmpUserValue
            case $tmpUserValue in
            Y | y)
                tmpValue=0
                ;;
            *)
                tmpValue=5
                ;;
            esac
        fi
    done

    while [[ ! -d /tmp/i3-dotfiles-master/rofi ]]
    do
        unzip /tmp/master.zip
    done

done

unset tmpValue
unset tmpUserValue

cp -r /tmp/i3-dotfiles-master/rofi/ ~/.config/rofi/

if [[$(cat /home/$USER/.config/i3/config) =~ $'设置i3wm快捷键 - rofi']]
then
echo "Do not need modified the /home/$USER/.config/i3/config"
else
cat << EOF >> /home/$USER/.config/i3/config

# ==============================

# 设置 i3wm 快捷键 - rofi

# ==============================

bindsym \$mod+\$mod1+d exec rofi -show drun -show window -show run -show ssh
EOF
echo "OK, modified the /home/$USER/.config/i3/config"
fi

# ------------------------------

# 配置 feh

# ------------------------------

if [[-f /home/$USER/i3wm/bg/bg1.jpg]]
then
sleep 0s
else
cd /home/$USER/i3wm/bg/ && wget http://i0.hdslb.com/bfs/album/fbf6e747fc40438ab5472c1e017f97dba558d26d.png && mv fbf6e747fc40438ab5472c1e017f97dba558d26d.png bg1.jpg

# curl -o /home/$USER/i3wm/bg/bg1.jpg <https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fi0.hdslb.com%2Fbfs%2Falbum%2Ffbf6e747fc40438ab5472c1e017f97dba558d26d.png&refer=http%3A%2F%2Fi0.hdslb.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1673364442&t=85e8655769742de4b10fd8ebf74df3e7>

fi

if [[-f /home/$USER/i3wm/bg/bg2.jpg]]
then
sleep 0s
else
cd /home/$USER/i3wm/bg/ && wget https://tva1.sinaimg.cn/large/005NWMakgy1gs795kdk69j62yo1o0kjq02.jpg && mv 005NWMakgy1gs795kdk69j62yo1o0kjq02.jpg bg2.jpg

# curl -o /home/$USER/i3wm/bg/bg2.jpg <https://tva1.sinaimg.cn/large/005NWMakgy1gs795kdk69j62yo1o0kjq02.jpg>

fi

if [[-f /home/$USER/i3wm/bg/bg.jpg]]
then
sleep 0s
else
cp /home/$USER/i3wm/bg/bg1.jpg /home/$USER/i3wm/bg/bg.jpg
fi

if [[$(cat /home/$USER/.config/i3/config) =~ $'设置随i3wm启动的应用 - feh']]
then
echo "Do not need modified the /home/$USER/.config/i3/config"
else
cat << EOF >> /home/$USER/.config/i3/config

# ==============================

# 设置随 i3wm 启动的应用 - feh

# ==============================

exec --no-startup-id feh --randomize --bg-fill /home/\$USER/i3wm/bg/bg.jpg
EOF
echo "OK, modified the /home/$USER/.config/i3/config"
fi

# ------------------------------

# 配置 xfce4-terminal

# ------------------------------

if [[$(cat /home/$USER/.config/i3/config) =~ $'bindsym $mod+Return exec xfce4-terminal']]
then
echo "Do not need modified the /home/$USER/.config/i3/config"
else
sed -i 's/bindsym $mod+Return exec i3-sensible-terminal/bindsym $mod+Return exec xfce4-terminal/g' /home/$USER/.config/i3/config
echo "OK, modified the /home/$USER/.config/i3/config"
fi

cat << EOF > /home/$USER/.config/xfce4/terminal/terminalrc
[Configuration]
MiscAlwaysShowTabs=FALSE
MiscBell=FALSE
MiscBellUrgent=FALSE
MiscBordersDefault=TRUE
MiscCursorBlinks=FALSE
MiscCursorShape=TERMINAL_CURSOR_SHAPE_BLOCK
MiscDefaultGeometry=80x24
MiscInheritGeometry=FALSE
MiscMenubarDefault=FALSE
MiscMouseAutohide=FALSE
MiscMouseWheelZoom=TRUE
MiscToolbarDefault=FALSE
MiscConfirmClose=TRUE
MiscCycleTabs=TRUE
MiscTabCloseButtons=TRUE
MiscTabCloseMiddleClick=TRUE
MiscTabPosition=GTK_POS_TOP
MiscHighlightUrls=TRUE
MiscMiddleClickOpensUri=FALSE
MiscCopyOnSelect=TRUE
MiscShowRelaunchDialog=TRUE
MiscRewrapOnResize=TRUE
MiscUseShiftArrowsToScroll=FALSE
MiscSlimTabs=FALSE
MiscNewTabAdjacent=FALSE
ScrollingBar=TERMINAL_SCROLLBAR_NONE
BackgroundMode=TERMINAL_BACKGROUND_TRANSPARENT
BackgroundDarkness=0.800000
ColorPalette=rgb(79,79,79);rgb(238,68,68);rgb(68,221,136);rgb(254,221,68);rgb(0,170,255);rgb(238,51,187);rgb(68,205,205);rgb(199,199,199);rgb(111,111,111);rgb(255,102,102);rgb(68,238,136);rgb(253,253,85);rgb(0,204,255);rgb(238,102,238);rgb(51,238,238);rgb(247,247,247)
ColorBackground=#0f0f0f0f0f0f
ColorForeground=#f7f7f7f7f7f7
ColorSelectionUseDefault=FALSE
ColorSelection=#4f4f4f4f4f4f
ColorSelectionBackground=#fefedddd4444
ColorCursorUseDefault=FALSE
ColorCursor=#4444eeee8888
TabActivityColor=#0000aaa9ffff
ColorBoldUseDefault=FALSE
ColorBold=#fefedddd4444
ColorCursorForeground=#000000000000
EOF

# ------------------------------

# 已完成 - 配置核心应用

# ------------------------------

clear
echo "=============================="
echo "已完成 - 配置核心应用"
echo "=============================="
sleep 3s

# ==============================

# 结束语

# ==============================

clear
echo "=============================="
echo "桌面搭建已完成"
echo "使用愉快!"
echo "=============================="
sleep 3s

fi