|
1 | 1 | #!/bin/bash -e
|
2 | 2 |
|
3 | 3 | if [ "$EUID" -ne 0 ]; then
|
4 |
| - echo "Please run as root." |
5 |
| - exit 1 |
| 4 | + echo "Please run as root." |
| 5 | + exit 1 |
6 | 6 | fi
|
7 | 7 | if [ "$EUID" -eq 0 ]; then
|
8 |
| - if [ "$SUDO_USER" == "" ]; then # most likely under Docker |
9 |
| - SUDO_USER="root" |
10 |
| - HOME="/root" |
11 |
| - else # most likely as a regular OS installation |
12 |
| - HOME=/home/$SUDO_USER |
13 |
| - fi |
| 8 | + if [ "$SUDO_USER" == "" ]; then # most likely under Docker |
| 9 | + SUDO_USER="root" |
| 10 | + HOME="/root" |
| 11 | + else # most likely as a regular OS installation |
| 12 | + HOME=/home/$SUDO_USER |
| 13 | + fi |
14 | 14 | fi
|
15 | 15 |
|
16 | 16 | run_as_super_user () {
|
17 |
| - if [ "$SUDO_USER" = "root" ]; then |
18 |
| - $1 |
19 |
| - else |
20 |
| - sudo -H -u "$SUDO_USER" bash -c "$1" |
21 |
| - fi |
| 17 | + if [ "$SUDO_USER" = "root" ]; then |
| 18 | + $1 |
| 19 | + else |
| 20 | + sudo -H -u "$SUDO_USER" bash -c "$1" |
| 21 | + fi |
22 | 22 | }
|
23 | 23 |
|
24 |
| -os_distro="" |
25 |
| -if [[ "$OSTYPE" == "linux-gnu"* ]]; then |
26 |
| - if grep -qF "Ubuntu" /etc/os-release ; then |
27 |
| - os_distro="Ubuntu" |
28 |
| - elif grep -qF "Fedora" /etc/os-release ; then |
29 |
| - os_distro="Fedora" |
30 |
| - elif grep -qF "CentOS" /etc/os-release ; then |
31 |
| - os_distro="CentOS" |
32 |
| - else |
33 |
| - echo "Unknown OS" |
34 |
| - exit 1 |
35 |
| - fi |
36 |
| -else |
37 |
| - echo "Unknown OS" |
38 |
| - exit 1 |
39 |
| -fi |
40 |
| -echo "DISTRO: $os_distro" |
41 |
| - |
42 |
| -if [ "$os_distro" = "Ubuntu" ]; then |
43 |
| - apt update -y |
44 |
| - # apt purge -y |
45 |
| - apt install -y wget git vim neovim tmux htop gcc g++ clang clang-format libssl-dev silversearcher-ag fzf shellcheck procps make cmake |
46 |
| -fi |
47 |
| -if [ "$os_distro" = "CentOS" ]; then |
48 |
| - yum update -y |
49 |
| - # dnf remove -y |
50 |
| - yum install -y wget git vim neovim tmux htop gcc g++ clang openssl-devel fzf shellcheck procps-ng make cmake |
51 |
| -fi |
52 |
| -if [ "$os_distro" = "Fedora" ]; then |
53 |
| - dnf update -y |
54 |
| - # dnf remove -y |
55 |
| - dnf install -y wget git vim neovim tmux htop gcc g++ clang openssl-devel fzf shellcheck procps-ng make cmake |
56 |
| -fi |
57 |
| - |
58 |
| -run_as_super_user "mkdir -p $HOME/.ssh" |
59 |
| -run_as_super_user "chmod 700 $HOME/.ssh" |
60 |
| -run_as_super_user "mkdir -p $HOME/Workspace/code" |
61 |
| -run_as_super_user "mkdir -p $HOME/.local" |
62 |
| - |
63 |
| -# https://wiki.archlinux.org/title/SSH_keys |
64 |
| -ssh_agent_setup_path="$HOME/.local/ssh-agent-setup" |
65 |
| -if [ ! -f "$ssh_agent_setup_path" ]; then |
66 |
| - cat >"$ssh_agent_setup_path" << EOF |
| 24 | +setup_system () { |
| 25 | + os_distro="" |
| 26 | + if [[ "$OSTYPE" == "linux-gnu"* ]]; then |
| 27 | + if grep -qF "Ubuntu" /etc/os-release ; then |
| 28 | + os_distro="Ubuntu" |
| 29 | + elif grep -qF "Fedora" /etc/os-release ; then |
| 30 | + os_distro="Fedora" |
| 31 | + elif grep -qF "CentOS" /etc/os-release ; then |
| 32 | + os_distro="CentOS" |
| 33 | + else |
| 34 | + echo "Unknown OS" |
| 35 | + exit 1 |
| 36 | + fi |
| 37 | + else |
| 38 | + echo "Unknown OS" |
| 39 | + exit 1 |
| 40 | + fi |
| 41 | + echo "DISTRO: $os_distro" |
| 42 | + if [ "$os_distro" = "Ubuntu" ]; then |
| 43 | + apt update -y |
| 44 | + # apt purge -y |
| 45 | + apt install -y wget git vim neovim tmux htop gcc g++ clang clang-format libssl-dev silversearcher-ag fzf shellcheck procps make cmake |
| 46 | + fi |
| 47 | + if [ "$os_distro" = "CentOS" ]; then |
| 48 | + yum update -y |
| 49 | + # dnf remove -y |
| 50 | + yum install -y wget git vim neovim tmux htop gcc g++ clang openssl-devel fzf shellcheck procps-ng make cmake |
| 51 | + fi |
| 52 | + if [ "$os_distro" = "Fedora" ]; then |
| 53 | + dnf update -y |
| 54 | + # dnf remove -y |
| 55 | + dnf install -y wget git vim neovim tmux htop gcc g++ clang openssl-devel fzf shellcheck procps-ng make cmake |
| 56 | + fi |
| 57 | + run_as_super_user "mkdir -p $HOME/.ssh" |
| 58 | + run_as_super_user "chmod 700 $HOME/.ssh" |
| 59 | + run_as_super_user "mkdir -p $HOME/.local" |
| 60 | + run_as_super_user "mkdir -p $HOME/Workspace/code" |
| 61 | + # https://wiki.archlinux.org/title/SSH_keys |
| 62 | + ssh_agent_setup_path="$HOME/.local/ssh-agent-setup" |
| 63 | + if [ ! -f "$ssh_agent_setup_path" ]; then |
| 64 | + cat >"$ssh_agent_setup_path" << EOF |
67 | 65 | if ! pgrep -u "$SUDO_USER" ssh-agent > /dev/null; then
|
68 | 66 | ssh-agent -t 24h > "$HOME/.ssh/ssh-agent.env"
|
69 | 67 | fi
|
70 | 68 | if [[ ! -f "$SSH_AUTH_SOCK" ]]; then
|
71 | 69 | source "$HOME/.ssh/ssh-agent.env" >/dev/null
|
72 | 70 | fi
|
73 | 71 | EOF
|
74 |
| -fi |
75 |
| -if ! grep -qF "source $HOME/.local/ssh-agent-setup" "$HOME/.bashrc" ; then |
76 |
| - echo "source $HOME/.local/ssh-agent-setup" >> "$HOME/.bashrc" |
77 |
| -fi |
| 72 | + fi |
| 73 | + if ! grep -qF "source $HOME/.local/ssh-agent-setup" "$HOME/.bashrc" ; then |
| 74 | + echo "source $HOME/.local/ssh-agent-setup" >> "$HOME/.bashrc" |
| 75 | + fi |
| 76 | +} |
78 | 77 |
|
79 |
| -gitconfig_path="$HOME/.gitconfig" |
80 |
| -if [ ! -f "$gitconfig_path" ]; then |
81 |
| - wget https://raw.githubusercontent.com/gitbuda/dotfiles/master/gitconfig -O "$gitconfig_path" |
82 |
| -fi |
83 |
| -gitignore_path="$HOME/.gitignore" |
84 |
| -if [ ! -f "$gitignore_path" ]; then |
85 |
| - wget https://raw.githubusercontent.com/gitbuda/dotfiles/master/gitignore -O "$gitignore_path" |
86 |
| -fi |
| 78 | +setup_dot_files () { |
| 79 | + gitconfig_path="$HOME/.gitconfig" |
| 80 | + if [ ! -f "$gitconfig_path" ]; then |
| 81 | + wget https://raw.githubusercontent.com/gitbuda/dotfiles/master/gitconfig -O "$gitconfig_path" |
| 82 | + fi |
| 83 | + gitignore_path="$HOME/.gitignore" |
| 84 | + if [ ! -f "$gitignore_path" ]; then |
| 85 | + wget https://raw.githubusercontent.com/gitbuda/dotfiles/master/gitignore -O "$gitignore_path" |
| 86 | + fi |
| 87 | + bash_aliases_path="$HOME/.bash_aliases" |
| 88 | + if [ ! -f "$bash_aliases_path" ]; then |
| 89 | + wget https://raw.githubusercontent.com/gitbuda/dotfiles/master/bash_aliases -O "$bash_aliases_path" |
| 90 | + fi |
| 91 | + if ! grep -qF "$bash_aliases_path" "$HOME/.bashrc" ; then |
| 92 | + echo "source $bash_aliases_path" >> "$HOME/.bashrc" |
| 93 | + fi |
| 94 | +} |
87 | 95 |
|
88 |
| -bash_aliases_path="$HOME/.bash_aliases" |
89 |
| -if [ ! -f "$bash_aliases_path" ]; then |
90 |
| - wget https://raw.githubusercontent.com/gitbuda/dotfiles/master/bash_aliases -O "$bash_aliases_path" |
91 |
| -fi |
92 |
| -if ! grep -qF "$bash_aliases_path" "$HOME/.bashrc" ; then |
93 |
| - echo "source $bash_aliases_path" >> "$HOME/.bashrc" |
94 |
| -fi |
| 96 | +setup_system |
| 97 | +setup_dot_files |
0 commit comments