UOS SP1 自动部署之部署脚本-[不适用,只做参考]

注意

uos软件库已经标准化,以下软件已经不在适用,只能作为参考!!!

UOS SP1 自动部署之部署脚本

介绍

每次安装系统,都要进行一个个的进行重新设置部署,软件多了真的是非常的繁琐。好在linux系统可自定义性非常高。

脚本说明

  • 此脚本外加两个源,deepin的panda以及docker源。
  • 此脚本集合了一些我常用的软件进行自动化安装。
  • 由于uos的定制化比较高,提权之前需要进行一些设置,以开启权限。

执行脚本

sudo python3 uos_package_install.py

UOS需要开启权限

1.激活-试用期激活
设置-系统信息-激活-试用期激活-立即激活
2.登陆
设置-网络账户-登陆
3.获取root权限-开启开发者模式
设置-通用-开发者模式-进入开发者模式-在线激活-重启

uos_package_install.py

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import shutil

install_package = {
    # 编译
    'cmake': '',
    'gcc': '',
    'make': '',
    'pkg-config': '',
    'fakeroot': '',
    'patch': '',
    'apt-transport-https': '',
    'ca-certificates': '',
    'curl': '',
    'software-properties-common': '',
    'binutils': '',

    # 终端
    'ssh': '',
    'neofetch': '终端显示信息/screenfetch',
    'lolcat': '代码色彩',
    'cmatrix': '代码雨',
    'tmux': '分屏软件',
    'autojump': 'autojump插件',
    'git': 'github',
    'zsh': '',
    'vim': '',
    'proxychains-ng': '代理转发终端命令',
    'oh-my-zsh': '',
    'screenfetch': '终端显示信息-信息全-反应慢',
    'deepin-terminal': 'deepin透明终端',
    'locate': '文件搜索工具',

    # 字体
    'fonts-wqy-zenhei': '',
    'fonts-wqy-microhei': '',
    'ttf-dejavu': '',
    'noto-fonts': '',

    # 网络应用
    'cn.360.browser-stable': '360安全浏览器',
    'google-chrome-stable': '谷歌浏览器',
    'org.mozilla.firefox-en-us': '火狐浏览器',
    'deepin.com.foxmail': 'wine-foxmail邮件客户端',
    'deepin.com.thunderspeed': 'wine-迅雷极速版',
    'evolution': 'evolution',
    'thunderbird': '雷鸟邮件',
    'uget': 'bt下载器',
    'baidunetdisk': '百度网盘',
    'filezilla': '文件上传',
    'shadowsocks-qt5': '科学上网',
    # 'electron-ssr': '科学上网-不存在',
    'teamviewer': '远程软件',

    # 社交沟通
    # 'deepin.com.qq.im.light': 'wine-QQ轻聊版',
    # 'electronic-wechat': '微信(第三方)',
    # 'apps.com.wechat.web': '微信网页版',
    'linuxqq': 'QQ-linux',
    'deepin.com.qq.im': 'wine-QQ',
    'deepin.com.qq.office': 'wine-TIM',
    'deepin.com.wechat': 'wine-微信',

    # 音乐欣赏
    # 'pulseaudio': 'pulseaudio音量控制',
    'netease-cloud-music': '网易云音乐',
    'deepin-voice-recorder': '深度录音',

    # 音乐视频
    'deepin-movie': '深度影院',
    # 'obs-studio': 'OBS录屏',
    'smplayer': '播放器',
    'mpv': '播放器',

    # 图像图像
    'gimp': 'GNU 图像处理程序',
    'inkscape': '',
    # 'deepin-screenshot': '深度截图-被替代',
    'deepin-screen-recorder': '截图录屏',
    'deepin-picker': '深度取色器',

    # 办公学习
    # 'libreoffice': 'office',
    # 'openoffice': 'office',
    'wps-office ttf-wps-fonts': 'wps',
    'moeditor': 'markdown',
    'typora': 'markdown',
    'foxitreader': '福昕阅读器',
    'diffuse': '代码对比工具',
    'xmind': 'xmind思维导图',
    'youdao-dict': '有道词典',

    # 数据库
    'mongodb': '数据库',
    'redis': '数据库',
    'mariadb-server': 'mysql数据库',
    'mariadb-client': 'mysql数据库',
    'navicat': 'mysql数据库可视化',
    'redis-desktop-manager': 'redis可视化工具',
    'robo3t': 'mongodb数据库可视化',

    # 编程开发
    'wireshark': 'wireshark网络抓包',
    'charles': 'charles抓包',
    'postman': '网页调试工具',
    'sublime-text3': '编辑器',
    # 'code': 'Visual Studio Code',
    # 'com.visualstudio.code': 'Visual Studio Code IDE',
    # 'org.eclipse.java-ee': '',
    'docker-ce': 'docker-需要添加源',
    'openjdk-8-jdk': '',
    'pycharm-professional': 'python IDE',
    'putty': 'shell工具',

    # 系统管理
    # 'sogoupinyin': '搜狗输入法-与uos输入法冲突'
    # 'utools': 'utools搜索工具-不存在',
    'gufw': '防火墙',
    'deepin-calculator': '深度计算器',
    'deepin-boot-maker': '深度操作系统启动盘的制作工具',
    'deepin-clone': '深度备份还原工具',
    'p7zip': '7Z解压',
    'deepin.cn.360.yasuo': 'wine-360压缩-4.0',
    'deepin.cn.com.winrar': 'wine-winrar压缩工具',
    'bleachbit': '安装磁盘清理工具Bleachbit',
    'synaptic': '新立得软件包管理器',
    'deepin-topbar': 'topbar',
    'deepin-cloud-print': '深度云打印',
    'deepin-cloud-scanner': '深度云扫描',
    'ttf-deepin-opensymbol': '深度开源字体',
    'deepin-repair-tools': '深度系统修复工具',
    'deepin-graphics-driver-manager': '深度显卡驱动管理器',

    # 声卡
    # 'alsa-base': '',
    # 'alsa-oss': '',
    # 'alsa-tools': '',
    # 'alsa-utils': '',
    # 'alsa-tools-gui': '',
    # 'alsa-firmware-loaders': '',
}

enable_package = {
    'ssh': '',
    'mariadb': '',
}

update_package_info = {

}

failed_package_info = {
    # 手动安装
    # 虚拟化
    'virtualbox': 'vbox虚拟机-手动安装',
    'vmware-workstation': 'vmware-workstation 虚拟机-手动安装',

    # 编程开发
    # 'golang': 'golang 语言 and IDE',
}

home_user_dir = os.path.expanduser('~')


def install_package_cmd(command="sudo apt install -y "):
    print("================ 安装应用 ================")
    for package in install_package:
        new_cmd = command + package
        print(new_cmd)
        os.system(new_cmd)


def enable_package_cmd():
    print("================ 开机启动 ================")
    for package in enable_package:
        enable_cmd = "systemctl enable %s" % package
        start_cmd = "systemctl start %s" % package

        os.system(enable_cmd)
        os.system(start_cmd)


def failed_package_info_cmd():
    print("================ 无法安装的应用 ================")
    for package in failed_package_info:
        print('%s: %s' % (package, failed_package_info[package]))


def writer_file(path, content):
    with open(path, "w", encoding="utf-8") as f:
        f.write(content)


def set_apt_source():
    """
    更新源
    :return:
    """
    # 备份修改源
    apt_docker_file = "/etc/apt/sources.list.d/docker.list"
    apt_source_file = "/etc/apt/sources.list"
    apt_docker_file_content = """
deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/debian stretch stable
    """
    apt_source_file_content = """
## Generated by deepin-installer

deb [by-hash=force] https://packages.chinauos.cn/uos eagle main contrib non-free
#deb-src https://packages.chinauos.cn/uos eagle main contrib non-free

# Aliyun-deepin
#deb [by-hash=force] https://mirrors.aliyun.com/deepin lion main contrib non-free
deb [by-hash=force] https://mirrors.aliyun.com/deepin panda main contrib non-free
#deb-src https://mirrors.aliyun.com/deepin panda main contrib non-free
    """
    if os.path.exists(apt_docker_file):
        shutil.copy(apt_docker_file, apt_docker_file + '-bak')
    if os.path.exists(apt_source_file):
        shutil.copy(apt_source_file, apt_source_file + '-bak')
    writer_file(apt_docker_file, apt_docker_file_content)
    writer_file(apt_source_file, apt_source_file_content)

    # 更新源
    os.system('sudo apt update')

    # 添加docker密匙
    os.system('sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 7EA0A9C3F273FCD8')


def set_python():
    os.system('mkdir ~/.pip')
    pip_file = home_user_dir + '/.pip/pip.conf'
    pip_content = """
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com    
"""
    writer_file(pip_file, pip_content)

    os.system('pip3 install virtualenvwrapper')

def set_golang():
    os.system("wget https://dl.google.com/go/go1.14.linux-amd64.tar.gz")
    os.system("sudo tar -C /usr/local/lib -xzf go1.14.linux-amd64.tar.gz")


def set_oh_my_zsh():
    """
    设置 zsh
    :return:
    """
    oh_my_zsh_install = r"""
#!/bin/sh
#
# This script should be run via curl:
#   sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
# or wget:
#   sh -c "$(wget -qO- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
#
# As an alternative, you can first download the install script and run it afterwards:
#   wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh
#   sh install.sh
#
# You can tweak the install behavior by setting variables when running the script. For
# example, to change the path to the Oh My Zsh repository:
#   ZSH=~/.zsh sh install.sh
#
# Respects the following environment variables:
#   ZSH     - path to the Oh My Zsh repository folder (default: $HOME/.oh-my-zsh)
#   REPO    - name of the GitHub repo to install from (default: robbyrussell/oh-my-zsh)
#   REMOTE  - full remote URL of the git repo to install (default: GitHub via HTTPS)
#   BRANCH  - branch to check out immediately after install (default: master)
#
# Other options:
#   CHSH    - 'no' means the installer will not change the default shell (default: yes)
#   RUNZSH  - 'no' means the installer will not run zsh after the install (default: yes)
#
# You can also pass some arguments to the install script to set some these options:
#   --skip-chsh: has the same behavior as setting CHSH to 'no'
#   --unattended: sets both CHSH and RUNZSH to 'no'
# For example:
#   sh install.sh --unattended
#
set -e

# Default settings
ZSH=${ZSH:-~/.oh-my-zsh}
REPO=${REPO:-robbyrussell/oh-my-zsh}
REMOTE=${REMOTE:-https://github.com/${REPO}.git}
BRANCH=${BRANCH:-master}

# Other options
CHSH=${CHSH:-yes}
RUNZSH=${RUNZSH:-yes}


command_exists() {
	command -v "$@" >/dev/null 2>&1
}

error() {
	echo ${RED}"Error: $@"${RESET} >&2
}

setup_color() {
	# Only use colors if connected to a terminal
	if [ -t 1 ]; then
		RED=$(printf '\033[31m')
		GREEN=$(printf '\033[32m')
		YELLOW=$(printf '\033[33m')
		BLUE=$(printf '\033[34m')
		BOLD=$(printf '\033[1m')
		RESET=$(printf '\033[m')
	else
		RED=""
		GREEN=""
		YELLOW=""
		BLUE=""
		BOLD=""
		RESET=""
	fi
}

setup_ohmyzsh() {
	# Prevent the cloned repository from having insecure permissions. Failing to do
	# so causes compinit() calls to fail with "command not found: compdef" errors
	# for users with insecure umasks (e.g., "002", allowing group writability). Note
	# that this will be ignored under Cygwin by default, as Windows ACLs take
	# precedence over umasks except for filesystems mounted with option "noacl".
	umask g-w,o-w

	echo "${BLUE}Cloning Oh My Zsh...${RESET}"

	command_exists git || {
		error "git is not installed"
		exit 1
	}

	if [ "$OSTYPE" = cygwin ] && git --version | grep -q msysgit; then
		error "Windows/MSYS Git is not supported on Cygwin"
		error "Make sure the Cygwin git package is installed and is first on the \$PATH"
		exit 1
	fi

	git clone -c core.eol=lf -c core.autocrlf=false \
		-c fsck.zeroPaddedFilemode=ignore \
		-c fetch.fsck.zeroPaddedFilemode=ignore \
		-c receive.fsck.zeroPaddedFilemode=ignore \
		--depth=1 --branch "$BRANCH" "$REMOTE" "$ZSH" || {
		error "git clone of oh-my-zsh repo failed"
		exit 1
	}

	echo
}

setup_zshrc() {
	# Keep most recent old .zshrc at .zshrc.pre-oh-my-zsh, and older ones
	# with datestamp of installation that moved them aside, so we never actually
	# destroy a user's original zshrc
	echo "${BLUE}Looking for an existing zsh config...${RESET}"

	# Must use this exact name so uninstall.sh can find it
	OLD_ZSHRC=~/.zshrc.pre-oh-my-zsh
	if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then
		if [ -e "$OLD_ZSHRC" ]; then
			OLD_OLD_ZSHRC="${OLD_ZSHRC}-$(date +%Y-%m-%d_%H-%M-%S)"
			if [ -e "$OLD_OLD_ZSHRC" ]; then
				error "$OLD_OLD_ZSHRC exists. Can't back up ${OLD_ZSHRC}"
				error "re-run the installer again in a couple of seconds"
				exit 1
			fi
			mv "$OLD_ZSHRC" "${OLD_OLD_ZSHRC}"

			echo "${YELLOW}Found old ~/.zshrc.pre-oh-my-zsh." \
				"${GREEN}Backing up to ${OLD_OLD_ZSHRC}${RESET}"
		fi
		echo "${YELLOW}Found ~/.zshrc.${RESET} ${GREEN}Backing up to ${OLD_ZSHRC}${RESET}"
		mv ~/.zshrc "$OLD_ZSHRC"
	fi

	echo "${GREEN}Using the Oh My Zsh template file and adding it to ~/.zshrc.${RESET}"

	cp "$ZSH/templates/zshrc.zsh-template" ~/.zshrc
	sed "/^export ZSH=/ c\\
export ZSH=\"$ZSH\"
" ~/.zshrc > ~/.zshrc-omztemp
	mv -f ~/.zshrc-omztemp ~/.zshrc

	echo
}

setup_shell() {
	# Skip setup if the user wants or stdin is closed (not running interactively).
	if [ $CHSH = no ]; then
		return
	fi

	# If this user's login shell is already "zsh", do not attempt to switch.
	if [ "$(basename "$SHELL")" = "zsh" ]; then
		return
	fi

	# If this platform doesn't provide a "chsh" command, bail out.
	if ! command_exists chsh; then
		cat <<-EOF
			I can't change your shell automatically because this system does not have chsh.
			${BLUE}Please manually change your default shell to zsh${RESET}
		EOF
		return
	fi

	echo "${BLUE}Time to change your default shell to zsh:${RESET}"

	# Prompt for user choice on changing the default login shell
	printf "${YELLOW}Do you want to change your default shell to zsh? [Y/n]${RESET} "
	read opt
	case $opt in
		y*|Y*|"") echo "Changing the shell..." ;;
		n*|N*) echo "Shell change skipped."; return ;;
		*) echo "Invalid choice. Shell change skipped."; return ;;
	esac

	# Check if we're running on Termux
	case "$PREFIX" in
		*com.termux*) termux=true; zsh=zsh ;;
		*) termux=false ;;
	esac

	if [ "$termux" != true ]; then
		# Test for the right location of the "shells" file
		if [ -f /etc/shells ]; then
			shells_file=/etc/shells
		elif [ -f /usr/share/defaults/etc/shells ]; then # Solus OS
			shells_file=/usr/share/defaults/etc/shells
		else
			error "could not find /etc/shells file. Change your default shell manually."
			return
		fi

		# Get the path to the right zsh binary
		# 1. Use the most preceding one based on $PATH, then check that it's in the shells file
		# 2. If that fails, get a zsh path from the shells file, then check it actually exists
		if ! zsh=$(which zsh) || ! grep -qx "$zsh" "$shells_file"; then
			if ! zsh=$(grep '^/.*/zsh$' "$shells_file" | tail -1) || [ ! -f "$zsh" ]; then
				error "no zsh binary found or not present in '$shells_file'"
				error "change your default shell manually."
				return
			fi
		fi
	fi

	# We're going to change the default shell, so back up the current one
	if [ -n "$SHELL" ]; then
		echo $SHELL > ~/.shell.pre-oh-my-zsh
	else
		grep "^$USER:" /etc/passwd | awk -F: '{print $7}' > ~/.shell.pre-oh-my-zsh
	fi

	# Actually change the default shell to zsh
	if ! chsh -s "$zsh"; then
		error "chsh command unsuccessful. Change your default shell manually."
	else
		export SHELL="$zsh"
		echo "${GREEN}Shell successfully changed to '$zsh'.${RESET}"
	fi

	echo
}

main() {
	# Run as unattended if stdin is closed
	if [ ! -t 0 ]; then
		RUNZSH=no
		CHSH=no
	fi

	# Parse arguments
	while [ $# -gt 0 ]; do
		case $1 in
			--unattended) RUNZSH=no; CHSH=no ;;
			--skip-chsh) CHSH=no ;;
		esac
		shift
	done

	setup_color

	if ! command_exists zsh; then
		echo "${YELLOW}Zsh is not installed.${RESET} Please install zsh first."
		exit 1
	fi

	if [ -d "$ZSH" ]; then
		cat <<-EOF
			${YELLOW}You already have Oh My Zsh installed.${RESET}
			You'll need to remove '$ZSH' if you want to reinstall.
		EOF
		exit 1
	fi

	setup_ohmyzsh
	setup_zshrc
	setup_shell

	printf "$GREEN"
	cat <<-'EOF'
		         __                                     __
		  ____  / /_     ____ ___  __  __   ____  _____/ /_
		 / __ \/ __ \   / __ `__ \/ / / /  /_  / / ___/ __ \
		/ /_/ / / / /  / / / / / / /_/ /    / /_(__  ) / / /
		\____/_/ /_/  /_/ /_/ /_/\__, /    /___/____/_/ /_/
		                        /____/                       ....is now installed!


		Please look over the ~/.zshrc file to select plugins, themes, and options.

		p.s. Follow us on https://twitter.com/ohmyzsh

		p.p.s. Get stickers, shirts, and coffee mugs at https://shop.planetargon.com/collections/oh-my-zsh

	EOF
	printf "$RESET"

	if [ $RUNZSH = no ]; then
		echo "${YELLOW}Run zsh to try it out.${RESET}"
		exit
	fi

	exec zsh -l
}

main "$@"
"""

    zshrc = r"""
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

# Path to your oh-my-zsh installation.
export ZSH="$HOME/.oh-my-zsh"

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="robbyrussell"

# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in ~/.oh-my-zsh/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"

# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"

# Uncomment the following line to automatically update without prompting.
# DISABLE_UPDATE_PROMPT="true"

# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13

# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS=true

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"

# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"

# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load?
# Standard plugins can be found in ~/.oh-my-zsh/plugins/*
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git)

source $ZSH/oh-my-zsh.sh

# User configuration

# export MANPATH="/usr/local/man:$MANPATH"

# You may need to manually set your language environment
# export LANG=en_US.UTF-8

# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
#   export EDITOR='vim'
# else
#   export EDITOR='mvim'
# fi

# Compilation flags
# export ARCHFLAGS="-arch x86_64"

# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"


# virtualenvs
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_VIRTUALENV=~/.local/bin/virtualenv
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source $HOME/.local/bin/virtualenvwrapper.sh

# java
#export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
#export JRE_HOME=${JAVA_HOEM}/jre
#export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib

# GOROOT: GO的安装路径
export GOROOT=/usr/local/lib/go
# GOPATH: GO的工作路径,此处为自行创建的GoEnv目录,GoEnv下的src、pkg、bin也需自行创建
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin


#color{{{
autoload colors
colors

for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
eval _$color='%{$terminfo[bold]$fg[${(L)color}]%}'
eval $color='%{$fg[${(L)color}]%}'
(( count = $count + 1 ))
done
FINISH="%{$terminfo[sgr0]%}"
#}}}



#关于历史纪录的配置 {{{
#历史纪录条目数量
export HISTSIZE=10000
#注销后保存的历史纪录条目数量
export SAVEHIST=10000
#历史纪录文件
export HISTFILE=~/.zsh_history
#以附加的方式写入历史纪录
setopt INC_APPEND_HISTORY
#如果连续输入的命令相同,历史纪录中只保留一个
setopt HIST_IGNORE_DUPS
#为历史纪录中的命令添加时间戳
setopt EXTENDED_HISTORY

#启用 cd 命令的历史纪录,cd -[TAB]进入历史路径
setopt AUTO_PUSHD
#相同的历史路径只保留一个
setopt PUSHD_IGNORE_DUPS

#在命令前添加空格,不将此命令添加到纪录文件中
#setopt HIST_IGNORE_SPACE
#}}}

# 补全{{{
#彩色补全菜单
eval $(dircolors -b)
export ZLSCOLORS="${LS_COLORS}"
zmodload zsh/complist
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'


##行编辑高亮模式 {{{
# Ctrl+@ 设置标记,标记和光标点之间为 region
zle_highlight=(region:bg=magenta #选中区域
special:bold      #特殊字符
isearch:underline)#搜索时使用的关键字
#}}}


#命令别名 {{{
alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -i'
alias ls='ls -F --color=auto'
alias ll='ls -l --color=auto'
alias grep='grep --color=auto'
alias la='ls -a'
#}}}


#漂亮又实用的命令高亮界面
setopt extended_glob
TOKENS_FOLLOWED_BY_COMMANDS=('|' '||' ';' '&' '&&' 'sudo' 'do' 'time' 'strace')


recolor-cmd() {
region_highlight=()
colorize=true
start_pos=0
for arg in ${(z)BUFFER}; do
((start_pos+=${#BUFFER[$start_pos+1,-1]}-${#${BUFFER[$start_pos+1,-1]## #}}))
((end_pos=$start_pos+${#arg}))
if $colorize; then
colorize=false
res=$(LC_ALL=C builtin type $arg 2>/dev/null)
case $res in
*'reserved word'*)   style="fg=magenta,bold";;
*'alias for'*)       style="fg=cyan,bold";;
*'shell builtin'*)   style="fg=yellow,bold";;
*'shell function'*)  style='fg=green,bold';;
*"$arg is"*)
[[ $arg = 'sudo' ]] && style="fg=red,bold" || style="fg=blue,bold";;
*)                   style='none,bold';;
esac
region_highlight+=("$start_pos $end_pos $style")
fi
[[ ${${TOKENS_FOLLOWED_BY_COMMANDS[(r)${arg//|/\|}]}:+yes} = 'yes' ]] && colorize=true
start_pos=$end_pos
done
}
check-cmd-self-insert() { zle .self-insert && recolor-cmd }
check-cmd-backward-delete-char() { zle .backward-delete-char && recolor-cmd }

zle -N self-insert check-cmd-self-insert
zle -N backward-delete-char check-cmd-backward-delete-char
"""

    vimrc = r"""
" [Common Configration] 公共配置
" [ui beautification] 界面美化
syntax enable  " 开启代码高亮
set nu    " 开启行号
set ruler " 开启标尺
" set cursorline " 开启高亮光标所在行
set hlsearch " 开启搜索结果高亮显示
set incsearch " 开启搜索逐字符高亮
" [improve performance] 提示性能
set viminfo= " 关闭 viminfo (用于加快 vim 启动速度)
" [polyfill] 功能填补
set clipboard=unnamedplus " 开启系统剪贴板支持(需要手动编译最新版 vim 使其 +clipboard)
set backspace=indent,eol,start " 开启 Backspace 键支持(否则 Backspace 无法删除字符)
" [mouse support] 鼠标支持
set mouse=a " 开启鼠标支持
set mouse=v " vim文件间复制粘贴完美方案
set selection=inclusive " 指定在选择文本时光标所在位置也属于被选中的范围
set selectmode=mouse,key " 使鼠标和键盘都可以控制光标选择文本
" [tab] tab键
set ts=4 " 指定制表符(tab)等于的空格数
set softtabstop=4 " 开启软制表(如果这4个空格是用tab键打出来的删除会一起删除)
set shiftwidth=4 " 指定自动缩进时缩进4个空格
" [indent] 缩进
set smartindent " 开启智能缩进
set autoindent " 开启自动缩进
set cindent " 开启C缩进(对C、C++语言文件有效)
" [other] 其它配置
set backupcopy=yes " 开启备份时行为为覆盖
set cmdheight=1 " 设置命令行的高度为1
"""

    install_file = home_user_dir + "oh-my-zsh-install.sh"
    zshrc_file = home_user_dir + "/.zshrc"
    vimrc_file = home_user_dir + "/.vimrc"

    writer_file(install_file, oh_my_zsh_install)
    os.system('sudo chmod 755 ' + install_file)
    os.system("sh " + install_file)

    writer_file(zshrc_file, zshrc)
    writer_file(vimrc_file, vimrc)

    # 激活
    os.system('source .zshrc')
    os.system('source .vimrc')

    # 使用zsh替换bash
    os.system("chsh -s /bin/zsh")


def set_others():
    """
    其他设置
    :return:
    """
    # 双系统时间不一致
    os.system('sudo timedatectl set-local-rtc 1')

    # 终端打开文件
    os.system("sudo ln -s /usr/bin/xdg-open /usr/bin/open")

    # locate 当删除或添加文件后
    os.system("sudo updatedb")

    # 刷新字体缓存
    os.system("sudo fc-cache -fv")


def header():
    title = """
************************************************************
***                     Start                            ***
                    UOS SP1 自动部署

UOS需要开启权限:
1.激活-试用期激活
    设置-系统信息-激活-试用期激活-立即激活
2.登陆
    设置-网络账户-登陆
3.获取root权限-开启开发者模式
    设置-通用-开发者模式-进入开发者模式-在线激活-重启

***                     End                             ***
***********************************************************
"""
    print(title)


def main1():
    package_list = ""
    for package in install_package:
        package_list += package + " "
    print(package_list)


def main2():
    header()
    set_apt_source()
    set_python()
    set_golang()
    set_oh_my_zsh()
    set_others()

    install_package_cmd()
    enable_package_cmd()
    failed_package_info_cmd()


if __name__ == "__main__":
    main2()

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值