Kali Linux 自定义GDM3登录背景图片和LOGO

[toc]

Kali Linux 自定义GDM3登录背景图片和LOGO

目标

    1. 更改 gdm3 登录页面背景图片
    1. 更改 gdm3 登录页面显示LOGO

预备

  • Kali Linux (操作系统)
  • GDM3 (显示管理器)
  • Gnome 桌面环境(可选)
  • Python3 (脚本语言, 以root或sudo权限执行)

更改 GDM3登录页面背景图片

#!/usr/bin/env python3
# -coding:utf-8 -*-
# Desc: change gdm3 background
# Date: 2020-11-22
# Email: pydes@qq.com

# TODO: 导入相关模块
import os 
import subprocess
import re 
import shutil

# TODO: 配置
## 脚本目录路径 
current_dir = os.path.abspath(os.curdir)
## gnome-shell-theme.gresource 路径 
gnome_shell_resouce_path = '''/usr/share/gnome-shell/gnome-shell-theme.gresource'''
## 临时存储主题文件目录
gnome_shell_workdir = os.path.join(current_dir, 'ShellTheme')
## 提取的主题文件目录
gnome_shell_theme_dir = os.path.join(gnome_shell_workdir, 'org/gnome/shell/theme/')
## 主题资源配置文件
gnome_shell_resource_xml = os.path.join(gnome_shell_workdir, 'org/gnome/shell/theme/gnome-shell-theme.gresource.xml')
## 主题样式配置文件
gnome_shell_theme_gnome_shell_css = os.path.join(gnome_shell_workdir, 'org/gnome/shell/theme/gnome-shell.css')
## 更改成的背景图片的路径
background_png_path = '''/home/Pydes/Pictures/wallpaper/background.png''' 
print('>_ Png Path: {}'.format(background_png_path))

## 锁屏对话界面样式, 在这里设置显示的背景图片
lockDialogGroupConent = '''lockDialogGroup {
    background: #2e3436 url(file://%s);
    background-repeat: repeat;
    background-color: #41494c;
}
''' %(background_png_path)

# TODO: 获取原GDM配置资源列表
def gresource_list():
    cmd = '''gresource list {}'''.format(gnome_shell_resouce_path)
    gresource_list = subprocess.getoutput(cmd).split() 
    return gresource_list

# TODO: 创建临时存储对应目录
def make_gresource_dir():
    gresource_dir_source_list = []
    get_gresource_list = gresource_list()
    for each_path in get_gresource_list:
        get_base_dir = os.path.dirname(each_path)
        get_base_dir_path = gnome_shell_workdir+get_base_dir
        gresource_dir_source_list.append(get_base_dir_path)
    get_gresource_dirs = set(gresource_dir_source_list)
    for each_dir in get_gresource_dirs:
        if os.path.exists(each_dir):
            pass 
        else:
            os.makedirs(each_dir)
    return get_gresource_dirs

# TOOD: 解压资源文件到临时存储目录
def extract_gst():
    get_gresource_list = gresource_list()
    for each_gresource in get_gresource_list:
        cmd = '''gresource extract %s %s > %s%s''' %(gnome_shell_resouce_path, each_gresource, gnome_shell_workdir,  each_gresource)
        print(cmd)
        run_cmd = subprocess.getoutput(cmd)
        print(run_cmd)
    return get_gresource_list

# TODO: 遍历解压出来的主题目录文件
def walk_theme_path():
    theme_path_list = []
    for root, dirs, files in os.walk(gnome_shell_theme_dir):
        for file in files:
            file_path = os.path.join(root, file)
            theme_path_list.append(file_path)
    return theme_path_list

# TODO: 生成新的资源配置文件 gnome-shell-theme.gresource.xml
def create_gnome_shell_theme_gresource_xml():
    get_file_list = walk_theme_path()
    format_file_name_string = ''
    for each_file_name in get_file_list:
        format_file_name_string = format_file_name_string+ '<file>'+each_file_name.replace(gnome_shell_theme_dir,'')+'</file>\n'
    gnome_shell_theme_gresource_xml_content = '''<?xml version="1.0" encoding="UTF-8"?><gresources>
  <gresource prefix="/org/gnome/shell/theme">'''+format_file_name_string+'''</gresource>
</gresources>'''
    with open(gnome_shell_resource_xml, 'w+') as gnome_shell_resource_xml_file:
        gnome_shell_resource_xml_file.write(gnome_shell_theme_gresource_xml_content)
    return (gnome_shell_resource_xml, gnome_shell_theme_gresource_xml_content)

# TODO: 更改原GDM默认样式内容,写入自定义的背景图片路径
def change_gnome_shell_css_content():
    gnome_shell_css_content = ''
    with open(gnome_shell_theme_gnome_shell_css, 'r') as gnome_shell_css_file:
        gnome_shell_css_content = gnome_shell_css_file.read()
    sub_string = r'(lockDialogGroup[\s+]\{[^}]*[?=\}])'
    result_string = re.sub(sub_string, lockDialogGroupConent,gnome_shell_css_content)
    with open(gnome_shell_theme_gnome_shell_css, 'w+') as gnome_shell_css_file:
        gnome_shell_css_file.write(result_string)
    return result_string

# TODO: 打包新的主题目文件
def compile_theme():
    cmd = '''glib-compile-resources gnome-shell-theme.gresource.xml'''
    os.chdir(os.path.join(gnome_shell_workdir, 'org/gnome/shell/theme'))
    run_cmd = subprocess.getoutput(cmd)
    return run_cmd

# TODO: 备份旧的主题文件并将新的文件存放来原主题文件路径下 
def copy_back_gresouce_xml():
    if os.path.isfile(gnome_shell_resouce_path):
        bak_path = gnome_shell_resouce_path+'_bak'
        move_action = shutil.move(gnome_shell_resouce_path, bak_path)
        print(move_action)
    new_gnome_shell_theme_gresource = os.path.join(gnome_shell_theme_dir, 'gnome-shell-theme.gresource')
    move_action = shutil.move(new_gnome_shell_theme_gresource, gnome_shell_resouce_path)
    return move_action

# TODO: 重新启动 GDM 服务
def restart_gdm_service():
    cmd = '''systemctl restart gdm'''
    run_cmd = subprocess.getoutput(cmd)
    return run_cmd


# TODO: Test
#print(gresource_list())
#print(make_gresource_dir())
#print(extract_gst())
#print(walk_theme_path())
#print(create_gnome_shell_theme_gresource_xml())
#print(change_gnome_shell_css_content())
#print(compile_theme())
#print(copy_back_gresouce_xml())
#print(restart_gdm_service())
  • 按以上步骤执行对应的程序函数后,系统回退回到登录界面,此时显示的登录界面背景图片则已经变更成功。
  • 但登录界面上的 LOGO还是会显示 Kali Linux的图标。

更改GDM3登录页面LOGO

# 以管理员权限执行以下步骤

# TODO: 创建 gmd 文件
sudo vim /etc/dconf/profile/gdm

## gdm 内容 start
user-db:user
system-db:gdm
file-db:/usr/share/gdm/greeter-dconf-defaults
## gdm 内容 end

# TODO: 创建 LOGO 配置文件
sudo mkdir -p /etc/dconf/db/gdm.d/
sudo vim /etc/dconf/db/gdm.d/01-logo

## 01-logo 内容  start 
[org/gnome/login-screen]
logo='/usr/share/pixmaps/logo/greeter-logo.png'
## 01-logo 内容  end

# TODO: 更新变更内容 
dconf update 
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容