├── .gitignore ├── README.md ├── py ├── pyproject.toml └── README.md ├── starship.win.toml ├── LICENSE ├── modules ├── web.sh ├── system.sh └── config.sh ├── config ├── starship.toml └── .zshrc ├── bash ├── sync_k3s.sh ├── sync_wsl.sh ├── install_zsh.sh ├── .zshrc ├── k3s.zshrc └── init_wsl.sh ├── starship.toml ├── dokploy └── install.sh ├── run.sh ├── helper.sh ├── zsh └── zimfw-install.sh └── coolify └── install.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .history 2 | *.log 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Configurations 2 | 3 | 1. [`pyproject.toml`](/py/): [yapf](https://github.com/google/yapf) configuration, python formatter provider 4 | -------------------------------------------------------------------------------- /py/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.yapfignore] 2 | ignore_patterns = [ 3 | "temp/**/*.py", 4 | "temp2/*.py" 5 | ] 6 | 7 | # https://github.com/google/yapf/blob/main/yapf/yapflib/style.py#L418 8 | [tool.yapf] 9 | based_on_style = "pep8" 10 | spaces_before_comment = 2 11 | split_before_logical_operator = true 12 | column_limit = 120 13 | -------------------------------------------------------------------------------- /starship.win.toml: -------------------------------------------------------------------------------- 1 | # 设置配置范例,开启编辑器的自动补全 2 | "$schema" = 'https://starship.rs/config-schema.json' 3 | 4 | [cmd_duration] 5 | show_milliseconds = true 6 | show_notifications = true 7 | 8 | [localip] 9 | ssh_only = false 10 | format = "[IP:$localipv4](bold red) " 11 | disabled = false 12 | 13 | [memory_usage] 14 | disabled = false 15 | threshold = -1 16 | format = "[${ram} ${ram_pct}]($style) " 17 | style = "bold dimmed green" 18 | 19 | [time] 20 | disabled = false 21 | format = '[\[ $time \]]($style) ' 22 | time_format = "%T" 23 | utc_time_offset = "+8" 24 | style = "bold dimmed blue" 25 | -------------------------------------------------------------------------------- /py/README.md: -------------------------------------------------------------------------------- 1 | # Python 2 | 3 | ## **pyproject.toml** 4 | 5 | + Install [yapf](https://github.com/google/yapf): 6 | 7 | ```bash 8 | pip install yapf 9 | ``` 10 | 11 | + Install `pyproject.toml` deps module `toml`: 12 | 13 | ```bash 14 | pip install toml 15 | ``` 16 | 17 | + Set formatting provider in `settings.json`: 18 | 19 | ```json 20 | { 21 | "python.formatting.provider": "yapf", 22 | "[python]": { 23 | "editor.formatOnSave": true 24 | }, 25 | } 26 | ``` 27 | 28 | + Clone `pyproject.toml`: 29 | 30 | ```bash 31 | npx degit aliuq/config/py/pyproject.toml pyproject.toml 32 | ``` 33 | 34 | + See more in [`style.py`](https://github.com/google/yapf/blob/main/yapf/yapflib/style.py) 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 liuq 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /modules/web.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # 个人开发环境管理脚本 - 前端模块 4 | # 5 | # - 目前仅支持 Ubuntu apt 安装 6 | # 7 | # sh <(curl -sL https://raw.githubusercontent.com/aliuq/config/refs/heads/master/run.sh) 8 | # 9 | set -e 10 | 11 | if ! command -v run >/dev/null 2>&1; then 12 | . /dev/stdin < 当前终端不是 zsh,请在 zsh 环境下执行" 25 | return 26 | fi 27 | 28 | if $dry_run; then 29 | run "commands_valid curl" 30 | else 31 | commands_valid curl 32 | fi 33 | echo 34 | version=$(read_input "请输入 nvm 版本(默认最新版 master/v0.40.1): " "master") 35 | echo 36 | run "curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/$version/install.sh | bash" 37 | 38 | echo 39 | green "安装完成,请执行 $(cyan "source ~/.zshrc") 使配置生效" 40 | echo 41 | info " - 安装最新的 LTS 版本: $(cyan "nvm install --lts")" 42 | info " - 查看所有可安装的版本: $(cyan "nvm ls-remote")" 43 | echo 44 | info " - 如果遇到错误\n" 45 | info " 1. $(red "mkdir: cannot create directory '~/.nvm/alias': Permission denied")\n" 46 | info " 请尝试为 ~/.nvm 目录添加写权限 $(cyan "sudo chmod 777 -R ~/.nvm")" 47 | } 48 | -------------------------------------------------------------------------------- /config/starship.toml: -------------------------------------------------------------------------------- 1 | # 设置配置范例,开启编辑器的自动补全 2 | "$schema" = 'https://starship.rs/config-schema.json' 3 | 4 | # Use the color palette 5 | palette = "dracula" 6 | 7 | 8 | [character] 9 | error_symbol = "[✖](bold red)" 10 | success_symbol = "[❯](bold green)" 11 | 12 | [cmd_duration] 13 | style = "bold yellow" 14 | show_milliseconds = true 15 | show_notifications = true 16 | 17 | [directory] 18 | style = "bold green" 19 | 20 | [git_branch] 21 | style = "bold pink" 22 | 23 | [git_status] 24 | style = "bold red" 25 | 26 | [localip] 27 | ssh_only = false 28 | disabled = false 29 | 30 | [memory_usage] 31 | disabled = false 32 | threshold = -1 33 | format = "[${ram}( | ${swap})]($style) " 34 | style = "bold dimmed white" 35 | 36 | [time] 37 | disabled = false 38 | format = '[\[ $time \]]($style) ' 39 | time_format = "%T" 40 | utc_time_offset = "+8" 41 | style = "bold dimmed blue" 42 | 43 | [hostname] 44 | ssh_only = false 45 | style = "bold purple" 46 | format = '[$ssh_symbol$hostname]($style) ' 47 | disabled = false 48 | 49 | [username] 50 | style_user = "bold cyan" 51 | show_always = true 52 | disabled = false 53 | 54 | [shell] 55 | style = 'bold cyan' 56 | format = '[$indicator]($style) ' 57 | fish_indicator = '󰈺 ' 58 | powershell_indicator = '_' 59 | disabled = false 60 | 61 | 62 | # Define Dracula color palette 63 | [palettes.dracula] 64 | background = "#282a36" 65 | current_line = "#44475a" 66 | foreground = "#f8f8f2" 67 | comment = "#6272a4" 68 | cyan = "#8be9fd" 69 | green = "#50fa7b" 70 | orange = "#ffb86c" 71 | pink = "#ff79c6" 72 | purple = "#bd93f9" 73 | red = "#ff5555" 74 | yellow = "#f1fa8c" 75 | -------------------------------------------------------------------------------- /bash/sync_k3s.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | set -e 3 | # 4 | # Usage 5 | # curl -fsSL https://github.com/aliuq/config/raw/master/bash/sync_k3s.sh | sh 6 | # 7 | # Mirror of China: 8 | # curl -fsSL https://hub.llll.host/aliuq/config/raw/master/bash/sync_k3s.sh | sh -s - --mirror 9 | # 10 | 11 | mirror=false 12 | while [ $# -gt 0 ]; do 13 | case "$1" in 14 | --mirror|-M) mirror=true shift ;; 15 | --*) echo "Illegal option $1" ;; 16 | esac 17 | shift $(( $# > 0 ? 1 : 0 )) 18 | done 19 | 20 | RAW_URL=${RAW_URL:-"https://raw.llll.host"} 21 | HUB_URL=${HUB_URL:-"https://hub.llll.host"} 22 | 23 | if ! $mirror; then 24 | HUB_URL="https://github.com" 25 | RAW_URL="https://raw.githubusercontent.com" 26 | fi 27 | 28 | command_exists() { 29 | command -v "$@" >/dev/null 2>&1 30 | } 31 | 32 | if ! command_exists zsh; then 33 | if ! $mirror; then 34 | curl -fsSL "$RAW_URL/aliuq/config/master/bash/install_zsh.sh" | sh 35 | else 36 | curl -fsSL "$RAW_URL/aliuq/config/master/bash/install_zsh.sh" | sh -s - --mirror 37 | fi 38 | fi 39 | 40 | if ! command_exists git; then 41 | yum install -y git 42 | fi 43 | 44 | # Backup old zsh config 45 | if [ -f ~/.zshrc ]; then 46 | cp ~/.zshrc ~/.zshrc.bak.`date +%Y%m%d%H%M%S` 47 | fi 48 | 49 | custom_dir=${ZSH_CUSTOM:-~/.oh-my-zsh/custom} 50 | 51 | # Install zsh-autosuggestions 52 | autosuggestionsDir="$custom_dir/plugins/zsh-autosuggestions" 53 | if [ ! -d "$autosuggestionsDir" ]; then 54 | git clone $HUB_URL/zsh-users/zsh-autosuggestions $autosuggestionsDir 55 | else 56 | echo -e "\e[1;32mzsh-autosuggestions is already installed in $autosuggestionsDir\e[0m" 57 | fi 58 | 59 | # Install zsh-syntax-highlighting 60 | syntaxHighlightingDir="$custom_dir/plugins/zsh-syntax-highlighting" 61 | if [ ! -d "$syntaxHighlightingDir" ]; then 62 | git clone $HUB_URL/zsh-users/zsh-syntax-highlighting $syntaxHighlightingDir 63 | else 64 | echo -e "\e[1;32mzsh-syntax-highlighting is already installed in $syntaxHighlightingDir\e[0m" 65 | fi 66 | 67 | curl -fsSL $RAW_URL/aliuq/config/master/bash/k3s.zshrc > ~/.zshrc 68 | 69 | -------------------------------------------------------------------------------- /bash/sync_wsl.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # 3 | # Usage 4 | # curl -fsSL https://github.com/aliuq/config/raw/master/bash/sync_k3s.sh | sh 5 | # 6 | # Mirror of China: 7 | # curl -fsSL https://hub.llll.host/aliuq/config/raw/master/bash/sync_k3s.sh | sh -s - --mirror 8 | # 9 | 10 | mirror=false 11 | while [ $# -gt 0 ]; do 12 | case "$1" in 13 | --mirror|-M) mirror=true shift ;; 14 | --*) echo "Illegal option $1" ;; 15 | esac 16 | shift $(( $# > 0 ? 1 : 0 )) 17 | done 18 | 19 | RAW_URL=${RAW_URL:-"https://raw.llll.host"} 20 | HUB_URL=${HUB_URL:-"https://hub.llll.host"} 21 | ZSH_URL=${ZSH_URL:-"https://aliuq.oss-cn-beijing.aliyuncs.com/zsh-5.9.tar.xz"} 22 | 23 | if ! $mirror; then 24 | HUB_URL="https://github.com" 25 | RAW_URL="https://raw.githubusercontent.com" 26 | ZSH_URL="https://udomain.dl.sourceforge.net/project/zsh/zsh/5.9/zsh-5.9.tar.xz" 27 | fi 28 | 29 | command_exists() { 30 | command -v "$@" >/dev/null 2>&1 31 | } 32 | 33 | if ! command_exists zsh; then 34 | if ! $mirror; then 35 | curl -fsSL "$RAW_URL/aliuq/config/master/bash/install_zsh.sh" | sh 36 | else 37 | curl -fsSL "$RAW_URL/aliuq/config/master/bash/install_zsh.sh" | sh -s - --mirror 38 | fi 39 | fi 40 | 41 | if ! command_exists git; then 42 | yum install -y git 43 | fi 44 | 45 | # Backup old zsh config 46 | if [ -f ~/.zshrc ]; then 47 | cp ~/.zshrc ~/.zshrc.bak.`date +%Y%m%d%H%M%S` 48 | fi 49 | 50 | # Install zsh-autosuggestions 51 | autosuggestionsDir="${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions" 52 | if [ ! -d "$autosuggestionsDir" ]; then 53 | git clone $HUB_URL/zsh-users/zsh-autosuggestions $autosuggestionsDir 54 | else 55 | echo -e "\e[1;32mzsh-autosuggestions is already installed in $autosuggestionsDir\e[0m" 56 | fi 57 | 58 | # Install zsh-syntax-highlighting 59 | syntaxHighlightingDir="${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting" 60 | if [ ! -d "$syntaxHighlightingDir" ]; then 61 | git clone $HUB_URL/zsh-users/zsh-syntax-highlighting $syntaxHighlightingDir 62 | else 63 | echo -e "\e[1;32mzsh-syntax-highlighting is already installed in $syntaxHighlightingDir\e[0m" 64 | fi 65 | 66 | curl -fsSL $RAW_URL/aliuq/config/master/bash/.zshrc > ~/.zshrc 67 | 68 | -------------------------------------------------------------------------------- /bash/install_zsh.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | set -e 3 | # 4 | # Usage 5 | # curl -fsSL https://github.com/aliuq/config/raw/master/bash/install_zsh.sh | sh 6 | # 7 | # Mirror of China: 8 | # curl -fsSL https://hub.llll.host/aliuq/config/raw/master/bash/install_zsh.sh | sh -s - --mirror 9 | # 10 | 11 | mirror=false 12 | while [ $# -gt 0 ]; do 13 | case "$1" in 14 | --mirror|-M) mirror=true shift ;; 15 | --*) echo "Illegal option $1" ;; 16 | esac 17 | shift $(( $# > 0 ? 1 : 0 )) 18 | done 19 | 20 | RAW_URL=${RAW_URL:-"https://raw.llll.host"} 21 | HUB_URL=${HUB_URL:-"https://hub.llll.host"} 22 | ZSH_URL=${ZSH_URL:-"https://dl.llll.host/https://udomain.dl.sourceforge.net/project/zsh/zsh/5.9/zsh-5.9.tar.xz"} 23 | 24 | if ! $mirror; then 25 | HUB_URL="https://github.com" 26 | RAW_URL="https://raw.githubusercontent.com" 27 | ZSH_URL="https://udomain.dl.sourceforge.net/project/zsh/zsh/5.9/zsh-5.9.tar.xz" 28 | fi 29 | 30 | command_exists() { 31 | command -v "$@" >/dev/null 2>&1 32 | } 33 | 34 | if ! command_exists zsh; then 35 | # Manualy install zsh v5.9 36 | yum update -y && yum install -y make ncurses-devel gcc autoconf man 37 | wget $ZSH_URL -O /tmp/zsh.tar.xz 38 | tar -xf /tmp/zsh.tar.xz -C /tmp 39 | current_dir=$(pwd) 40 | cd /tmp/zsh-5.9 41 | ./Util/preconfig && ./configure 42 | make -j 20 install.bin install.modules install.fns 43 | command -v zsh | sudo tee -a /etc/shells 44 | chsh -s /usr/local/bin/zsh 45 | cd $current_dir 46 | fi 47 | 48 | if ! command_exists git; then 49 | yum install -y git 50 | fi 51 | # Install oh-my-zsh 52 | # The REMOTE environment variable is used to mirror the repository. 53 | curl -fsSL $RAW_URL/ohmyzsh/ohmyzsh/master/tools/install.sh | REMOTE="$HUB_URL/ohmyzsh/ohmyzsh.git" sh -s - -y 54 | 55 | # # 记录下 Ubuntu 下的操作 56 | # sudo apt-get update 57 | # sudo apt-get install -y build-essential curl git libncurses-dev 58 | 59 | # curl -LO https://sourceforge.net/projects/zsh/files/latest/download 60 | # tar xvf download 61 | # cd zsh-* 62 | 63 | # ./configure 64 | # make 65 | # sudo make install 66 | 67 | # sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" 68 | 69 | # command -v zsh | sudo tee -a /etc/shells 70 | # chsh -s /usr/local/bin/zsh 71 | -------------------------------------------------------------------------------- /bash/.zshrc: -------------------------------------------------------------------------------- 1 | # If you come from bash you might have to change your $PATH. 2 | # export PATH=$HOME/bin:/usr/local/bin:$PATH 3 | 4 | # Path to your oh-my-zsh installation. 5 | export ZSH="$HOME/.oh-my-zsh" 6 | 7 | # See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes 8 | ZSH_THEME="agnoster" 9 | 10 | # https://kubernetes.io/zh-cn/docs/tasks/tools/included/optional-kubectl-configs-zsh/ 11 | autoload -Uz compinit 12 | compinit 13 | 14 | # git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions 15 | # git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting 16 | plugins=(git zsh-autosuggestions zsh-syntax-highlighting) 17 | 18 | # Enable aliases to be sudo’ed 19 | # http://askubuntu.com/questions/22037/aliases-not-available-when-using-sudo 20 | alias _='sudo ' 21 | 22 | alias py="python3" 23 | alias cls="clear" 24 | alias apps="cd ~/apps" 25 | alias szsh="source ~/.zshrc" 26 | alias vzsh="vim ~/.zshrc" 27 | alias sbash="source ~/.bashrc" 28 | alias vbash="vim ~/.bashrc" 29 | alias aptup="sudo apt update && sudo apt -y upgrade" 30 | alias yumup="sudo yum update && sudo yum -y upgrade" 31 | 32 | alias s="systemctl" 33 | alias sr="systemctl restart" 34 | alias srf="systemctl daemon-reload && systemctl restart" 35 | alias sst="systemctl status" 36 | 37 | function i() { cd ~/apps/$1 } 38 | function get_ip() { curl -s ip.llll.host } 39 | 40 | export PATH=$HOME/bin:/usr/local/bin:$PATH 41 | 42 | export NVM_DIR="$HOME/.nvm" 43 | [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm 44 | [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion 45 | 46 | # tabtab source for packages 47 | # uninstall by removing these lines 48 | [[ -f ~/.config/tabtab/zsh/__tabtab.zsh ]] && . ~/.config/tabtab/zsh/__tabtab.zsh || true 49 | 50 | # bun completions 51 | [ -s "~/$USER/.bun/_bun" ] && source "~/$USER/.bun/_bun" 52 | 53 | # Bun 54 | export BUN_INSTALL="~/$USER/.bun" 55 | export PATH="$BUN_INSTALL/bin:$PATH" 56 | 57 | # Pnpm 58 | export PNPM_HOME="~/$USER/.local/share/pnpm" 59 | export PATH="$PNPM_HOME:$PATH" 60 | 61 | source $ZSH/oh-my-zsh.sh 62 | # User configuration 63 | source ~/.bash_profile 64 | -------------------------------------------------------------------------------- /starship.toml: -------------------------------------------------------------------------------- 1 | # 设置配置范例,开启编辑器的自动补全 2 | "$schema" = 'https://starship.rs/config-schema.json' 3 | 4 | # $username$hostname$localip$shlvl$singularity$kubernetes$directory$vcsh$fossil_branch$fossil_metrics\ 5 | # $git_branch$git_commit$git_state$git_metrics$git_status$hg_branch$pijul_channel$docker_context$package$c\ 6 | # $cmake$cobol$daml$dart$deno$dotnet$elixir$elm$erlang$fennel\ 7 | # $golang$guix_shell$haskell$haxe$helm$java$julia$kotlin$gradle$lua$nim$nodejs$ocaml\ 8 | # $opa$perl$php$pulumi$purescript$python$raku$rlang$red$ruby$rust$scala$solidity$swift\ 9 | # $terraform$typst$vlang$vagrant$zig$buf$nix_shell$conda$meson$spack$memory_usage$aws$gcloud\ 10 | # $openstack$azure$direnv$env_var$crystal$custom$sudo$cmd_duration$line_break\ 11 | # $jobs$battery$status$os$container$shell 12 | # $time$character 13 | 14 | format = """ 15 | $username$hostname$localip$shlvl$singularity$kubernetes$directory$vcsh$fossil_branch$fossil_metrics\ 16 | $git_branch$git_commit$git_state$git_metrics$git_status$hg_branch$pijul_channel$docker_context$package$c\ 17 | $cmake$cobol$daml$dart$deno$dotnet$elixir$elm$erlang$fennel\ 18 | $golang$guix_shell$haskell$haxe$helm$java$julia$kotlin$gradle$lua$nim$nodejs$ocaml\ 19 | $opa$perl$php$pulumi$purescript$python$raku$rlang$red$ruby$rust$scala$solidity$swift\ 20 | $terraform$typst$vlang$vagrant$zig$buf$nix_shell$conda$meson$spack$memory_usage$aws$gcloud\ 21 | $openstack$azure$direnv$env_var$crystal$custom$sudo$cmd_duration\ 22 | $jobs$battery$status$os$container$shell$line_break\ 23 | $time$character 24 | """ 25 | 26 | [username] 27 | style_user = "yellow bold" 28 | style_root = "red bold" 29 | format = "[$user]($style) " 30 | show_always = true 31 | 32 | [hostname] 33 | ssh_only = false 34 | format = 'on [$hostname]($style) ' 35 | disabled = false 36 | 37 | [localip] 38 | ssh_only = false 39 | format = "in [$localipv4](bold red) " 40 | disabled = false 41 | 42 | [memory_usage] 43 | disabled = false 44 | threshold = -1 45 | format = "[${ram} ${ram_pct}]($style) " 46 | style = "bold dimmed green" 47 | 48 | [time] 49 | disabled = false 50 | format = '[\[ $time \]]($style) ' 51 | time_format = "%T" 52 | utc_time_offset = "+8" 53 | style = "bold dimmed blue" 54 | 55 | [cmd_duration] 56 | show_milliseconds = true 57 | show_notifications = false 58 | 59 | [container] 60 | format = '[$symbol \[$name\]]($style) ' 61 | -------------------------------------------------------------------------------- /modules/system.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # 个人开发环境管理脚本 - 系统模块 4 | # 5 | # - 目前仅支持 Ubuntu apt 安装 6 | # 7 | # sh <(curl -sL https://raw.githubusercontent.com/aliuq/config/refs/heads/master/run.sh) 8 | # 9 | set -e 10 | 11 | if ! command -v run >/dev/null 2>&1; then 12 | . /dev/stdin < $(cyan $new_hostname)" 34 | } 35 | 36 | change_ssh_port() { 37 | log "修改 SSH 端口:" 38 | read_confirm "是否修改 SSH 端口?(y/n): " || return 39 | 40 | new_port=$(read_input "请输入新的 SSH 端口: ") 41 | if [ -z "$new_port" ]; then 42 | red "\n=> 端口不能为空" 43 | else 44 | echo 45 | run "sed -i 's/#Port 22/Port $new_port/g' /etc/ssh/sshd_config" 46 | if is_ubuntu; then 47 | run "systemctl restart ssh" 48 | fi 49 | if is_centos; then 50 | run "systemctl restart sshd" 51 | fi 52 | echo 53 | yellow "=> SSH 端口修改成功,$(cyan 22) => $(cyan $new_port)" 54 | yellow "=> 在云服务器中时,请在云服务商的安全组中开放新的 SSH 端口 $(cyan $new_port)" 55 | yellow "=> 最后不要忘了重启服务器 $(cyan "sudo reboot")" 56 | 57 | read_confirm "是否立即重启服务器?(y/n): " && run "sudo reboot" 58 | fi 59 | } 60 | 61 | generate_ssh_key() { 62 | log "生成 SSH 密钥:" 63 | 64 | if read_confirm "是否生成 SSH 密钥?(y/n): "; then 65 | save_dir="/tmp/ssh/$(date "+%Y-%m-%d-%H-%M-%S")" 66 | name=$(read_input "请输入密钥名称(默认 key): " "key") 67 | type=$(read_input "请输入密钥类型(1. rsa, 2. ed25519, 默认 2): " "2") 68 | if [ "$type" = "1" ]; then type="rsa"; else type="ed25519"; fi 69 | key="$save_dir/$name" 70 | 71 | run "mkdir -p $save_dir" 72 | run "ssh-keygen -t "$type" -b 4096 -C "aliuq@bilishare.com" -f \"$key\" -N \"\" -q" 73 | 74 | green "\n✅ SSH 密钥生成成功\n" 75 | info " - 私钥保存在 $(cyan $key)" 76 | info " - 公钥保存在 $(cyan $key.pub)" 77 | echo 78 | info "使用: \n" 79 | info " 1. 将公钥添加到远程服务器" 80 | info " 先通过服务器控制台或者密码连接到远程服务器, 然后执行以下命令\n" 81 | info " > $(cyan "echo \"$(cat $key.pub)\" >> ~/.ssh/authorized_keys")" 82 | echo 83 | info " 2. 将私钥保存到本地, 通常是 $(cyan "~/.ssh") 下\n" 84 | info " > $(cyan "cp $key ~/.ssh/")" 85 | info " > $(cyan "ssh -i $key user@host")" 86 | echo 87 | yellow_bright " * 注意: 请不要泄露私钥,否则可能导致账号被盗\n" 88 | fi 89 | } 90 | -------------------------------------------------------------------------------- /bash/k3s.zshrc: -------------------------------------------------------------------------------- 1 | # This configuration is used for k3s cluster node servers 2 | # Copyright (c) by aliuq 3 | # 4 | 5 | # If you come from bash you might have to change your $PATH. 6 | # export PATH=$HOME/bin:/usr/local/bin:$PATH 7 | 8 | # Path to your oh-my-zsh installation. 9 | export ZSH="$HOME/.oh-my-zsh" 10 | 11 | # See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes 12 | ZSH_THEME="agnoster" 13 | 14 | # https://kubernetes.io/zh-cn/docs/tasks/tools/included/optional-kubectl-configs-zsh/ 15 | autoload -Uz compinit 16 | compinit 17 | 18 | # git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions 19 | # git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting 20 | plugins=(git kubectl zsh-autosuggestions zsh-syntax-highlighting) 21 | 22 | # Enable aliases to be sudo’ed 23 | # http://askubuntu.com/questions/22037/aliases-not-available-when-using-sudo 24 | alias _='sudo ' 25 | alias cls="clear" 26 | alias szsh="source ~/.zshrc" 27 | alias vzsh="vim ~/.zshrc" 28 | alias aptup="sudo apt update && sudo apt -y upgrade" 29 | alias yumup="sudo yum update && sudo yum -y upgrade" 30 | 31 | export PATH=$HOME/bin:/usr/local/bin:$PATH 32 | 33 | export NVM_DIR="$HOME/.nvm" 34 | [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm 35 | [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion 36 | 37 | # tabtab source for packages 38 | # uninstall by removing these lines 39 | [[ -f ~/.config/tabtab/zsh/__tabtab.zsh ]] && . ~/.config/tabtab/zsh/__tabtab.zsh || true 40 | 41 | source $ZSH/oh-my-zsh.sh 42 | # User configuration 43 | source ~/.bash_profile 44 | 45 | # Variables 46 | # kgpa | awk "$AWK_SPACE{print \$1,\$2}" 47 | AWK_SPACE="BEGIN { FPAT = \"([[:space:]]*[[:alnum:][:punct:][:digit:]]+)\"; OFS = \"\"; }" 48 | 49 | # Alias 50 | alias s="systemctl" 51 | alias sr="systemctl restart" 52 | alias srf="systemctl daemon-reload && systemctl restart" 53 | alias sst="systemctl status" 54 | alias sync_zsh_conf_mirror="curl -fsSL https://hub.llll.host/aliuq/config/raw/master/bash/sync_k3s.sh | sh -s - --mirror" 55 | alias sync_zsh_conf="curl -fsSL https://github.com/aliuq/config/raw/master/bash/sync_k3s.sh | sh" 56 | alias ktn="kubectl top node" 57 | 58 | # Functions 59 | get_ip() { curl -s ip.llll.host } 60 | 61 | # Force delete namespace 62 | kdelnsf() { 63 | if ! command -v jq >/dev/null 2>&1; then 64 | echo -e "\e[1;33mjq is not installed, please install it first, \"yum install -y jq\"\e[0m" 65 | return 0 66 | fi 67 | if [ $1 ]; then 68 | file="$1_tmp.json" 69 | echo "kubectl get namespace $1 -o json > $file" 70 | kubectl get namespace $1 -o json > $file >/dev/null 2>&1 71 | echo "echo \`cat $file\` | perl -pe \"s/\\\"finalizers\\\": \[.*?\]/\\\"finalizers\\\": \[\]/g\" | jq . > $file" 72 | echo `cat $file` | perl -pe "s/\"finalizers\": \[.*?\]/\"finalizers\": \[\]/g" | jq . > $file >/dev/null 2>&1 73 | echo "kubectl replace --raw \"/api/v1/namespaces/$1/finalize\" -f $file" 74 | kubectl replace --raw "/api/v1/namespaces/$1/finalize" -f $file >/dev/null 2>&1 75 | if [ $? -eq 0 ]; then 76 | echo "namespace $1 deleted" 77 | echo "rm $file -rf" 78 | rm $file -rf 79 | else 80 | echo "failed deleted namespace $1" 81 | fi 82 | return 0 83 | fi 84 | } 85 | 86 | # Delete pod by matching label 87 | kdelpm() { 88 | pod=$1 89 | if [ $pod ]; then 90 | shift 91 | kubectl get pods -A | grep $pod | awk '{print $1,$2}' | while read ns name; do 92 | kubectl delete -n $ns pod $name $@ 93 | done 94 | fi 95 | } 96 | 97 | _kde_comp() { 98 | local curword="${COMP_WORDS[COMP_CWORD]}" 99 | if [ $curword ]; then 100 | pods=$(kubectl get pods -A | grep $curword | awk '{print $2}') 101 | else 102 | pods=$(kubectl get pods -A | awk '{if (NR>1){print $2}}') 103 | fi 104 | local completions=(${(@f)pods}) 105 | _describe 'command' completions 106 | } 107 | 108 | compdef _kde_comp kdelpm 109 | 110 | ktp() { 111 | if [ $# -eq 0 ]; then 112 | kubectl top pods -A | awk 'NR == 1 {print $0};NR != 1 {print $0 | "sort -n -k 4 -r"}' 113 | else 114 | kubectl top pods -A | awk 'NR == 1 {print $0};NR != 1 {print $0 | "sort -n -k 4 -r | grep -P '$1'"}' 115 | fi 116 | } 117 | -------------------------------------------------------------------------------- /bash/init_wsl.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # 初始化 WSL 环境和依赖 5 | # 6 | # sh <(curl -L -s https://raw.githubusercontent.com/aliuq/config/refs/heads/master/bash/init_wsl.sh) 7 | # 8 | 9 | set -e 10 | 11 | # . /home/aliuq/apps/config/helper.sh 12 | 13 | . /dev/stdin <\n" 38 | printf "$(gray 脚本描述) : 安装通用的环境和依赖,确保各机器之间保持体验一致\n" 39 | printf "$(gray 运行环境) : $(red WSL2 Ubuntu)\n" 40 | printf "$(gray "所用 Shell") : sh\n" 41 | echo 42 | 43 | # 脚本信息 44 | SCRIPT_NAME="WSL Ubuntu 环境初始化" 45 | VERSION="1.0.0" 46 | AUTHOR="AliuQ" 47 | DESCRIPTION="安装通用的环境和依赖,确保各机器之间保持体验一致" 48 | REQUIRED_SHELL="sh" 49 | 50 | echo "------------------- $(magenta 系统) -------------------" 51 | printf "$(green "1.") 更新软件包 $(green "2.") 修改主机名 $(green "q.") 退出\n" 52 | 53 | echo "\n\n------------------- $(magenta 配置) -------------------" 54 | printf "$(green "100.") 安装 zsh $(green "101.") 安装 oh-my-zsh $(green "102.") 覆盖 ~/.zshrc\n" 55 | 56 | echo "\n\n------------------- $(magenta 前端) -------------------" 57 | printf "$(green "200.") 安装 nvm \n" 58 | 59 | echo 60 | echo 61 | read -p "$(magenta "=> 请输入要执行的命令编号:") " command_index 62 | echo 63 | echo 64 | 65 | case $command_index in 66 | 1) 67 | update_packages 68 | ;; 69 | 2) 70 | change_hostname 71 | ;; 72 | 200) 73 | install_zsh 74 | ;; 75 | 101) 76 | install_oh_my_zsh 77 | ;; 78 | 102) 79 | sync_zshrc 80 | ;; 81 | 200) 82 | install_nvm 83 | ;; 84 | [qQ] | [eE][xX][iI][tT] | [qQ][uU][iI][tT]) 85 | exit 0 86 | ;; 87 | *) 88 | red "命令编号错误: $command_index" 89 | exit 1 90 | ;; 91 | esac 92 | echo 93 | echo 94 | } 95 | 96 | # ======================== 分割线 ======================== 97 | 98 | update_packages() { 99 | log "更新软件包" 100 | read_confirm "是否更新软件包?(y/n): " || return 101 | run "apt update -y && apt upgrade -y" 102 | } 103 | 104 | change_hostname() { 105 | log "修改主机名和 /etc/hosts:" 106 | read_confirm "是否修改主机名?(y/n): " || return 107 | 108 | new_hostname=$(read_input "请输入新的主机名(wsl): " wsl) 109 | HOSTNAME=$(hostname) 110 | echo 111 | run "sed -i 's/$HOSTNAME/$new_hostname/g' /etc/hosts" 112 | run "hostnamectl set-hostname $new_hostname" 113 | info "主机名修改成功,$(cyan $HOSTNAME) => $(cyan $new_hostname)" 114 | } 115 | 116 | install_nvm() { 117 | log "安装 nvm" 118 | read_confirm "是否安装 nvm?(y/n): " || return 119 | 120 | # 判断当前终端 echo $SHELL 是否是 zsh 121 | if [ "$SHELL" != "/usr/bin/zsh" ]; then 122 | red "==> 当前终端不是 zsh,请在 zsh 环境下执行" 123 | return 124 | fi 125 | 126 | if $dry_run; then 127 | run "commands_valid curl" 128 | else 129 | commands_valid curl 130 | fi 131 | echo 132 | version=$(read_input "请输入 nvm 版本(默认最新版 master/v0.40.1): " "master") 133 | echo 134 | run "curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/$version/install.sh | bash" 135 | 136 | echo "--------------------------------------------" 137 | info "安装完成,请执行 $(cyan "source ~/.zshrc") 使配置生效" 138 | info "安装完成后,可以执行 $(cyan "nvm install --lts") 安装最新的 LTS 版本" 139 | info "安装完成后,可以执行 $(cyan "nvm ls-remote") 查看所有可安装的版本" 140 | echo 141 | } 142 | 143 | # ======================== 分割线 ======================== 144 | 145 | echo_commands 146 | -------------------------------------------------------------------------------- /dokploy/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | install_dokploy() { 3 | if [ "$(id -u)" != "0" ]; then 4 | echo "This script must be run as root" >&2 5 | exit 1 6 | fi 7 | 8 | # check if is Mac OS 9 | if [ "$(uname)" = "Darwin" ]; then 10 | echo "This script must be run on Linux" >&2 11 | exit 1 12 | fi 13 | 14 | # check if is running inside a container 15 | if [ -f /.dockerenv ]; then 16 | echo "This script must be run on Linux" >&2 17 | exit 1 18 | fi 19 | 20 | # check if something is running on port 80 21 | if ss -tulnp | grep ':80 ' >/dev/null; then 22 | echo "Error: something is already running on port 80" >&2 23 | exit 1 24 | fi 25 | 26 | # check if something is running on port 443 27 | if ss -tulnp | grep ':443 ' >/dev/null; then 28 | echo "Error: something is already running on port 443" >&2 29 | exit 1 30 | fi 31 | 32 | command_exists() { 33 | command -v "$@" >/dev/null 2>&1 34 | } 35 | 36 | if command_exists docker; then 37 | echo "Docker already installed" 38 | else 39 | curl -sSL https://get.docker.com | sh 40 | fi 41 | 42 | docker swarm leave --force 2>/dev/null 43 | 44 | get_ip() { 45 | # Try to get IPv4 46 | local ipv4=$(curl -4s https://ifconfig.io 2>/dev/null) 47 | 48 | if [ -n "$ipv4" ]; then 49 | echo "$ipv4" 50 | else 51 | # Try to get IPv6 52 | local ipv6=$(curl -6s https://ifconfig.io 2>/dev/null) 53 | if [ -n "$ipv6" ]; then 54 | echo "$ipv6" 55 | fi 56 | fi 57 | } 58 | 59 | # advertise_addr=$(get_ip) 60 | # docker swarm init --advertise-addr $advertise_addr 61 | 62 | # 修改部分 63 | advertise_addr=192.168.2.122 64 | docker swarm init 65 | 66 | echo "Swarm initialized" 67 | 68 | docker network rm -f dokploy-network 2>/dev/null 69 | docker network create --driver overlay --attachable dokploy-network 70 | 71 | echo "Network created" 72 | 73 | mkdir -p /etc/dokploy 74 | 75 | chmod 777 /etc/dokploy 76 | 77 | docker pull dokploy/dokploy:latest 78 | 79 | # Installation 80 | docker service create \ 81 | --name dokploy \ 82 | --replicas 1 \ 83 | --network dokploy-network \ 84 | --mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock \ 85 | --mount type=bind,source=/etc/dokploy,target=/etc/dokploy \ 86 | --mount type=volume,source=dokploy-docker-config,target=/root/.docker \ 87 | --publish published=13000,target=3000,mode=host \ 88 | --update-parallelism 1 \ 89 | --update-order stop-first \ 90 | --constraint 'node.role == manager' \ 91 | -e PORT=13000 \ 92 | dokploy/dokploy:latest 93 | 94 | GREEN="\033[0;32m" 95 | YELLOW="\033[1;33m" 96 | BLUE="\033[0;34m" 97 | NC="\033[0m" # No Color 98 | 99 | format_ip_for_url() { 100 | local ip="$1" 101 | if echo "$ip" | grep -q ':'; then 102 | # IPv6 103 | echo "[${ip}]" 104 | else 105 | # IPv4 106 | echo "${ip}" 107 | fi 108 | } 109 | 110 | formatted_addr=$(format_ip_for_url "$advertise_addr") 111 | echo "" 112 | printf "${GREEN}Congratulations, Dokploy is installed!${NC}\n" 113 | printf "${BLUE}Wait 15 seconds for the server to start${NC}\n" 114 | printf "${YELLOW}Please go to http://${formatted_addr}:13000${NC}\n\n" 115 | } 116 | 117 | update_dokploy() { 118 | echo "Updating Dokploy..." 119 | 120 | # Pull the latest image 121 | docker pull dokploy/dokploy:latest 122 | 123 | # Update the service 124 | docker service update --image dokploy/dokploy:latest dokploy 125 | 126 | echo "Dokploy has been updated to the latest version." 127 | } 128 | 129 | uninstall_dokploy() { 130 | echo "Uninstalling Dokploy..." 131 | 132 | docker service rm dokploy dokploy-traefik dokploy-postgres dokploy-redis 133 | # docker volume rm dokploy-postgres-database redis-data-volume -f 134 | # sudo rm -rf /etc/dokploy 135 | 136 | echo "Dokploy has been uninstalled." 137 | } 138 | 139 | # Main script execution 140 | if [ "$1" = "update" ]; then 141 | update_dokploy 142 | elif [ "$1" = "uninstall" ]; then 143 | uninstall_dokploy 144 | else 145 | install_dokploy 146 | fi 147 | -------------------------------------------------------------------------------- /run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # 个人开发环境管理脚本 4 | # 5 | # - 目前仅支持 Ubuntu apt 安装 6 | # 7 | # sh <(curl -sL https://raw.githubusercontent.com/aliuq/config/refs/heads/master/run.sh) 8 | # sh <(curl -sL https://s.xod.cc/run) 9 | # MIRROR=true sh <(curl -sL https://s.xod.cc/run-mirror) 10 | # MIRROR=true sh <(curl -sL https://raw.llll.host/aliuq/config/refs/heads/master/run.sh) 11 | # 12 | set -e 13 | 14 | # 从环境变量来判断是否通过镜像获取文件,避免请求过慢的问题 15 | global_mirror=${MIRROR:-false} 16 | 17 | case $global_mirror in 18 | true) 19 | global_mirror="https://raw.llll.host" 20 | ;; 21 | false) 22 | global_mirror="https://raw.githubusercontent.com" 23 | ;; 24 | esac 25 | 26 | . /dev/stdin < 0 ? 1 : 0)) 45 | done 46 | 47 | if $help; then 48 | yellow "\n暂未实现 help 功能" 49 | exit 0 50 | fi 51 | 52 | echo_info() { 53 | OS=$(uname -s) 54 | KERNEL_VERSION=$(uname -r) 55 | USERNAME=$(whoami) 56 | 57 | # 检查是否在 WSL 环境中 58 | if grep -qi microsoft /proc/version; then 59 | IS_WSL="Yes" 60 | else 61 | IS_WSL="No" 62 | fi 63 | 64 | # 获取完整的系统信息 65 | if [ -f /etc/os-release ]; then 66 | . /etc/os-release 67 | OS_NAME="$NAME" 68 | OS_VERSION="$VERSION" 69 | elif [ -f /etc/lsb-release ]; then 70 | . /etc/lsb-release 71 | OS_NAME="$DISTRIB_ID" 72 | OS_VERSION="$DISTRIB_RELEASE" 73 | else 74 | OS_NAME="Unknown" 75 | OS_VERSION="Unknown" 76 | fi 77 | 78 | UPTIME_RAW=$(uptime -p) 79 | UPTIME_CN=$(echo "$UPTIME_RAW" | sed \ 80 | -e 's/up //g' \ 81 | -e 's/ days/天/g' \ 82 | -e 's/ day/天/g' \ 83 | -e 's/ hours/小时/g' \ 84 | -e 's/ hour/小时/g' \ 85 | -e 's/ minutes/分钟/g' \ 86 | -e 's/ minute/分钟/g' \ 87 | -e 's/,//g' \ 88 | -e 's/ and / /g') 89 | 90 | echo 91 | clear 92 | printf "脚本名称 : $(white "个人开发环境管理脚本")\n" 93 | printf "脚本地址 : https://github.com/aliuq/config/blob/master/run.sh\n" 94 | printf "描述 : 记录一些本人经常使用的脚本操作\n" 95 | printf "Shell : %s\n" "$SHELL" 96 | printf "Hostname : %s\n" "$(hostname)" 97 | printf "Username : %s\n" "$USERNAME" 98 | printf "IP : %s\n" "$(hostname -I)" 99 | printf "公网 IP : %s\n" "$(green "$(curl -sL https://ip.llll.host)")" 100 | printf "系统运行时间: %s\n" "$UPTIME_CN" 101 | 102 | if $verbose; then 103 | echo "_________________________________________\n" 104 | printf "系统 : %s %s\n" "$OS_NAME" "$OS_VERSION" 105 | printf "内核 : %s\n" "$KERNEL_VERSION" 106 | printf "是否是 WSL : %s\n" "$IS_WSL" 107 | printf "系统架构 : %s\n" "$(uname -m)" 108 | printf "Home : %s\n" "$HOME" 109 | printf "当前目录 : %s\n" "$(pwd)" 110 | echo 111 | fi 112 | } 113 | 114 | echo_commands() { 115 | printf "\n------------------- $(magenta "系统") -------------------\n" 116 | printf "$(green "1.") 更新软件包 $(green "2.") 修改主机名 $(green "q.") 退出\n" 117 | printf "$(green "3.") 修改 ssh 端口\n" 118 | 119 | printf "\n\n------------------- $(magenta "配置") -------------------\n" 120 | printf "$(green "100.") 安装 zsh $(green "101.") 安装 oh-my-zsh $(green "102.") 覆盖 ~/.zshrc\n" 121 | printf "$(green "103.") 安装 starship $(green "104.") 添加 waketime $(green "105.") 添加 docker 镜像\n" 122 | printf "$(green "106.") 生成 ssh 密钥\n" 123 | 124 | printf "\n\n------------------- $(magenta 前端) -------------------\n" 125 | printf "$(green "200.") 安装 nvm \n" 126 | 127 | echo 128 | echo 129 | read -p "$(magenta "=> 请输入要执行的命令编号:") " command_index 130 | echo 131 | echo 132 | 133 | case $command_index in 134 | 1) 135 | update_packages 136 | ;; 137 | 2) 138 | change_hostname 139 | ;; 140 | 3) 141 | change_ssh_port 142 | ;; 143 | 100) 144 | install_zsh 145 | ;; 146 | 101) 147 | install_oh_my_zsh 148 | ;; 149 | 102) 150 | sync_zshrc 151 | ;; 152 | 103) 153 | install_starship 154 | ;; 155 | 104) 156 | add_wakatime 157 | ;; 158 | 105) 159 | add_docker_mirror 160 | ;; 161 | 106) 162 | generate_ssh_key 163 | ;; 164 | 200) 165 | install_nvm 166 | ;; 167 | [qQ] | [eE][xX][iI][tT] | [qQ][uU][iI][tT]) 168 | exit 0 169 | ;; 170 | *) 171 | red "命令编号错误: $command_index" 172 | exit 1 173 | ;; 174 | esac 175 | echo 176 | echo 177 | } 178 | 179 | echo_info 180 | echo_commands 181 | -------------------------------------------------------------------------------- /config/.zshrc: -------------------------------------------------------------------------------- 1 | # If you come from bash you might have to change your $PATH. 2 | # export PATH=$HOME/bin:$HOME/.local/bin:/usr/local/bin:$PATH 3 | 4 | # Path to your Oh My Zsh installation. 5 | export ZSH="$HOME/.oh-my-zsh" 6 | 7 | # Set name of the theme to load --- if set to "random", it will 8 | # load a random theme each time Oh My Zsh is loaded, in which case, 9 | # to know which specific one was loaded, run: echo $RANDOM_THEME 10 | # See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes 11 | ZSH_THEME="agnoster" 12 | 13 | # Set list of themes to pick from when loading at random 14 | # Setting this variable when ZSH_THEME=random will cause zsh to load 15 | # a theme from this variable instead of looking in $ZSH/themes/ 16 | # If set to an empty array, this variable will have no effect. 17 | # ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" ) 18 | 19 | # Uncomment the following line to use case-sensitive completion. 20 | # CASE_SENSITIVE="true" 21 | 22 | # Uncomment the following line to use hyphen-insensitive completion. 23 | # Case-sensitive completion must be off. _ and - will be interchangeable. 24 | # HYPHEN_INSENSITIVE="true" 25 | 26 | # Uncomment one of the following lines to change the auto-update behavior 27 | # zstyle ':omz:update' mode disabled # disable automatic updates 28 | # zstyle ':omz:update' mode auto # update automatically without asking 29 | # zstyle ':omz:update' mode reminder # just remind me to update when it's time 30 | 31 | # Uncomment the following line to change how often to auto-update (in days). 32 | # zstyle ':omz:update' frequency 13 33 | 34 | # Uncomment the following line if pasting URLs and other text is messed up. 35 | # DISABLE_MAGIC_FUNCTIONS="true" 36 | 37 | # Uncomment the following line to disable colors in ls. 38 | # DISABLE_LS_COLORS="true" 39 | 40 | # Uncomment the following line to disable auto-setting terminal title. 41 | # DISABLE_AUTO_TITLE="true" 42 | 43 | # Uncomment the following line to enable command auto-correction. 44 | # ENABLE_CORRECTION="true" 45 | 46 | # Uncomment the following line to display red dots whilst waiting for completion. 47 | # You can also set it to another string to have that shown instead of the default red dots. 48 | # e.g. COMPLETION_WAITING_DOTS="%F{yellow}waiting...%f" 49 | # Caution: this setting can cause issues with multiline prompts in zsh < 5.7.1 (see #5765) 50 | # COMPLETION_WAITING_DOTS="true" 51 | 52 | # Uncomment the following line if you want to disable marking untracked files 53 | # under VCS as dirty. This makes repository status check for large repositories 54 | # much, much faster. 55 | # DISABLE_UNTRACKED_FILES_DIRTY="true" 56 | 57 | # Uncomment the following line if you want to change the command execution time 58 | # stamp shown in the history command output. 59 | # You can set one of the optional three formats: 60 | # "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd" 61 | # or set a custom format using the strftime function format specifications, 62 | # see 'man strftime' for details. 63 | # HIST_STAMPS="mm/dd/yyyy" 64 | 65 | # Would you like to use another custom folder than $ZSH/custom? 66 | # ZSH_CUSTOM=/path/to/new-custom-folder 67 | 68 | # Which plugins would you like to load? 69 | # Standard plugins can be found in $ZSH/plugins/ 70 | # Custom plugins may be added to $ZSH_CUSTOM/plugins/ 71 | # Example format: plugins=(rails git textmate ruby lighthouse) 72 | # Add wisely, as too many plugins slow down shell startup. 73 | plugins=(git zsh-autosuggestions zsh-syntax-highlighting) 74 | 75 | source $ZSH/oh-my-zsh.sh 76 | 77 | # User configuration 78 | 79 | # export MANPATH="/usr/local/man:$MANPATH" 80 | 81 | # You may need to manually set your language environment 82 | # export LANG=en_US.UTF-8 83 | 84 | # Preferred editor for local and remote sessions 85 | # if [[ -n $SSH_CONNECTION ]]; then 86 | # export EDITOR='vim' 87 | # else 88 | # export EDITOR='nvim' 89 | # fi 90 | 91 | # Compilation flags 92 | # export ARCHFLAGS="-arch $(uname -m)" 93 | 94 | # Set personal aliases, overriding those provided by Oh My Zsh libs, 95 | # plugins, and themes. Aliases can be placed here, though Oh My Zsh 96 | # users are encouraged to define aliases within a top-level file in 97 | # the $ZSH_CUSTOM folder, with .zsh extension. Examples: 98 | # - $ZSH_CUSTOM/aliases.zsh 99 | # - $ZSH_CUSTOM/macos.zsh 100 | # For a full list of active aliases, run `alias`. 101 | # 102 | # Example aliases 103 | # alias zshconfig="mate ~/.zshrc" 104 | # alias ohmyzsh="mate ~/.oh-my-zsh" 105 | 106 | # Enable aliases to be sudo’ed 107 | # http://askubuntu.com/questions/22037/aliases-not-available-when-using-sudo 108 | alias _="sudo " 109 | alias cls="clear" 110 | alias szsh="source ~/.zshrc" 111 | alias vzsh="vim ~/.zshrc" 112 | alias sbash="source ~/.bashrc" 113 | alias vbash="vim ~/.bashrc" 114 | alias aptup="sudo apt update && sudo apt -y upgrade" 115 | 116 | # some more ls aliases 117 | alias ll="ls -alF" 118 | alias la="ls -A" 119 | alias l="ls -CF" 120 | 121 | function get_ip() { curl -s https://ip.llll.host; } 122 | 123 | export PATH=$HOME/bin:/usr/local/bin:$PATH 124 | -------------------------------------------------------------------------------- /modules/config.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # 个人开发环境管理脚本 - 配置模块 4 | # 5 | # - 目前仅支持 Ubuntu apt 安装 6 | # 7 | # sh <(curl -sL https://raw.githubusercontent.com/aliuq/config/refs/heads/master/run.sh) 8 | # 9 | set -e 10 | 11 | if ! command -v run >/dev/null 2>&1; then 12 | . /dev/stdin <~/.zshrc" 98 | info "\n\n请执行 $(cyan "source ~/.zshrc") 使配置生效" 99 | fi 100 | } 101 | 102 | install_zsh() { 103 | log "安装 zsh" 104 | 105 | if read_confirm "是否安装 zsh?(y/n): "; then 106 | install_type=$(read_input "请选择安装方式(1. apt 安装,2. 源码安装,默认为 1): " "1") 107 | if [ "$install_type" = "1" ]; then 108 | run "apt install -y zsh" 109 | else 110 | install_zsh_from_source 111 | fi 112 | if $dry_run; then 113 | run "sudo chsh -s $(which zsh)" 114 | else 115 | sudo chsh -s $(which zsh) 116 | fi 117 | fi 118 | 119 | echo 120 | install_oh_my_zsh 121 | 122 | echo 123 | sync_zshrc 124 | } 125 | 126 | install_starship_add_config() { 127 | if read_confirm "是否添加通用配置到 ~/.config/starship.toml?(y/n): " false; then 128 | if read_confirm "是否使用 mirror?(y/n): "; then 129 | RAW_URL="https://raw.llll.host" 130 | else 131 | RAW_URL="https://raw.githubusercontent.com" 132 | fi 133 | 134 | run "mkdir -p ~/.config" 135 | run "curl -fsSL $RAW_URL/aliuq/config/master/config/starship.toml >~/.config/starship.toml" 136 | fi 137 | } 138 | 139 | install_starship_set_cloud() { 140 | log "设置云服务商环境变量" 141 | if read_confirm "是否设置云服务商环境变量?(y/n): " false; then 142 | cloud_server_str="阿里云|腾讯云" 143 | read_from_options_show $cloud_server_str 144 | cloud_server=$(read_from_options "请选择云服务厂商?" "" $cloud_server_str) 145 | echo 146 | if [ -n "$cloud_server" ]; then 147 | if echo "$SHELL" | grep -qE "/bash$"; then 148 | run "echo 'export CLOUD_SERVER=$cloud_server' >>~/.bashrc" 149 | fi 150 | if echo "$SHELL" | grep -qE "/zsh$"; then 151 | run "echo 'export CLOUD_SERVER=$cloud_server' >>~/.zshrc" 152 | fi 153 | fi 154 | 155 | cloud_server_region_str="上海|北京|广州|深圳|杭州|香港|新加坡" 156 | read_from_options_show $cloud_server_region_str 157 | cloud_server_region=$(read_from_options "请选择所在地域?" "" $cloud_server_region_str) 158 | echo 159 | if [ -n "$cloud_server_region" ]; then 160 | if echo "$SHELL" | grep -qE "/bash$"; then 161 | run "echo 'export CLOUD_SERVER_REGION=$cloud_server_region' >>~/.bashrc" 162 | fi 163 | if echo "$SHELL" | grep -qE "/zsh$"; then 164 | run "echo 'export CLOUD_SERVER_REGION=$cloud_server_region' >>~/.zshrc" 165 | fi 166 | fi 167 | fi 168 | } 169 | 170 | install_starship() { 171 | log "安装 starship" 172 | 173 | if read_confirm "是否安装 starship?(y/n): "; then 174 | if $dry_run; then 175 | run "commands_valid curl" 176 | else 177 | commands_valid curl 178 | fi 179 | run "curl -sS https://starship.rs/install.sh | sh" 180 | 181 | # 如果 shell 匹配到 /*\/bash/,且 .bashrc 文件中不包含 【eval "$(starship init bash)"】 则添加 182 | if echo "$SHELL" | grep -qE "/bash$"; then 183 | if ! grep -q "eval \"\$(starship init bash)\"" ~/.bashrc; then 184 | run "echo 'eval \"\$(starship init bash)\"' >>~/.bashrc" 185 | fi 186 | install_starship_add_config 187 | info "\n\n请执行 $(cyan "source ~/.bashrc") 使配置生效" 188 | fi 189 | 190 | # 如果 shell 匹配到 /*\/zsh/,且 .zshrc 文件中不包含 【eval "$(starship init zsh)"】 则添加 191 | if echo "$SHELL" | grep -qE "/zsh$"; then 192 | if ! grep -q "eval \"\$(starship init zsh)\"" ~/.zshrc; then 193 | run "echo 'eval \"\$(starship init zsh)\"' >>~/.zshrc" 194 | fi 195 | install_starship_add_config 196 | info "\n\n请执行 $(cyan "source ~/.zshrc") 使配置生效" 197 | fi 198 | 199 | install_starship_set_cloud 200 | fi 201 | } 202 | 203 | add_wakatime() { 204 | log "添加 wakatime" 205 | 206 | if read_confirm "是否添加通用配置到 ~/.wakatime.cfg?(y/n): " false; then 207 | api_url=$(read_input "请输入 api_url: ") 208 | api_key=$(read_input "请输入 api_key: ") 209 | 210 | if [ -z "$api_url" ] || [ -z "$api_key" ]; then 211 | red "api_url 和 api_key 不能为空" 212 | else 213 | run "cat >~/.wakatime.cfg <<-EOF 214 | [settings] 215 | api_url = $api_url 216 | api_key = $api_key 217 | EOF" 218 | fi 219 | fi 220 | } 221 | 222 | add_docker_mirror() { 223 | log "添加 docker 镜像加速" 224 | 225 | if $dry_run; then 226 | run "commands_valid docker jq" 227 | else 228 | commands_valid docker jq 229 | fi 230 | 231 | if read_confirm "是否添加 docker 镜像加速?(y/n): "; then 232 | mirror_url=$(read_input "请输入镜像地址,国内服务器无法访问 https://registry-1.docker.io: ") 233 | if [ -z "$mirror_url" ]; then 234 | red "镜像地址不能为空" 235 | else 236 | # 判断是否存在 /etc/docker/daemon.json 文件,如果不存在则创建 237 | if [ ! -f /etc/docker/daemon.json ]; then 238 | run "mkdir -p /etc/docker" 239 | run "touch /etc/docker/daemon.json" 240 | fi 241 | # 使用 jq 进行修复意外空格或者空行情况 242 | if ! jq -e '.["registry-mirrors"]' /etc/docker/daemon.json >/dev/null 2>&1; then 243 | run "jq '. + {\"registry-mirrors\": [\"$mirror_url\"]}' /etc/docker/daemon.json > /tmp/daemon.json && mv /tmp/daemon.json /etc/docker/daemon.json" 244 | else 245 | run "jq '.\"registry-mirrors\" += [\"$mirror_url\"]' /etc/docker/daemon.json > /tmp/daemon.json && mv /tmp/daemon.json /etc/docker/daemon.json" 246 | fi 247 | 248 | run "systemctl restart docker" 249 | fi 250 | fi 251 | } 252 | -------------------------------------------------------------------------------- /helper.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Usage: 4 | # 5 | # For shell: 6 | # 7 | # . /dev/stdin </dev/null 2>&1 153 | } 154 | 155 | command_valid() { 156 | if ! command_exists "$1"; then 157 | if [ -z "$2" ]; then 158 | red "Error: $1 is not installed or not in PATH" 159 | else 160 | red "$2" 161 | fi 162 | exit 1 163 | fi 164 | } 165 | 166 | commands_valid() { 167 | for cmd in "$@"; do 168 | command_valid "$cmd" 169 | done 170 | } 171 | 172 | run() { 173 | if $dry_run; then 174 | echo "+ $sh_c '$1'" 175 | return 176 | fi 177 | if $verbose; then 178 | echo "+ $sh_c '$1'" 179 | fi 180 | $sh_c "$1" 181 | } 182 | 183 | set_var() { 184 | user="$(id -un 2>/dev/null || true)" 185 | sh_c="sh -c" 186 | if [ "$user" != "root" ]; then 187 | if command_exists sudo; then 188 | sh_c="sudo -E sh -c" 189 | elif command_exists su; then 190 | sh_c="su -c" 191 | else 192 | printf >&2 "Error: this installer needs the ability to run commands as root.\n" 193 | printf >&2 "We are unable to find either \"sudo\" or \"su\" available to make this happen.\n" 194 | exit 1 195 | fi 196 | fi 197 | } 198 | 199 | # 发送 Webhook 消息 200 | send_webhook() { 201 | # 如果不存在 MY_WEBHOOK_URL 环境变量,则不发送消息 202 | if [ -z "$MY_WEBHOOK_URL" ]; then 203 | yellow "MY_WEBHOOK_URL 环境变量不存在" 204 | return 205 | fi 206 | 207 | # 如果不存在消息内容,则不发送消息 208 | if [ -z "$1" ]; then 209 | return 210 | fi 211 | 212 | local content="$1" 213 | body="{\"content\":\"$content\"}" 214 | run "curl -X POST -H 'Content-Type: application/json' -d '$body' \"$MY_WEBHOOK_URL\"" 215 | } 216 | 217 | read_confirm() { 218 | echo 219 | read -p "$(green "$1")" confrim 220 | # 如果 $2 为 true,则取消 echo,否则打印 221 | [ "$2" = false ] || echo 222 | 223 | case $confrim in 224 | [yY] | [yY][eE][sS]) 225 | return 0 226 | ;; 227 | [nN] | [nN][oO]) 228 | return 1 229 | ;; 230 | *) 231 | return 0 232 | ;; 233 | esac 234 | } 235 | 236 | read_input() { 237 | read -p "$(green "$1")" input 238 | case $input in 239 | "") 240 | input="$2" 241 | ;; 242 | esac 243 | echo $input 244 | } 245 | 246 | read_confirm_and_input() { 247 | read -p "$(green "$1")" confrim 248 | case $confrim in 249 | "" | [yY] | [yY][eE][sS]) 250 | confrim="$2" 251 | ;; 252 | [nN] | [nN][oO]) 253 | confrim="" 254 | ;; 255 | esac 256 | echo $confrim 257 | } 258 | 259 | # $1: 选项列表 260 | read_from_options_show() { 261 | if [ -n "$1" ]; then 262 | echo 263 | IFS="|" 264 | index=1 265 | printf "$(cyan "可选项:") \n" 266 | echo "-------------------" 267 | for item in $1; do 268 | echo "$(green "$index.") $(echo "$item" | sed 's/:/ - /')" 269 | index=$(($index + 1)) 270 | done 271 | unset IFS 272 | echo 273 | fi 274 | } 275 | 276 | # $1: 提示文案 277 | # $2: 默认值 278 | # $3: 选项列表 279 | read_from_options() { 280 | option=$(read_input "$1(默认 $2): " "$2") 281 | 282 | IFS="|" 283 | index=1 284 | for item in $3; do 285 | if [ "$option" = "$index" ]; then 286 | IFS=":" 287 | val=$(echo "$item" | cut -d':' -f1) 288 | echo "$val" 289 | break 290 | fi 291 | index=$(($index + 1)) 292 | done 293 | unset IFS 294 | } 295 | 296 | is_ubuntu() { 297 | [ -f /etc/lsb-release ] && grep -q "DISTRIB_ID=Ubuntu" /etc/lsb-release 298 | } 299 | is_centos() { 300 | [ -f /etc/redhat-release ] && grep -q "CentOS" /etc/redhat-release 301 | } 302 | is_debian() { 303 | [ -f /etc/os-release ] && grep -q "ID=debian" /etc/os-release 304 | } 305 | 306 | print_arg_warn 307 | set_var 308 | -------------------------------------------------------------------------------- /zsh/zimfw-install.sh: -------------------------------------------------------------------------------- 1 | # zimfw for CN users 2 | # source: https://github.com/zimfw/install/blob/master/install.zsh 3 | # 4 | 5 | if [[ -z ${ZSH_VERSION} ]]; then 6 | echo 'You must use zsh to run install.zsh' >&2 7 | exit 1 8 | fi 9 | 10 | emulate -L zsh -o EXTENDED_GLOB 11 | 12 | _replace_home() { 13 | local abs_path=${1:A} 14 | local suffix=${abs_path#${${ZDOTDIR:-${HOME}}:A}} 15 | if [[ ${abs_path} != ${suffix} ]]; then 16 | print -R '${ZDOTDIR:-${HOME}}'${suffix} 17 | else 18 | print -R ${1} 19 | fi 20 | } 21 | 22 | typeset -A ZTEMPLATES 23 | readonly CLEAR_LINE=$'\E[2K\r' 24 | ZIM_HOME_STR='${ZDOTDIR:-${HOME}}/.zim' 25 | 26 | # Check Zsh version 27 | autoload -Uz is-at-least && if ! is-at-least 5.2; then 28 | print -u2 -PR "%F{red}x You're using Zsh version ${ZSH_VERSION} and versions < 5.2 are not supported. Please update your Zsh.%f" 29 | return 1 30 | fi 31 | print -PR "%F{green})%f Using Zsh version ${ZSH_VERSION}" 32 | 33 | # Check ZIM_HOME 34 | if (( ! ${+ZIM_HOME} )); then 35 | print -P '%F{green})%f ZIM_HOME not set, using the default one.' 36 | ZIM_HOME=${(e)ZIM_HOME_STR} 37 | elif [[ ${ZIM_HOME} == ${(e)ZIM_HOME_STR} ]]; then 38 | print -P '%F{green})%f Your ZIM_HOME is the default one.' 39 | else 40 | ZIM_HOME_STR=$(_replace_home ${ZIM_HOME}) 41 | print -PR "%F{green})%f Your ZIM_HOME is customized to %B${ZIM_HOME_STR}%b" 42 | fi 43 | if [[ -e ${ZIM_HOME} ]]; then 44 | if [[ -n ${ZIM_HOME}(#qN/^F) ]]; then 45 | print -P '%F{green})%f ZIM_HOME already exists, but is empty.' 46 | else 47 | print -u2 -PR "%F{red}x %B${ZIM_HOME}%b already exists. Please set ZIM_HOME to the path where you want to install Zim.%f" 48 | return 1 49 | fi 50 | fi 51 | 52 | # Check if Zsh is the default shell 53 | if [[ ${SHELL:t} == zsh ]]; then 54 | print -P '%F{green})%f Zsh is your default shell.' 55 | else 56 | readonly ZPATH==zsh 57 | if command chsh -s ${ZPATH}; then 58 | print -PR "%F{green})%f Changed your default shell to %B${ZPATH}%b" 59 | else 60 | print -u2 -PR "%F{yellow}! Could not change your default shell to %B${ZPATH}%b. Please manually change it later.%f" 61 | fi 62 | fi 63 | 64 | # Check if other frameworks are enabled 65 | for ZDOTFILE in /etc/(zsh/)#(z|.z)(shenv|profile|shrc|login)(N) ${ZDOTDIR:-${HOME}}/.z(shenv|profile|shrc|login)(N); do 66 | if grep -Eq "^[^#]*(\\bsource|\\.).*(${ZIM_HOME:t}|\\\$[{]?ZIM_HOME[}]?)/init.zsh\\b" ${ZDOTFILE}; then 67 | print -u2 -P "%F{red}x You seem to have Zim already installed in %B${ZDOTFILE}%b. Please uninstall it first.%f" 68 | return 1 69 | fi 70 | if grep -Eq '^[^#]*(\bsource|\.).*prezto/init.zsh\b' ${ZDOTFILE}; then 71 | print -u2 -P "%F{yellow}! You seem to have prezto enabled in %B${ZDOTFILE}%b. Please disable it.%f" 72 | fi 73 | if grep -Eq '^[^#]*(\bsource|\.).*/oh-my-zsh.sh\b' ${ZDOTFILE}; then 74 | print -u2 -P "%F{yellow}! You seem to have oh-my-zsh enabled in %B${ZDOTFILE}%b. Please disable it.%f" 75 | fi 76 | if grep -Eq '^[^#]*\bantibody\s+bundle\b' ${ZDOTFILE}; then 77 | print -u2 -P "%F{yellow}! You seem to have antibody enabled in %B${ZDOTFILE}%b. Please disable it.%f" 78 | fi 79 | if grep -Eq '^[^#]*\bantigen\s+apply\b' ${ZDOTFILE}; then 80 | print -u2 -P "%F{yellow}! You seem to have antigen enabled in %B${ZDOTFILE}%b. Please disable it.%f" 81 | fi 82 | if grep -Eq '^[^#]*(\bsource|\.).*/zgen.zsh\b' ${ZDOTFILE}; then 83 | print -u2 -P "%F{yellow}! You seem to have zgen enabled in %B${ZDOTFILE}%b. Please disable it.%f" 84 | fi 85 | if grep -Eq '^[^#]*\bzplug\s+load\b' ${ZDOTFILE}; then 86 | print -u2 -P "%F{yellow}! You seem to have zplug enabled in %B${ZDOTFILE}%b. Please disable it.%f" 87 | fi 88 | if grep -Eq '^[^#]*\b(function\s+grml_vcs_info_toggle_colour\b|grml_vcs_info_toggle_colour\s*\(\s*\))' ${ZDOTFILE}; then 89 | print -u2 -P "%F{yellow}! You seem to have grml installed in %B${ZDOTFILE}%b. Please uninstall it.%f" 90 | fi 91 | if grep -Eq '^[^#]*\bcompinit\b' ${ZDOTFILE}; then 92 | print -u2 -P "%F{yellow}! You seem to be already calling %Bcompinit%b in %B${ZDOTFILE}%b. Please remove it, because Zim's completion module will call %Bcompinit%b for you.%f" 93 | fi 94 | if grep -Eq '^[^#]*\bpromptinit\b' ${ZDOTFILE}; then 95 | print -u2 -P "%F{yellow}! You seem to be calling %Bpromptinit%b in %B${ZDOTFILE}%b. Please remove it, because Zim already has a prompt theme for you that does not require %Bpromptinit%b.%f" 96 | fi 97 | done 98 | 99 | declare -A cache 100 | 101 | test_connect() { 102 | local url="${1:-https://github.com}" 103 | local limit=${2:-5} 104 | local now=$(date +%s) 105 | local cache_key="${url}_timestamp" 106 | local last_test_time=${cache[$cache_key]} 107 | 108 | # Check cache for recent result 109 | if [[ -n "$last_test_time" && $((now - last_test_time)) -lt $limit ]]; then 110 | return ${cache["${url}_result"]} 111 | fi 112 | 113 | # Test connection with 1-second timeout 114 | local result=$(curl -s -m 1 -o /dev/null -w "%{http_code}" "$url") 115 | local exit_code=$? 116 | 117 | # Handle curl errors 118 | if [[ $exit_code -ne 0 ]]; then 119 | cache["${url}_result"]=1 120 | cache["${url}_timestamp"]="$now" 121 | return 1 122 | fi 123 | 124 | # Check HTTP status code 125 | if [[ $result -eq 200 ]]; then 126 | cache["${url}_result"]=0 127 | cache["${url}_timestamp"]="$now" 128 | return 0 129 | else 130 | cache["${url}_result"]=1 131 | cache["${url}_timestamp"]="$now" 132 | return 1 133 | fi 134 | } 135 | 136 | # GFW proxy 137 | if test_connect; then 138 | GITHUB_URL="https://github.com/" 139 | ZMODULE_GITHUB="" 140 | else 141 | GITHUB_URL="https://hub.llll.host/" 142 | ZMODULE_GITHUB=$GITHUB_URL 143 | fi 144 | 145 | # Download zimfw script 146 | readonly ZTARGET=${ZIM_HOME}/zimfw.zsh 147 | if ( 148 | command mkdir -p ${ZIM_HOME} || return 1 149 | readonly ZURL="${GITHUB_URL}zimfw/zimfw/releases/latest/download/zimfw.zsh" 150 | if [[ ${+commands[curl]} -ne 0 && -x ${commands[curl]} ]]; then 151 | command curl -fsSL -o ${ZTARGET} ${ZURL} || return 1 152 | elif [[ ${+commands[wget]} -ne 0 && -x ${commands[wget]} ]]; then 153 | command wget -nv -O ${ZTARGET} ${ZURL} || return 1 154 | else 155 | print -u2 -P '%F{red}x Either %Bcurl%b or %Bwget%b are required to download the Zim script.%f' 156 | return 1 157 | fi 158 | ); then 159 | print -PR "%F{green})%f Downloaded the Zim script to %B${ZTARGET}%b" 160 | else 161 | command rm -rf ${ZIM_HOME} 162 | print -u2 -PR "%F{red}x Could not download the Zim script to %B${ZTARGET}%b%f" 163 | return 1 164 | fi 165 | 166 | # Prepend templates 167 | if [[ ${+commands[git]} -ne 0 && -x ${commands[git]} ]]; then 168 | HAS_GIT=1 169 | else 170 | HAS_GIT=0 171 | print -PR '%F{green})%f Git not found, setting degit as the default in your .zshrc file.' 172 | # Also set degit as the defaul in the current shell session, used by the install step. 173 | zstyle ':zim:zmodule' use 'degit' 174 | fi 175 | ZTEMPLATES[zimrc]="# Start configuration added by Zim install {{{ 176 | # 177 | # This is not sourced during shell startup, and it's only used to configure the 178 | # zimfw plugin manager. 179 | # 180 | 181 | # 182 | # Modules 183 | # 184 | 185 | # Sets sane Zsh built-in environment options. 186 | zmodule ${ZMODULE_GITHUB}zimfw/environment 187 | # Applies correct bindkeys for input events. 188 | zmodule ${ZMODULE_GITHUB}zimfw/input 189 | # Sets a custom terminal title. 190 | zmodule ${ZMODULE_GITHUB}zimfw/termtitle 191 | # Utility aliases and functions. Adds colour to ls, grep and less. 192 | zmodule ${ZMODULE_GITHUB}zimfw/utility 193 | # Another modules 194 | # zmodule ${ZMODULE_GITHUB}zimfw/archive 195 | # zmodule ${ZMODULE_GITHUB}zimfw/fzf 196 | # zmodule ${ZMODULE_GITHUB}joke/zim-starship 197 | # zmodule ${ZMODULE_GITHUB}kiesman99/zim-zoxide 198 | zmodule ${ZMODULE_GITHUB}ohmyzsh/ohmyzsh --root plugins/git 199 | zmodule ${ZMODULE_GITHUB}ohmyzsh/ohmyzsh --root plugins/eza 200 | zmodule ${ZMODULE_GITHUB}ohmyzsh/ohmyzsh --root plugins/fzf 201 | zmodule ${ZMODULE_GITHUB}ohmyzsh/ohmyzsh --root plugins/starship 202 | zmodule ${ZMODULE_GITHUB}ohmyzsh/ohmyzsh --root plugins/zoxide 203 | zmodule ${ZMODULE_GITHUB}ohmyzsh/ohmyzsh --root plugins/universalarchive 204 | zmodule ${ZMODULE_GITHUB}ohmyzsh/ohmyzsh --root plugins/docker 205 | zmodule ${ZMODULE_GITHUB}ohmyzsh/ohmyzsh --root plugins/docker-compose 206 | 207 | # 208 | # Prompt 209 | # 210 | 211 | # Exposes to prompts how long the last command took to execute, used by asciiship. 212 | # zmodule duration-info 213 | # Exposes git repository status information to prompts, used by asciiship. 214 | zmodule ${ZMODULE_GITHUB}zimfw/git-info 215 | # A heavily reduced, ASCII-only version of the Spaceship and Starship prompts. 216 | zmodule ${ZMODULE_GITHUB}zimfw/asciiship 217 | 218 | # 219 | # Completion 220 | # 221 | 222 | # Additional completion definitions for Zsh. 223 | zmodule ${ZMODULE_GITHUB}zsh-users/zsh-completions --fpath src 224 | # Enables and configures smart and extensive tab completion. 225 | # completion must be sourced after all modules that add completion definitions. 226 | zmodule ${ZMODULE_GITHUB}zimfw/completion 227 | 228 | # 229 | # Modules that must be initialized last 230 | # 231 | 232 | # Fish-like syntax highlighting for Zsh. 233 | # zsh-users/zsh-syntax-highlighting must be sourced after completion 234 | zmodule ${ZMODULE_GITHUB}zsh-users/zsh-syntax-highlighting 235 | # Fish-like history search (up arrow) for Zsh. 236 | # zsh-users/zsh-history-substring-search must be sourced after zsh-users/zsh-syntax-highlighting 237 | zmodule ${ZMODULE_GITHUB}zsh-users/zsh-history-substring-search 238 | # Fish-like autosuggestions for Zsh. 239 | zmodule ${ZMODULE_GITHUB}zsh-users/zsh-autosuggestions 240 | # }}} End configuration added by Zim install 241 | " 242 | ZTEMPLATES[zshrc]="# Start configuration added by Zim install {{{ 243 | # 244 | # User configuration sourced by interactive shells 245 | # 246 | 247 | # ----------------- 248 | # Zsh configuration 249 | # ----------------- 250 | 251 | # 252 | # History 253 | # 254 | 255 | # Remove older command from the history if a duplicate is to be added. 256 | setopt HIST_IGNORE_ALL_DUPS 257 | 258 | # 259 | # Input/output 260 | # 261 | 262 | # Set editor default keymap to emacs (\`-e\`) or vi (\`-v\`) 263 | bindkey -e 264 | 265 | # Prompt for spelling correction of commands. 266 | #setopt CORRECT 267 | 268 | # Customize spelling correction prompt. 269 | #SPROMPT='zsh: correct %F{red}%R%f to %F{green}%r%f [nyae]? ' 270 | 271 | # Remove path separator from WORDCHARS. 272 | WORDCHARS=\${WORDCHARS//[\\/]} 273 | 274 | # ----------------- 275 | # Zim configuration 276 | # ----------------- 277 | 278 | # Use degit instead of git as the default tool to install and update modules. 279 | #zstyle ':zim:zmodule' use 'degit' 280 | 281 | # -------------------- 282 | # Module configuration 283 | # -------------------- 284 | 285 | # 286 | # git 287 | # 288 | 289 | # Set a custom prefix for the generated aliases. The default prefix is 'G'. 290 | #zstyle ':zim:git' aliases-prefix 'g' 291 | 292 | # 293 | # input 294 | # 295 | 296 | # Append \`../\` to your input for each \`.\` you type after an initial \`..\` 297 | #zstyle ':zim:input' double-dot-expand yes 298 | 299 | # 300 | # termtitle 301 | # 302 | 303 | # Set a custom terminal title format using prompt expansion escape sequences. 304 | # See http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html#Simple-Prompt-Escapes 305 | # If none is provided, the default '%n@%m: %~' is used. 306 | #zstyle ':zim:termtitle' format '%1~' 307 | 308 | # 309 | # zsh-autosuggestions 310 | # 311 | 312 | # Disable automatic widget re-binding on each precmd. This can be set when 313 | # zsh-users/zsh-autosuggestions is the last module in your ~/.zimrc. 314 | ZSH_AUTOSUGGEST_MANUAL_REBIND=1 315 | 316 | # Customize the style that the suggestions are shown with. 317 | # See https://github.com/zsh-users/zsh-autosuggestions/blob/master/README.md#suggestion-highlight-style 318 | #ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=242' 319 | 320 | # 321 | # zsh-syntax-highlighting 322 | # 323 | 324 | # Set what highlighters will be used. 325 | # See https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md 326 | ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets) 327 | 328 | # Customize the main highlighter styles. 329 | # See https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters/main.md#how-to-tweak-it 330 | #typeset -A ZSH_HIGHLIGHT_STYLES 331 | #ZSH_HIGHLIGHT_STYLES[comment]='fg=242' 332 | 333 | # ------------------ 334 | # Initialize modules 335 | # ------------------ 336 | 337 | ZIM_HOME=${ZIM_HOME_STR} 338 | # Download zimfw plugin manager if missing. 339 | if [[ ! -e \${ZIM_HOME}/zimfw.zsh ]]; then 340 | if (( \${+commands[curl]} )); then 341 | curl -fsSL --create-dirs -o \${ZIM_HOME}/zimfw.zsh \\ 342 | ${GITHUB_URL}zimfw/zimfw/releases/latest/download/zimfw.zsh 343 | else 344 | mkdir -p \${ZIM_HOME} && wget -nv -O \${ZIM_HOME}/zimfw.zsh \\ 345 | ${GITHUB_URL}zimfw/zimfw/releases/latest/download/zimfw.zsh 346 | fi 347 | fi 348 | # Install missing modules, and update \${ZIM_HOME}/init.zsh if missing or outdated. 349 | if [[ ! \${ZIM_HOME}/init.zsh -nt \${ZDOTDIR:-\${HOME}}/.zimrc ]]; then 350 | source \${ZIM_HOME}/zimfw.zsh init -q 351 | fi 352 | # Initialize modules. 353 | source \${ZIM_HOME}/init.zsh 354 | 355 | # ------------------------------ 356 | # Post-init module configuration 357 | # ------------------------------ 358 | 359 | # 360 | # zsh-history-substring-search 361 | # 362 | 363 | zmodload -F zsh/terminfo +p:terminfo 364 | # Bind ^[[A/^[[B manually so up/down works both before and after zle-line-init 365 | for key ('^[[A' '^P' \${terminfo[kcuu1]}) bindkey \${key} history-substring-search-up 366 | for key ('^[[B' '^N' \${terminfo[kcud1]}) bindkey \${key} history-substring-search-down 367 | for key ('k') bindkey -M vicmd \${key} history-substring-search-up 368 | for key ('j') bindkey -M vicmd \${key} history-substring-search-down 369 | unset key 370 | # }}} End configuration added by Zim install 371 | " 372 | for ZTEMPLATE in ${(k)ZTEMPLATES}; do 373 | USER_FILE=${${:-${ZDOTDIR:-${HOME}}/.${ZTEMPLATE}}:A} 374 | if ERR=$(command mv -f =( 375 | if [[ ${ZTEMPLATE} == zshrc && ${HAS_GIT} -eq 0 ]]; then 376 | print -R "${(F)${(@f)ZTEMPLATES[${ZTEMPLATE}]}/(#b)\#(zstyle*degit*)/$match[1]}" 377 | else 378 | print -R ${ZTEMPLATES[${ZTEMPLATE}]} 379 | fi 380 | if [[ -e ${USER_FILE} ]] cat ${USER_FILE} 381 | ) ${USER_FILE} 2>&1); then 382 | print -PR "%F{green})%f Prepended Zim template to %B${USER_FILE}%b" 383 | else 384 | print -u2 -PlR "%F{red}x Error prepending Zim template to %B${USER_FILE}%b%f" ${ERR} 385 | return 1 386 | fi 387 | done 388 | 389 | print -n 'Installing modules ...' 390 | if ERR=$(source ${ZIM_HOME}/zimfw.zsh init -q 2>&1); then 391 | print -P ${CLEAR_LINE}'%F{green})%f Installed modules.' 392 | else 393 | print -u2 -PlR "${CLEAR_LINE}${ERR}" '%F{red}x Could not install modules.%f' 394 | return 1 395 | fi 396 | 397 | print -P ${CLEAR_LINE}'All done. Enjoy your Zsh IMproved! Restart your terminal for changes to take effect.' 398 | 399 | -------------------------------------------------------------------------------- /coolify/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ## Do not modify this file. You will lose the ability to install and auto-update! 3 | 4 | set -e # Exit immediately if a command exits with a non-zero status 5 | ## $1 could be empty, so we need to disable this check 6 | #set -u # Treat unset variables as an error and exit 7 | set -o pipefail # Cause a pipeline to return the status of the last command that exited with a non-zero status 8 | CDN="https://cdn.coollabs.io/coolify" 9 | DATE=$(date +"%Y%m%d-%H%M%S") 10 | 11 | VERSION="1.6" 12 | DOCKER_VERSION="26.0" 13 | # TODO: Ask for a user 14 | CURRENT_USER=$USER 15 | 16 | mkdir -p /data/coolify/{source,ssh,applications,databases,backups,services,proxy,webhooks-during-maintenance,metrics,logs} 17 | mkdir -p /data/coolify/ssh/{keys,mux} 18 | mkdir -p /data/coolify/proxy/dynamic 19 | 20 | chown -R 9999:root /data/coolify 21 | chmod -R 700 /data/coolify 22 | 23 | INSTALLATION_LOG_WITH_DATE="/data/coolify/source/installation-${DATE}.log" 24 | 25 | exec > >(tee -a $INSTALLATION_LOG_WITH_DATE) 2>&1 26 | 27 | getAJoke() { 28 | JOKES=$(curl -s --max-time 2 "https://v2.jokeapi.dev/joke/Programming?blacklistFlags=nsfw,religious,political,racist,sexist,explicit&format=txt&type=single" || true) 29 | if [ "$JOKES" != "" ]; then 30 | echo -e " - Until then, here's a joke for you:\n" 31 | echo -e "$JOKES\n" 32 | fi 33 | } 34 | 35 | read_confirm() { 36 | echo 37 | read -p "$1" confrim 38 | case $confrim in 39 | [yY] | [yY][eE][sS]) 40 | return 0 41 | ;; 42 | [nN] | [nN][oO]) 43 | return 1 44 | ;; 45 | *) 46 | return 0 47 | ;; 48 | esac 49 | } 50 | 51 | OS_TYPE=$(grep -w "ID" /etc/os-release | cut -d "=" -f 2 | tr -d '"') 52 | ENV_FILE="/data/coolify/source/.env" 53 | 54 | # Check if the OS is manjaro, if so, change it to arch 55 | if [ "$OS_TYPE" = "manjaro" ] || [ "$OS_TYPE" = "manjaro-arm" ]; then 56 | OS_TYPE="arch" 57 | fi 58 | 59 | # Check if the OS is Asahi Linux, if so, change it to fedora 60 | if [ "$OS_TYPE" = "fedora-asahi-remix" ]; then 61 | OS_TYPE="fedora" 62 | fi 63 | 64 | # Check if the OS is popOS, if so, change it to ubuntu 65 | if [ "$OS_TYPE" = "pop" ]; then 66 | OS_TYPE="ubuntu" 67 | fi 68 | 69 | # Check if the OS is linuxmint, if so, change it to ubuntu 70 | if [ "$OS_TYPE" = "linuxmint" ]; then 71 | OS_TYPE="ubuntu" 72 | fi 73 | 74 | #Check if the OS is zorin, if so, change it to ubuntu 75 | if [ "$OS_TYPE" = "zorin" ]; then 76 | OS_TYPE="ubuntu" 77 | fi 78 | 79 | if [ "$OS_TYPE" = "arch" ] || [ "$OS_TYPE" = "archarm" ]; then 80 | OS_VERSION="rolling" 81 | else 82 | OS_VERSION=$(grep -w "VERSION_ID" /etc/os-release | cut -d "=" -f 2 | tr -d '"') 83 | fi 84 | 85 | # Install xargs on Amazon Linux 2023 - lol 86 | if [ "$OS_TYPE" = 'amzn' ]; then 87 | dnf install -y findutils >/dev/null 88 | fi 89 | 90 | LATEST_VERSION=$(curl --silent $CDN/versions.json | grep -i version | xargs | awk '{print $2}' | tr -d ',') 91 | LATEST_HELPER_VERSION=$(curl --silent $CDN/versions.json | grep -i version | xargs | awk '{print $6}' | tr -d ',') 92 | LATEST_REALTIME_VERSION=$(curl --silent $CDN/versions.json | grep -i version | xargs | awk '{print $8}' | tr -d ',') 93 | 94 | if [ -z "$LATEST_HELPER_VERSION" ]; then 95 | LATEST_HELPER_VERSION=latest 96 | fi 97 | 98 | if [ -z "$LATEST_REALTIME_VERSION" ]; then 99 | LATEST_REALTIME_VERSION=latest 100 | fi 101 | 102 | if [ $EUID != 0 ]; then 103 | echo "Please run as root" 104 | exit 105 | fi 106 | 107 | case "$OS_TYPE" in 108 | arch | ubuntu | debian | raspbian | centos | fedora | rhel | ol | rocky | sles | opensuse-leap | opensuse-tumbleweed | almalinux | amzn | alpine) ;; 109 | *) 110 | echo "This script only supports Debian, Redhat, Arch Linux, Alpine Linux, or SLES based operating systems for now." 111 | exit 112 | ;; 113 | esac 114 | 115 | # Overwrite LATEST_VERSION if user pass a version number 116 | if [ "$1" != "" ]; then 117 | LATEST_VERSION=$1 118 | LATEST_VERSION="${LATEST_VERSION,,}" 119 | LATEST_VERSION="${LATEST_VERSION#v}" 120 | fi 121 | 122 | echo -e "\033[0;35m" 123 | cat <<"EOF" 124 | _____ _ _ __ 125 | / ____| | (_)/ _| 126 | | | ___ ___ | |_| |_ _ _ 127 | | | / _ \ / _ \| | | _| | | | 128 | | |___| (_) | (_) | | | | | |_| | 129 | \_____\___/ \___/|_|_|_| \__, | 130 | __/ | 131 | |___/ 132 | EOF 133 | echo -e "\033[0m" 134 | echo -e "Welcome to Coolify Installer!" 135 | echo -e "This script will install everything for you. Sit back and relax." 136 | echo -e "Source code: https://github.com/coollabsio/coolify/blob/main/scripts/install.sh\n" 137 | echo -e "---------------------------------------------" 138 | echo "| Operating System | $OS_TYPE $OS_VERSION" 139 | echo "| Docker | $DOCKER_VERSION" 140 | echo "| Coolify | $LATEST_VERSION" 141 | echo "| Helper | $LATEST_HELPER_VERSION" 142 | echo "| Realtime | $LATEST_REALTIME_VERSION" 143 | echo -e "---------------------------------------------\n" 144 | echo -e "1. Installing required packages (curl, wget, git, jq). " 145 | 146 | case "$OS_TYPE" in 147 | arch) 148 | pacman -Sy --noconfirm --needed curl wget git jq >/dev/null || true 149 | ;; 150 | alpine) 151 | sed -i '/^#.*\/community/s/^#//' /etc/apk/repositories 152 | apk update >/dev/null 153 | apk add curl wget git jq >/dev/null 154 | ;; 155 | ubuntu | debian | raspbian) 156 | apt-get update -y >/dev/null 157 | apt-get install -y curl wget git jq >/dev/null 158 | ;; 159 | centos | fedora | rhel | ol | rocky | almalinux | amzn) 160 | if [ "$OS_TYPE" = "amzn" ]; then 161 | dnf install -y wget git jq >/dev/null 162 | else 163 | if ! command -v dnf >/dev/null; then 164 | yum install -y dnf >/dev/null 165 | fi 166 | if ! command -v curl >/dev/null; then 167 | dnf install -y curl >/dev/null 168 | fi 169 | dnf install -y wget git jq >/dev/null 170 | fi 171 | ;; 172 | sles | opensuse-leap | opensuse-tumbleweed) 173 | zypper refresh >/dev/null 174 | zypper install -y curl wget git jq >/dev/null 175 | ;; 176 | *) 177 | echo "This script only supports Debian, Redhat, Arch Linux, or SLES based operating systems for now." 178 | exit 179 | ;; 180 | esac 181 | 182 | echo -e "2. Check OpenSSH server configuration. " 183 | 184 | # Detect OpenSSH server 185 | SSH_DETECTED=false 186 | if [ -x "$(command -v systemctl)" ]; then 187 | if systemctl status sshd >/dev/null 2>&1; then 188 | echo " - OpenSSH server is installed." 189 | SSH_DETECTED=true 190 | elif systemctl status ssh >/dev/null 2>&1; then 191 | echo " - OpenSSH server is installed." 192 | SSH_DETECTED=true 193 | fi 194 | elif [ -x "$(command -v service)" ]; then 195 | if service sshd status >/dev/null 2>&1; then 196 | echo " - OpenSSH server is installed." 197 | SSH_DETECTED=true 198 | elif service ssh status >/dev/null 2>&1; then 199 | echo " - OpenSSH server is installed." 200 | SSH_DETECTED=true 201 | fi 202 | fi 203 | if [ "$SSH_DETECTED" = "false" ]; then 204 | echo "###############################################################################" 205 | echo "WARNING: Could not detect if OpenSSH server is installed and running - this does not mean that it is not installed, just that we could not detect it." 206 | echo -e "Please make sure it is set, otherwise Coolify cannot connect to the host system. \n" 207 | echo "###############################################################################" 208 | fi 209 | 210 | # Detect SSH PermitRootLogin 211 | SSH_PERMIT_ROOT_LOGIN=$(sshd -T | grep -i "permitrootlogin" | awk '{print $2}') || true 212 | if [ "$SSH_PERMIT_ROOT_LOGIN" = "yes" ] || [ "$SSH_PERMIT_ROOT_LOGIN" = "without-password" ] || [ "$SSH_PERMIT_ROOT_LOGIN" = "prohibit-password" ]; then 213 | echo " - SSH PermitRootLogin is enabled." 214 | else 215 | echo " - SSH PermitRootLogin is disabled." 216 | echo " If you have problems with SSH, please read this: https://coolify.io/docs/knowledge-base/server/openssh" 217 | fi 218 | 219 | # Detect if docker is installed via snap 220 | if [ -x "$(command -v snap)" ]; then 221 | SNAP_DOCKER_INSTALLED=$(snap list docker >/dev/null 2>&1 && echo "true" || echo "false") 222 | if [ "$SNAP_DOCKER_INSTALLED" = "true" ]; then 223 | echo " - Docker is installed via snap." 224 | echo " Please note that Coolify does not support Docker installed via snap." 225 | echo " Please remove Docker with snap (snap remove docker) and reexecute this script." 226 | exit 1 227 | fi 228 | fi 229 | 230 | if grep -iq "Microsoft" /proc/version; then 231 | echo 232 | echo " - This is WSL" 233 | echo -e "3. Check Docker Installation. " 234 | if ! [ -x "$(command -v docker)" ]; then 235 | echo " - Please start docker-desktop before continuing." 236 | exit 1 237 | else 238 | echo " - Docker is installed." 239 | fi 240 | 241 | echo -e "4. Check Docker Configuration. " 242 | echo -e " - Manually check Docker configuration on WSL. " 243 | echo "{ 244 | "log-driver": "json-file", 245 | "log-opts": { 246 | "max-size": "10m", 247 | "max-file": "3" 248 | } 249 | }" 250 | if read_confirm "Manually check Docker configuration on docker desktop?(y/n): "; then 251 | echo " - Continuing with the installation." 252 | else 253 | echo " - Please check Docker configuration and restart Docker." 254 | exit 1 255 | fi 256 | else 257 | echo " - This is not WSL" 258 | echo -e "3. Check Docker Installation. " 259 | if ! [ -x "$(command -v docker)" ]; then 260 | echo " - Docker is not installed. Installing Docker. It may take a while." 261 | getAJoke 262 | case "$OS_TYPE" in 263 | "almalinux") 264 | dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo >/dev/null 2>&1 265 | dnf install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin >/dev/null 2>&1 266 | if ! [ -x "$(command -v docker)" ]; then 267 | echo " - Docker could not be installed automatically. Please visit https://docs.docker.com/engine/install/ and install Docker manually to continue." 268 | exit 1 269 | fi 270 | systemctl start docker >/dev/null 2>&1 271 | systemctl enable docker >/dev/null 2>&1 272 | ;; 273 | "alpine") 274 | apk add docker docker-cli-compose >/dev/null 2>&1 275 | rc-update add docker default >/dev/null 2>&1 276 | service docker start >/dev/null 2>&1 277 | if ! [ -x "$(command -v docker)" ]; then 278 | echo " - Failed to install Docker with apk. Try to install it manually." 279 | echo " Please visit https://wiki.alpinelinux.org/wiki/Docker for more information." 280 | exit 1 281 | fi 282 | ;; 283 | "arch") 284 | pacman -Sy docker docker-compose --noconfirm >/dev/null 2>&1 285 | systemctl enable docker.service >/dev/null 2>&1 286 | if ! [ -x "$(command -v docker)" ]; then 287 | echo " - Failed to install Docker with pacman. Try to install it manually." 288 | echo " Please visit https://wiki.archlinux.org/title/docker for more information." 289 | exit 1 290 | fi 291 | ;; 292 | "amzn") 293 | dnf install docker -y >/dev/null 2>&1 294 | DOCKER_CONFIG=${DOCKER_CONFIG:-/usr/local/lib/docker} 295 | mkdir -p $DOCKER_CONFIG/cli-plugins >/dev/null 2>&1 296 | curl -sL https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o $DOCKER_CONFIG/cli-plugins/docker-compose >/dev/null 2>&1 297 | chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose >/dev/null 2>&1 298 | systemctl start docker >/dev/null 2>&1 299 | systemctl enable docker >/dev/null 2>&1 300 | if ! [ -x "$(command -v docker)" ]; then 301 | echo " - Failed to install Docker with dnf. Try to install it manually." 302 | echo " Please visit https://www.cyberciti.biz/faq/how-to-install-docker-on-amazon-linux-2/ for more information." 303 | exit 1 304 | fi 305 | ;; 306 | *) 307 | curl -s https://releases.rancher.com/install-docker/${DOCKER_VERSION}.sh | sh >/dev/null 2>&1 308 | if ! [ -x "$(command -v docker)" ]; then 309 | curl -s https://get.docker.com | sh -s -- --version ${DOCKER_VERSION} >/dev/null 2>&1 310 | if ! [ -x "$(command -v docker)" ]; then 311 | echo " - Docker installation failed." 312 | echo " Maybe your OS is not supported?" 313 | echo " - Please visit https://docs.docker.com/engine/install/ and install Docker manually to continue." 314 | exit 1 315 | fi 316 | fi 317 | ;; 318 | esac 319 | echo " - Docker installed successfully." 320 | else 321 | echo " - Docker is installed." 322 | fi 323 | 324 | echo -e "4. Check Docker Configuration. " 325 | mkdir -p /etc/docker 326 | # shellcheck disable=SC2015 327 | test -s /etc/docker/daemon.json && cp /etc/docker/daemon.json /etc/docker/daemon.json.original-"$DATE" || cat >/etc/docker/daemon.json </etc/docker/daemon.json.coolify <"$TEMP_FILE"; then 347 | echo "Error merging JSON files" 348 | exit 1 349 | fi 350 | mv "$TEMP_FILE" /etc/docker/daemon.json 351 | 352 | restart_docker_service() { 353 | # Check if systemctl is available 354 | if command -v systemctl >/dev/null 2>&1; then 355 | echo " - Using systemctl to restart Docker." 356 | systemctl restart docker 357 | 358 | if [ $? -eq 0 ]; then 359 | echo " - Docker restarted successfully using systemctl." 360 | else 361 | echo " - Failed to restart Docker using systemctl." 362 | return 1 363 | fi 364 | 365 | # Check if service command is available 366 | elif command -v service >/dev/null 2>&1; then 367 | echo " - Using service command to restart Docker." 368 | service docker restart 369 | 370 | if [ $? -eq 0 ]; then 371 | echo " - Docker restarted successfully using service." 372 | else 373 | echo " - Failed to restart Docker using service." 374 | return 1 375 | fi 376 | 377 | # If neither systemctl nor service is available 378 | else 379 | echo " - Neither systemctl nor service command is available on this system." 380 | return 1 381 | fi 382 | } 383 | 384 | if [ -s /etc/docker/daemon.json.original-"$DATE" ]; then 385 | DIFF=$(diff <(jq --sort-keys . /etc/docker/daemon.json) <(jq --sort-keys . /etc/docker/daemon.json.original-"$DATE")) 386 | if [ "$DIFF" != "" ]; then 387 | echo " - Docker configuration updated, restart docker daemon..." 388 | restart_docker_service 389 | else 390 | echo " - Docker configuration is up to date." 391 | fi 392 | else 393 | echo " - Docker configuration updated, restart docker daemon..." 394 | restart_docker_service 395 | fi 396 | fi 397 | 398 | echo -e "5. Download required files from CDN. " 399 | curl -fsSL $CDN/docker-compose.yml -o /data/coolify/source/docker-compose.yml 400 | curl -fsSL $CDN/docker-compose.prod.yml -o /data/coolify/source/docker-compose.prod.yml 401 | curl -fsSL $CDN/.env.production -o /data/coolify/source/.env.production 402 | curl -fsSL $CDN/upgrade.sh -o /data/coolify/source/upgrade.sh 403 | 404 | echo -e "6. Make backup of .env to .env-$DATE" 405 | 406 | # Copy .env.example if .env does not exist 407 | if [ -f $ENV_FILE ]; then 408 | cp $ENV_FILE $ENV_FILE-$DATE 409 | else 410 | echo " - File does not exist: $ENV_FILE" 411 | echo " - Copying .env.production to .env-$DATE" 412 | cp /data/coolify/source/.env.production $ENV_FILE-$DATE 413 | # Generate a secure APP_ID and APP_KEY 414 | sed -i "s|^APP_ID=.*|APP_ID=$(openssl rand -hex 16)|" "$ENV_FILE-$DATE" 415 | sed -i "s|^APP_KEY=.*|APP_KEY=base64:$(openssl rand -base64 32)|" "$ENV_FILE-$DATE" 416 | 417 | # Generate a secure Postgres DB username and password 418 | # Causes issues: database "random-user" does not exist 419 | # sed -i "s|^DB_USERNAME=.*|DB_USERNAME=$(openssl rand -hex 16)|" "$ENV_FILE-$DATE" 420 | sed -i "s|^DB_PASSWORD=.*|DB_PASSWORD=$(openssl rand -base64 32)|" "$ENV_FILE-$DATE" 421 | 422 | # Generate a secure Redis password 423 | sed -i "s|^REDIS_PASSWORD=.*|REDIS_PASSWORD=$(openssl rand -base64 32)|" "$ENV_FILE-$DATE" 424 | 425 | # Generate secure Pusher credentials 426 | sed -i "s|^PUSHER_APP_ID=.*|PUSHER_APP_ID=$(openssl rand -hex 32)|" "$ENV_FILE-$DATE" 427 | sed -i "s|^PUSHER_APP_KEY=.*|PUSHER_APP_KEY=$(openssl rand -hex 32)|" "$ENV_FILE-$DATE" 428 | sed -i "s|^PUSHER_APP_SECRET=.*|PUSHER_APP_SECRET=$(openssl rand -hex 32)|" "$ENV_FILE-$DATE" 429 | fi 430 | 431 | # Merge .env and .env.production. New values will be added to .env 432 | echo -e "7. Propagating .env with new values - if necessary." 433 | awk -F '=' '!seen[$1]++' "$ENV_FILE-$DATE" /data/coolify/source/.env.production >$ENV_FILE 434 | 435 | if [ "$AUTOUPDATE" = "false" ]; then 436 | if ! grep -q "AUTOUPDATE=" /data/coolify/source/.env; then 437 | echo "AUTOUPDATE=false" >>/data/coolify/source/.env 438 | else 439 | sed -i "s|AUTOUPDATE=.*|AUTOUPDATE=false|g" /data/coolify/source/.env 440 | fi 441 | fi 442 | echo -e "8. Checking for SSH key for localhost access." 443 | if [ ! -f ~/.ssh/authorized_keys ]; then 444 | mkdir -p ~/.ssh 445 | chmod 700 ~/.ssh 446 | touch ~/.ssh/authorized_keys 447 | chmod 600 ~/.ssh/authorized_keys 448 | fi 449 | 450 | set +e 451 | IS_COOLIFY_VOLUME_EXISTS=$(docker volume ls | grep coolify-db | wc -l) 452 | set -e 453 | 454 | if [ "$IS_COOLIFY_VOLUME_EXISTS" -eq 0 ]; then 455 | echo " - Generating SSH key." 456 | ssh-keygen -t ed25519 -a 100 -f /data/coolify/ssh/keys/id.$CURRENT_USER@host.docker.internal -q -N "" -C coolify 457 | chown 9999 /data/coolify/ssh/keys/id.$CURRENT_USER@host.docker.internal 458 | sed -i "/coolify/d" ~/.ssh/authorized_keys 459 | cat /data/coolify/ssh/keys/id.$CURRENT_USER@host.docker.internal.pub >>~/.ssh/authorized_keys 460 | rm -f /data/coolify/ssh/keys/id.$CURRENT_USER@host.docker.internal.pub 461 | fi 462 | 463 | chown -R 9999:root /data/coolify 464 | chmod -R 700 /data/coolify 465 | 466 | echo -e "9. Installing Coolify ($LATEST_VERSION)" 467 | echo -e " - It could take a while based on your server's performance, network speed, stars, etc." 468 | echo -e " - Please wait." 469 | getAJoke 470 | 471 | bash /data/coolify/source/upgrade.sh "${LATEST_VERSION:-latest}" "${LATEST_HELPER_VERSION:-latest}" 472 | echo " - Coolify installed successfully." 473 | rm -f $ENV_FILE-$DATE 474 | 475 | echo " - Waiting for 20 seconds for Coolify (database migrations) to be ready." 476 | getAJoke 477 | 478 | sleep 20 479 | echo -e "\033[0;35m 480 | ____ _ _ _ _ _ 481 | / ___|___ _ __ __ _ _ __ __ _| |_ _ _| | __ _| |_(_) ___ _ __ ___| | 482 | | | / _ \| '_ \ / _\` | '__/ _\` | __| | | | |/ _\` | __| |/ _ \| '_ \/ __| | 483 | | |__| (_) | | | | (_| | | | (_| | |_| |_| | | (_| | |_| | (_) | | | \__ \_| 484 | \____\___/|_| |_|\__, |_| \__,_|\__|\__,_|_|\__,_|\__|_|\___/|_| |_|___(_) 485 | |___/ 486 | \033[0m" 487 | echo -e "\nYour instance is ready to use." 488 | echo -e "Please visit http://$(curl -4s https://ifconfig.io):8000 to get started.\n" 489 | echo -e "WARNING: We recommend you to backup your /data/coolify/source/.env file to a safe location, outside of this server." 490 | cp /data/coolify/source/.env /data/coolify/source/.env.backup 491 | --------------------------------------------------------------------------------