[toc]
Kali Linux 自定義GDM3登錄背景圖片和LOGO
目標(biāo)
- 更改 gdm3 登錄頁面背景圖片
- 更改 gdm3 登錄頁面顯示LOGO
預(yù)備
- Kali Linux (操作系統(tǒng))
- GDM3 (顯示管理器)
- Gnome 桌面環(huán)境(可選)
- Python3 (腳本語言搪锣, 以root或sudo權(quán)限執(zhí)行)
更改 GDM3登錄頁面背景圖片
#!/usr/bin/env python3
# -coding:utf-8 -*-
# Desc: change gdm3 background
# Date: 2020-11-22
# Email: pydes@qq.com
# TODO: 導(dǎo)入相關(guān)模塊
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))
## 鎖屏對話界面樣式, 在這里設(shè)置顯示的背景圖片
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: 創(chuàng)建臨時存儲對應(yīng)目錄
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默認(rèn)樣式內(nèi)容进宝,寫入自定義的背景圖片路徑
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 服務(wù)
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())
- 按以上步驟執(zhí)行對應(yīng)的程序函數(shù)后,系統(tǒng)回退回到登錄界面蜒茄,此時顯示的登錄界面背景圖片則已經(jīng)變更成功荣茫。
- 但登錄界面上的 LOGO還是會顯示 Kali Linux的圖標(biāo)落剪。
更改GDM3登錄頁面LOGO
# 以管理員權(quán)限執(zhí)行以下步驟
# TODO: 創(chuàng)建 gmd 文件
sudo vim /etc/dconf/profile/gdm
## gdm 內(nèi)容 start
user-db:user
system-db:gdm
file-db:/usr/share/gdm/greeter-dconf-defaults
## gdm 內(nèi)容 end
# TODO: 創(chuàng)建 LOGO 配置文件
sudo mkdir -p /etc/dconf/db/gdm.d/
sudo vim /etc/dconf/db/gdm.d/01-logo
## 01-logo 內(nèi)容 start
[org/gnome/login-screen]
logo='/usr/share/pixmaps/logo/greeter-logo.png'
## 01-logo 內(nèi)容 end
# TODO: 更新變更內(nèi)容
dconf update