|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright (c) 2021-2025 community-scripts ORG |
| 4 | +# Author: j4v3 (j4v3) |
| 5 | +# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE |
| 6 | +# Source: https://github.com/atuinsh/atuin |
| 7 | + |
| 8 | +# Import Functions und Setup |
| 9 | +source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" |
| 10 | +color |
| 11 | +verb_ip6 |
| 12 | +catch_errors |
| 13 | +setting_up_container |
| 14 | +network_check |
| 15 | +update_os |
| 16 | + |
| 17 | +# Installing Dependencies |
| 18 | +msg_info "Installing Dependencies" |
| 19 | +$STD apt-get install -y \ |
| 20 | + curl \ |
| 21 | + pkg-config \ |
| 22 | + libssl-dev \ |
| 23 | + protobuf-compiler \ |
| 24 | + postgresql \ |
| 25 | + postgresql-contrib |
| 26 | + |
| 27 | +# Configure PostgreSQL |
| 28 | +msg_info "Configuring PostgreSQL" |
| 29 | +# Start PostgreSQL service |
| 30 | +$STD systemctl start postgresql |
| 31 | +$STD systemctl enable postgresql |
| 32 | + |
| 33 | +# Create a database and user for Atuin |
| 34 | +$STD sudo -u postgres psql -c "CREATE USER atuin WITH PASSWORD 'atuin';" |
| 35 | +$STD sudo -u postgres psql -c "CREATE DATABASE atuin OWNER atuin;" |
| 36 | +$STD sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE atuin TO atuin;" |
| 37 | + |
| 38 | +# Allow local connections (no remote PostgreSQL access needed) |
| 39 | +$STD sed -i "s/#listen_addresses = 'localhost'/listen_addresses = 'localhost'/g" /etc/postgresql/*/main/postgresql.conf |
| 40 | +$STD systemctl restart postgresql |
| 41 | +msg_ok "Configured PostgreSQL" |
| 42 | + |
| 43 | +# Install Atuin using the official setup script |
| 44 | +msg_info "Installing Atuin" |
| 45 | +$STD curl --proto '=https' --tlsv1.2 -LsSf https://setup.atuin.sh | sh |
| 46 | + |
| 47 | +# Get the installed version |
| 48 | +ATUIN_VERSION=$(~/.atuin/bin/atuin --version | awk '{print $2}') |
| 49 | +msg_ok "Installed Atuin v${ATUIN_VERSION}" |
| 50 | + |
| 51 | +# Create a symlink in /usr/local/bin for easy access |
| 52 | +msg_info "Creating symlink for global access" |
| 53 | +$STD ln -sf ~/.atuin/bin/atuin /usr/local/bin/atuin |
| 54 | +msg_ok "Created symlink" |
| 55 | + |
| 56 | +# Setup Atuin Server |
| 57 | +msg_info "Setting up Atuin Server" |
| 58 | +mkdir -p /etc/atuin/ |
| 59 | + |
| 60 | +# Create server configuration |
| 61 | +cat <<EOF >/etc/atuin/server.toml |
| 62 | +# Atuin server configuration |
| 63 | +host = "0.0.0.0" |
| 64 | +port = 8888 |
| 65 | +open_registration = true |
| 66 | +db_uri = "postgres://atuin:atuin@localhost/atuin" |
| 67 | +EOF |
| 68 | + |
| 69 | +# Create systemd service for Atuin server |
| 70 | +cat <<EOF >/etc/systemd/system/atuin-server.service |
| 71 | +[Unit] |
| 72 | +Description=Atuin sync server |
| 73 | +After=network.target postgresql.service |
| 74 | +
|
| 75 | +[Service] |
| 76 | +Type=simple |
| 77 | +ExecStart=/usr/local/bin/atuin server start --config /etc/atuin/server.toml |
| 78 | +Restart=always |
| 79 | +User=root |
| 80 | +
|
| 81 | +[Install] |
| 82 | +WantedBy=multi-user.target |
| 83 | +EOF |
| 84 | + |
| 85 | +# Enable and start the Atuin server service |
| 86 | +$STD systemctl enable atuin-server |
| 87 | +$STD systemctl start atuin-server |
| 88 | +msg_ok "Setup Atuin Server" |
| 89 | + |
| 90 | +# Enable shell integration for local usage |
| 91 | +msg_info "Setting up shell integration" |
| 92 | + |
| 93 | +# For ZSH |
| 94 | +if [ -f /bin/zsh ] || [ -f /usr/bin/zsh ]; then |
| 95 | + $STD echo 'eval "$(~/.atuin/bin/atuin init zsh)"' >>/etc/zsh/zshrc |
| 96 | +fi |
| 97 | + |
| 98 | +# For Bash |
| 99 | +if [ -f /bin/bash ] || [ -f /usr/bin/bash ]; then |
| 100 | + # Install bash-preexec for bash integration |
| 101 | + $STD curl https://raw.githubusercontent.com/rcaloras/bash-preexec/master/bash-preexec.sh -o /etc/bash-preexec.sh |
| 102 | + $STD echo '[[ -f /etc/bash-preexec.sh ]] && source /etc/bash-preexec.sh' >>/etc/bash.bashrc |
| 103 | + $STD echo 'eval "$(~/.atuin/bin/atuin init bash)"' >>/etc/bash.bashrc |
| 104 | +fi |
| 105 | + |
| 106 | +msg_ok "Setup shell integration" |
| 107 | + |
| 108 | +# Create server info file |
| 109 | +cat <<EOF >~/atuin-server-info.txt |
| 110 | +Atuin Server Information |
| 111 | +======================== |
| 112 | +
|
| 113 | +Server Version: v${ATUIN_VERSION} |
| 114 | +Server URL: http://$(hostname -I | awk '{print $1}'):8888 |
| 115 | +
|
| 116 | +DATABASE CONFIGURATION: |
| 117 | +---------------------- |
| 118 | +PostgreSQL Database: atuin |
| 119 | +PostgreSQL User: atuin |
| 120 | +PostgreSQL Password: atuin |
| 121 | +
|
| 122 | +SERVER CONFIGURATION: |
| 123 | +------------------- |
| 124 | +Config Location: /etc/atuin/server.toml |
| 125 | +Current Settings: |
| 126 | +- host = 0.0.0.0 (listens on all interfaces) |
| 127 | +- port = 8888 |
| 128 | +- open_registration = true (new users can register) |
| 129 | +- db_uri = postgres://atuin:atuin@localhost/atuin |
| 130 | +
|
| 131 | +You can modify these settings in /etc/atuin/server.toml and restart the server: |
| 132 | +systemctl restart atuin-server |
| 133 | +
|
| 134 | +CONNECTING CLIENTS: |
| 135 | +----------------- |
| 136 | +On client machines, install Atuin and then run: |
| 137 | +
|
| 138 | +1. Configure client to use your server: |
| 139 | + atuin settings update sync_address http://$(hostname -I | awk '{print $1}'):8888 |
| 140 | +
|
| 141 | +2. Register a new account: |
| 142 | + atuin register --username <USERNAME> --password <PASSWORD> |
| 143 | +
|
| 144 | +3. Or login with existing account: |
| 145 | + atuin login --username <USERNAME> --password <PASSWORD> |
| 146 | +
|
| 147 | +4. Start syncing: |
| 148 | + atuin sync |
| 149 | +
|
| 150 | +SECURITY CONSIDERATIONS: |
| 151 | +---------------------- |
| 152 | +- The server has open registration enabled by default |
| 153 | +- To disable open registration, set 'open_registration = false' in the config |
| 154 | +- Consider setting up TLS for secure connections (see documentation) |
| 155 | +- For production environments, consider stronger PostgreSQL credentials |
| 156 | +
|
| 157 | +ENABLING TLS: |
| 158 | +----------- |
| 159 | +To enable TLS, modify /etc/atuin/server.toml to include: |
| 160 | +
|
| 161 | +[tls] |
| 162 | +enable = true |
| 163 | +cert_path = "/path/to/fullchain.pem" |
| 164 | +pkey_path = "/path/to/privkey.pem" |
| 165 | +
|
| 166 | +For more information, visit: https://docs.atuin.sh/self-hosting/server-setup/ |
| 167 | +EOF |
| 168 | + |
| 169 | +motd_ssh |
| 170 | +customize |
| 171 | + |
| 172 | +# Cleanup |
| 173 | +msg_info "Cleaning up" |
| 174 | +$STD apt-get -y autoremove |
| 175 | +$STD apt-get -y autoclean |
| 176 | +msg_ok "Cleaned" |
0 commit comments