1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
|
## Command-Line Arguments
Usage: `install-linux.sh [OPTIONS]`
Options:
`--no-home-policy`
Disables configuration that allows opkssh to see policy files in user's home directory (/home/<username>/auth_id). Greatly simplifies install.
`--no-sshd-restart`
Do not restart SSH after installation.
`--overwrite-config`
Overwrite the currently active sshd configuration for AuthorizedKeysCommand and AuthorizedKeysCommandUser directives.
`--install-from=FILEPATH`
Install using a local file instead of downloading from GitHub.
`--install-version=VERSION`
Install a specific version from GitHub instead of "latest".
- `--help`: Display this help message.
## Environment Variables
| Variable name | Default value | System env override |
|---------------|---------------|---------------------|
| **AUTH_CMD_USER** | `opksshuser` | OPKSSH_INSTALL_AUTH_CMD_USER |
| **AUTH_CMD_GROUP** | `opksshuser` | OPKSSH_INSTALL_AUTH_CMD_GROUP |
| **SUDOERS_PATH** | `/etc/sudoers.d/opkssh` | OPKSSH_INSTALL_SUDOERS_PATH |
| **HOME_POLICY** | `true` | OPKSSH_INSTALL_HOME_POLICY |
| **RESTART_SSH** | `true` | OPKSSH_INSTALL_RESTART_SSH |
| **OVERWRITE_ACTIVE_CONFIG** | `false` | OPKSSH_INSTALL_OVERWRITE_ACTIVE_CONFIG |
| **INSTALL_VERSION** | `latest` | OPKSSH_INSTALL_VERSION |
| **INSTALL_DIR** | `/usr/local/bin` | OPKSSH_INSTALL_DIR |
| **BINARY_NAME** | `opkssh` | OPKSSH_INSTALL_BINARY_NAME |
| **GITHUB_REPO** | `openpubkey/opkssh` | OPKSSH_INSTALL_GITHUB_REPO |
# Script Function Documentation
## `file_exists`
file_exists
check is file exists, helpers that wrap real commands so it can be
overridden in tests
**Arguments:**
- $1 - Path to file
**Returns:**
- 0 if the file exists, otherwise
## `dir_exists`
dir_exists
check is directory exists, helpers that wrap real commands so it can be
overridden in tests
**Arguments:**
- $1 - Path to directory
**Returns:**
- 0 if the directory exists, otherwise
## `check_bash_version`
check_bash_version
Checks if a bash version is >= 3.2
**Arguments:**
- $1 - Major version
- $2 - Minor version
- $3 - Patch lever (optional, not used)
- $4 - Build version (optional, not used)
- $5 - Version string (optional, not used)
- $6 - Vendor (optional, not used)
- $7 - Operating system (optional, not used)
**Returns:**
- 0 if version >= 3.2, 1 otherwise
**Example:**
```bash
check_bash_version "${BASH_VERSINFO[@]}"
```
## `determine_linux_type`
determine_linux_type
Determine the linux type the script is executed in
**Outputs:**
- Writes the current Linux type detected
**Returns:**
- 0 if successful, 1 if it's an unsupported OS
## `check_cpu_architecture`
check_cpu_architecture
Checks the CPU architecture the script is running on
**Outputs:**
- Writes the CPU architechture the script is runnin on
**Returns:**
- 0 if running on supported architectur, 1 otherwise
## `running_as_root`
running_as_root
Checks if the script executes as root
**Arguments:**
- $1 - UID of user to check
**Returns:**
- 0 if running as root, 1 otherwise
## `display_help_message`
display_help_message
Prints script help message to stdout
**Returns:**
- 0 on success
## `ensure_command`
ensure_command
Checks whether a given command is available on the system.
**Arguments:**
- $1 - Name of the command to check (e.g. "curl", "git", "netstat").
- $2 - Name of the package the command is delivered in (e.g. "curl", "git", "net-tools-deprecated" (optional, defauls to $1)
- $3 - OS Type the script is running on, output from function determine_linux_type (optional, default so OS_TYPE)
**Outputs:**
- Writes an error message to stderr if the command is missing and how to install the command on supported OS types.
**Returns:**
- 0 if the command is found, 1 otherwise.
**Example:**
```bash
ensure_command "wget" || exit 1
ensure_command "netstat" "net-tools-deprecated" || exit
```
## `ensure_openssh_server`
ensure_openssh_server
Ensures that openSSH-Server is installed and configuration targets exists
**Arguments:**
- $1 - OS Type the script is running on, output from function determine_linux_type
**Outputs:**
- Writes error if openSSH isn't installed with package manager
- Writes error if it could verify target configuration files for opkssh
**Returns:**
- 0 if openSSH is installed with package manager and configuration files exists, 1 otherwise.
## `ensure_opkssh_user_and_group`
ensure_opkssh_user_and_group
Checks if the group and user used bu AuthorizedKeysCommand exists if not creates it
**Arguments:**
- $1 - AuthorizedKeysCommand User
- $2 - AuthorizedKeysCommand Group
**Outputs:**
- Writes to stdout if group created and if user is created
**Returns:**
- 0 on success
## `parse_args`
parse_args
Parses CLI arguments and sets configuration flags.
**Arguments:**
- $@ - Command-line arguments
**Outputs:**
- Sets global variables: HOME_POLICY, RESTART_SSH, OVERWRITE_ACTIVE_CONFIG,LOCAL_INSTALL_FILE, INSTALL_VERSION.
**Returns:**
- 0 on success, 1 if help is in arguments
## `install_opkssh_binary`
install_opkssh_binary
Installs opkssh binary either from local file or downloads from repository
**Outputs:**
- Writes to stdout if installing from local file or repository or the URL from wher it's downloaded
- Writes to stderr if install path doesn't exist
**Returns:**
- 0 if installation is succeeded, 1 otherwise
## `check_selinux`
check_selinux
Checks if SELinux is enabled and if so, ensures the context is set correctly
**Outputs:**
- Progress of SELinux context installation/configuration or message that SELinux is disabled
**Returns:**
- 0 if SELinux is disabled or if context is correctly
## `configure_opkssh`
configure_opkssh
Creates/checks the opskssh configuration
**Arguments:**
- $1 - Path to etc directory (Optional, default /etc)
**Outputs:**
- Writes to stdout the configration progress
**Returns:**
- 0
## `configure_openssh_server`
configure_openssh_server
Configure openSSH-server to use opkssh using AuthorizedKeysCommand
**Arguments:**
- $1 - Path to ssh root configuratino directory (Optional, default /etc/ssh)
Output:
Writes to stdout the progress of configuration
**Returns:**
- 0 if succeeded, otherwise 1
## `restart_openssh_server`
restart_openssh_server
Checks if RESTART_SSH is true and restarts the openSSH server daemon if that is the case
**Outputs:**
- Writes to stdout the status if the daemon is restarted
- Writes to stdout is set to false and skipping daemon restart
**Returns:**
- 0 if successful, 1 if it's an unsupported OS_TYPE
## `configure_sudo`
configure_sudo
Configures sudo for opkssh if HOME_POLICY is set to true
**Outputs:**
- Writes to stdout the progress of sudo configuration if HOME_POLICY=true
- Writes to stdout that sudo is not configured if HOME_POLICY=false
**Returns:**
- 0
## `log_opkssh_installation`
log_opkssh_installation
Log the installation details to /var/log/opkssh.log to help with debugging
**Arguments:**
- $1 - Path to opkssh log file (Optional, default /var/log/opkssh.log)
Output:
Writes to stdout that installation is successful
Writes installation debug information to /var/log/opkssh.log
**Returns:**
- 0
## `main`
main
Running main function only if executed, not sourced
**Arguments:**
- "$@"
**Returns:**
- 0 if opkssh installs successfully, 1 if installation failed
|