|
1 | 1 | # Arch Installation Script |
2 | 2 |
|
3 | | -A post-installation script for **Arch Linux/EndeavourOS**. It Installs automaticly packages that are declared within the `packages/**/*.txt` files and transfers data from a borgbackup server to the current operating system. |
| 3 | +A post-installation script for **Arch Linux/EndeavourOS**. It Installs half-unattended packages that are declared within the `./src/packages/**/*.txt` files and transfers data from a Borg server to the current operating system. |
4 | 4 |
|
5 | 5 | # Getting Started |
6 | 6 |
|
7 | | -For a complete installation & syncing, make use of `./src/main.sh`. Before that It's recommend to change the mounting location declared in `./src/borgserver.sh`. Also before that you have to configure the connection to your borgbackup server. |
| 7 | +For a complete installation & syncing, make use of `./src/main.sh`. Before it's needed to configure the connection to the Borg server by creating a script named `./src/borg/conf/conf.sh`. Here an example how this configuration script should look like. |
8 | 8 |
|
9 | 9 | ```bash |
10 | 10 | #!/bin/bash |
11 | | -./src/main.sh |
| 11 | + |
| 12 | +# === conn config & auth === |
| 13 | +# reference file |
| 14 | +SSH_KEYFILE="PATH/YOUR-SSHKEY" # location of ssh private key |
| 15 | +# borg repo |
| 16 | +BORG_REPO="ssh://USERNAME@HOSTNAME:PORT/PATH" # repo address *REQUIRED |
| 17 | +BORG_PASSPHRASE="PASSWORD" # repo password *OPTIONAL |
| 18 | +# ssh conn |
| 19 | +BORG_RSH="ssh -i '$SSH_KEYFILE'" # ssh auth *OPTIONAL |
| 20 | + |
| 21 | +# === local config === |
| 22 | +MOUNT_DIR=/tmp/borg # borg archive mount location *REQUIRED |
| 23 | +BORG_HOME="$MOUNT_DIR/home/USERNAME" # borg archive home location *REQUIRED |
12 | 24 | ``` |
13 | 25 |
|
14 | | -## <u> Borgbackup </u> |
15 | 26 |
|
16 | | -Change location of the declared mounting directory `mount_dir` if needed. The location paths that are to transfer from the source (borgbackup archive) to the destination (current OS) are declared as map/dict. Also the script checks if both directories exits and tranfers the data via `rsync` to the destination afterwards. |
17 | 27 |
|
18 | | -### Borgbackup Server |
| 28 | +## <u> Configuration </u> |
| 29 | + |
| 30 | +First of all only the configuration variables `BORG_PASSPHRASE` and `BORG_RSH` are optional. If you are using SSH to communicate with your external Borg server you have to use `BORG_RSH`. But if the targeted Borg server is locally and not through SSH `BORG_RSH` do not set this variable at all. `SSH_KEYFILE` can be ignored if `BORG_RSH` is of no use for you. |
| 31 | + |
| 32 | +Furthermore If `BORG_PASSPHRASE` is set you don't have to input the password by hand but the connection will be directly without user interaction. |
| 33 | + |
| 34 | +## <u> How It Works </u> |
| 35 | + |
| 36 | +If the `./src/main.sh` is started it installs it's required packages via Pacman and after that It loads both core scripts `./src/borg/core.sh` and `./src/packages/core.sh`. Before the real process of installation and recovery starts. The core scripts are checking if, first of all, the package files (`./src/packages/pacman/*.txt`, `./src/packages/**/*.txt`, `...`) are to be found and last but not least if the Borg server is reachable, the connection is successful, archives are found and can be mounted to the desired location. After that the complete process is split in two. Firstly the installation process of every needed package and secoundly the data recovery via Borg and Rsync. And between the user has to confirm that the script should continue it's normal course. This interaction is recommended to keep for checking the results of package installation by hand. |
19 | 37 |
|
20 | | -To get the connection to a running borgbackup server running. You have to define a SSH URL, get your SSH private key ready and declare the repository password. Look for that into the `./src/borgserver.sh`. |
| 38 | +### Packages |
| 39 | + |
| 40 | +If you want to use this as base for a half-unattended install like I'm doing you should change up at least every package file (look below for more). So basicly go through `./src/packages/core.sh`. The package file locations are defined in the `./src/packages/install.sh`. |
| 41 | + |
| 42 | +For base driver I wrote down two package files `./src/packages/amd.txt` and `./src/packages/nvidia.txt`. Because I'm using mainly my Nvidia graphicscard you should change one line if you have a amd graphicscard. Also some driver are written down within `./src/packages/pacman/pkgs.txt`. What for package files are loaded with which packagemanager is written down in the script `./src/packages/core.sh`. |
21 | 43 |
|
22 | 44 | ```bash |
23 | 45 | #!/bin/bash |
24 | | - |
25 | 46 | ... |
| 47 | +install_pkgs() { |
| 48 | + inst_pacman_pkgs $nvidia_pkgs $pacman_pkgs # for nvidia |
| 49 | + inst_pacman_pkgs $amd_pkgs $pacman_pkgs # for amd |
| 50 | + ... |
| 51 | +... |
| 52 | +} |
| 53 | +``` |
| 54 | + |
| 55 | + |
| 56 | +Paste packages to the `**/pkgs.txt` of your choice. Two things are to pay attention. Firstly packages will be seperately placed into a new line and secoundly comments can be made but you can't mix up a line that is used up for a package with a comment line. |
| 57 | + |
| 58 | +#### *Positive Example* |
26 | 59 |
|
27 | | -# borg server |
28 | | -ssh_key="$ROOT_DIR/server/backupserver" # change me |
29 | | -ssh_port=22 # change me |
30 | | -repo="ssh://borg@server:$ssh_port/mnt/repo" # change me |
31 | | -repo_password="$ROOT_DIR/server/pass.txt" # optional |
| 60 | +Here an example how a `**/pkgs.txt` should look like. |
| 61 | + |
| 62 | +```bash |
| 63 | +# comment 1 |
| 64 | +package-1 |
| 65 | +# comment 2 |
| 66 | +package-2 |
| 67 | +# comment 3 |
| 68 | +package-3 |
| 69 | +package-4 |
32 | 70 | ``` |
33 | 71 |
|
34 | | -So `ssh_key`, `ssh_port` (if not port 22) and the `repo` adress has to be definied. The `repo_password` must not be given, but if so you don't have to put in the password for your borgbackup repository by hand. |
| 72 | +And here you can see how the packagemanagers will interpret this example `**/pkgs.txt` file. Flatpak doesn't support token based packages as parameter so one after another packages have to be installed. Pacman and Yay can both chain them together so those both have to execute only one it's installation process. |
35 | 73 |
|
36 | | -## <u> Seperately Setting Up </u> |
| 74 | +```bash |
| 75 | +#!/bin/bash |
| 76 | +# pacman |
| 77 | +sudo pacman -Syu --noconfirm --needed package-1 package-2 package-3 package-4 |
| 78 | +# yay |
| 79 | +yay -Syu --noconfirm --needed package-1 package-2 package-3 package-4 |
| 80 | +# flatpak |
| 81 | +flatpak install -y flathub package-1 |
| 82 | +flatpak install -y flathub package-2 |
| 83 | +flatpak install -y flathub package-3 |
| 84 | +flatpak install -y flathub package-4 |
| 85 | +``` |
| 86 | + |
| 87 | +#### *Negative Example* |
| 88 | + |
| 89 | +Now a bad example how the `**/pkgs.txt` would not work as you expected. |
| 90 | + |
| 91 | +```bash |
| 92 | +package-1 # comment 1 |
| 93 | +package-2 |
| 94 | +``` |
37 | 95 |
|
38 | | -It's also possible to use the scripts `./src/inst.sh` and `./src/borgserver.sh` seperately. The `./src/main.sh` does load first the installation script and after that the borgbackup server script. But only in `./src/main.sh` is the function implemented to keep-alive the sudo permission, so for a unattended installation it's recommended to use that script. |
| 96 | +The first line will be ignored because a `#` symbol so you better not mix them together with package declaration lines. |
39 | 97 |
|
40 | | -### Installation Script |
| 98 | +### Rsync |
41 | 99 |
|
42 | | -To install declared packages with Pacman, Yay and Flatpak. Afterwards it's loading manually the needed kernel modules (also declared in a file) and setting up services like database servers and more. |
| 100 | +The locations that are to transfer/sync are defined in the `./src/main.sh`. |
43 | 101 |
|
44 | 102 | ```bash |
45 | 103 | #!/bin/bash |
46 | | -./src/inst.sh # installing (via pacman, yay & flatpak) and enabling services |
| 104 | +... |
| 105 | +make_recovery() { |
| 106 | + # recovery locations |
| 107 | + declare -A sync_dirs=( |
| 108 | + ["$BORG_HOME/"]="$HOME" |
| 109 | + ) |
| 110 | + ... |
| 111 | +} |
| 112 | +... |
47 | 113 | ``` |
48 | 114 |
|
49 | | -### Borgbackup Script |
| 115 | +`sync_dirs` is a map basicly. The *key* (`$BORG_HOME/`) is the location of the Borg archive and the *value* (`$HOME`) should be a location on your localhost. The data transfer goes from the *key* synchronized to the *value*. |
50 | 116 |
|
51 | | -To transfer data from borgbackup archive to current OS. |
| 117 | +Here as example the complete content of the mounted archive and it's home directory will be "copied" to the home directory of the current user. The command that will be executed internally looks like this. |
52 | 118 |
|
53 | 119 | ```bash |
54 | 120 | #!/bin/bash |
55 | | -./src/borgserver.sh # recovery data using rsync |
56 | | -``` |
| 121 | +rsync -avP --exclude-from="$ROOT_DIR/exclude.txt" "$BORG_HOME/" "$HOME" |
| 122 | +``` |
| 123 | + |
| 124 | +#### *Exclude Patterns* |
| 125 | + |
| 126 | +If you want to exclude folders or files you can put your patterns into the `./src/exclude.txt`. Here an example how it could look like. |
| 127 | + |
| 128 | +```bash |
| 129 | +**/Downloads/** |
| 130 | +**/.wine/** |
| 131 | +**/.cache/** |
| 132 | +**/*.log |
| 133 | +**/Trash/** |
| 134 | +``` |
| 135 | + |
| 136 | +# Last Words |
| 137 | + |
| 138 | +This script does not make backups through Borg by itself but depends on software like **Vorta**. It's possible to code additionally a service that does alongside the Borg backup creation but I think **Vorta** and other applications like that are working very good with a desktop envirounment so It would be overkill and mostly useless for those that prefer **Vorta** to create backups. |
0 commit comments