Skip to content

Commit f93214f

Browse files
committed
add bitlocker support; allow dual service use
1 parent 83062bc commit f93214f

File tree

3 files changed

+580
-114
lines changed

3 files changed

+580
-114
lines changed

README.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,89 @@
11
# srv-ctl
22

33
Small utility to manage home server services dependent on encrypted storage.
4+
5+
## Features
6+
7+
- **Multiple Syncthing Services**: Supports running 2 parallel Syncthing services with different users
8+
- **Multiple Storage Devices**: Supports 5 storage devices (1 primary data + 4 paired storage devices)
9+
- **Dual Encryption Support**: Supports both LUKS and BitLocker encryption formats
10+
- **LVM Support**: Optional LVM (Logical Volume Manager) support for device management
11+
- **Network Storage**: CIFS/SMB network share mounting support
12+
- **Configuration Validation**: Built-in validation to verify setup before execution
13+
14+
## Requirements
15+
16+
- **cryptsetup**: Version 2.4.0+ (supports both LUKS and BitLocker encryption)
17+
- **lvm2**: Required only if using LVM volumes
18+
- **Root privileges**: Script must be run as root
19+
20+
## Configuration
21+
22+
Copy `config.local.template` to `config.local` and customize:
23+
24+
```bash
25+
cp config.local.template config.local
26+
```
27+
28+
### Service Configuration
29+
30+
```bash
31+
# Syncthing users (set to "none" to disable)
32+
readonly ST_USER_1="alice"
33+
readonly ST_USER_2="bob"
34+
35+
# Service names (constructed automatically)
36+
readonly ST_SERVICE_1="syncthing@${ST_USER_1}.service"
37+
readonly ST_SERVICE_2="syncthing@${ST_USER_2}.service"
38+
readonly DOCKER_SERVICE="docker.service"
39+
```
40+
41+
### Storage Device Configuration
42+
43+
Each storage device supports:
44+
45+
- **Mount Point**: Local directory under `/mnt/`
46+
- **Device Mapper**: Name for the unlocked device
47+
- **LVM Support**: Optional logical volume management
48+
- **Encryption Type**: Either `luks` or `bitlocker`
49+
- **Key Files**: Optional for automated unlocking
50+
51+
Example for BitLocker device:
52+
53+
```bash
54+
readonly STORAGE_2A_MOUNT="storage2a"
55+
readonly STORAGE_2A_MAPPER="storage2a-data"
56+
readonly STORAGE_2A_UUID="your-device-uuid"
57+
readonly STORAGE_2A_KEY_FILE="/path/to/recovery.key"
58+
readonly STORAGE_2A_ENCRYPTION_TYPE="bitlocker"
59+
```
60+
61+
## Usage
62+
63+
```bash
64+
sudo ./srv-ctl.sh start # Start all services and mount devices
65+
sudo ./srv-ctl.sh stop # Stop all services and unmount devices
66+
sudo ./srv-ctl.sh unlock-only # Only unlock and mount devices
67+
sudo ./srv-ctl.sh stop-services-only # Only stop services
68+
./srv-ctl.sh validate-config # Validate configuration without making changes
69+
./srv-ctl.sh help # Show help message
70+
```
71+
72+
## Migration from Old Format
73+
74+
If you have an existing `config.local` from an earlier version, you'll need to update it to the new format. The main changes:
75+
76+
1. **Service Configuration**:
77+
- `ST_SERVICE``ST_SERVICE_1` and `ST_SERVICE_2`
78+
- `ST_USER``ST_USER_1` and `ST_USER_2`
79+
80+
2. **Storage Device Configuration**:
81+
- `ACTIVE_DATA_*``PRIMARY_DATA_*`
82+
- `STORAGE_DATA_*``STORAGE_1A_*`, `STORAGE_1B_*`, `STORAGE_2A_*`, `STORAGE_2B_*`
83+
84+
3. **New Parameters**:
85+
- Added `*_ENCRYPTION_TYPE` parameters for each device
86+
- Updated minimum cryptsetup version requirement to 2.4.0
87+
- Enhanced validation and error handling
88+
89+
Use `./srv-ctl.sh validate-config` to check your configuration after updating.

config.local.template

Lines changed: 58 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,77 @@
11
# -----------------------------------------------------------------------------
2-
# Local storage device for active working data (i.e. DBs, logs, etc.)
2+
# Service configuration
33
# -----------------------------------------------------------------------------
44

5-
# set the value of unused parameters to "none"
5+
# Minimum cryptsetup version required (2.4.0+ supports modern unified syntax)
6+
readonly CRYPTSETUP_MIN_VERSION="2.4.0"
67

7-
readonly ACTIVE_DATA_UUID="DISK_X_UUID" # Reported by: `sudo blkid /dev/<device>`
8-
readonly ACTIVE_DATA_MAPPER="ext_ssd"
9-
readonly ACTIVE_DATA_MOUNT="srv_rapid_storage"
8+
# Syncthing users (set to "none" to disable)
9+
readonly ST_USER_1="none" # Set to username to enable (e.g., "alice")
10+
readonly ST_USER_2="none" # Set to username to enable (e.g., "bob")
1011

11-
readonly ACTIVE_DATA_LVM_NAME="logic_volume_name"
12-
readonly ACTIVE_DATA_LVM_GROUP="logic_volume_group"
12+
# Service names (automatically constructed)
13+
readonly ST_SERVICE_1="${ST_USER_1:+syncthing@${ST_USER_1}.service}"
14+
readonly ST_SERVICE_2="${ST_USER_2:+syncthing@${ST_USER_2}.service}"
15+
readonly DOCKER_SERVICE="none" # Set to "docker.service" to enable
1316

1417
# -----------------------------------------------------------------------------
15-
# Local storage device for data at rest
18+
# Primary data device configuration
1619
# -----------------------------------------------------------------------------
1720

18-
# set the value of unused parameters to "none"
19-
20-
readonly STORAGE_DATA_KEY_FILE="mass_storage_key_file_path"
21-
22-
readonly STORAGE_DATA_UUID="DISK_Y_UUID" # Reported by: `sudo blkid /dev/<device>`
23-
readonly STORAGE_DATA_MAPPER="ext_hdd"
24-
readonly STORAGE_DATA_MOUNT="srv_mass_storage"
25-
26-
readonly STORAGE_DATA_LVM_NAME="logic_volume_name"
27-
readonly STORAGE_DATA_LVM_GROUP="logic_volume_group"
21+
readonly PRIMARY_DATA_MOUNT="primary" # Mount point under /mnt/
22+
readonly PRIMARY_DATA_MAPPER="primary-data" # Device mapper name
23+
readonly PRIMARY_DATA_LVM_NAME="none" # Set to LVM volume name to enable LVM
24+
readonly PRIMARY_DATA_LVM_GROUP="vg-srv" # LVM group name (used if LVM volume is set)
25+
readonly PRIMARY_DATA_UUID="none" # Set to device UUID to enable (find with: sudo blkid)
26+
readonly PRIMARY_DATA_KEY_FILE="none" # Set to key file path for automated unlock
27+
readonly PRIMARY_DATA_ENCRYPTION_TYPE="luks" # Options: "luks" or "bitlocker"
2828

2929
# -----------------------------------------------------------------------------
30-
# Network storage for data at rest
30+
# Storage devices for Syncthing service 1
3131
# -----------------------------------------------------------------------------
3232

33-
readonly NETWORK_SHARE_PROTOCOL="cifs" # set to "none" if network share is not used
34-
35-
readonly NETWORK_SHARE_ADDRESS="//<address>/share_name"
36-
readonly NETWORK_SHARE_MOUNT="lan_data_storage"
37-
readonly NETWORK_SHARE_CREDENTIALS="lan_storage_credentials_file_path"
38-
readonly NETWORK_SHARE_OPTIONS="dir_mode=0555,file_mode=0444,uid=1000,gid=1000"
33+
readonly STORAGE_1A_MOUNT="storage1a" # Mount point under /mnt/
34+
readonly STORAGE_1A_MAPPER="storage1a-data" # Device mapper name
35+
readonly STORAGE_1A_LVM_NAME="none" # Set to LVM volume name to enable LVM
36+
readonly STORAGE_1A_LVM_GROUP="vg-srv" # LVM group name (used if LVM volume is set)
37+
readonly STORAGE_1A_UUID="none" # Set to device UUID to enable (find with: sudo blkid)
38+
readonly STORAGE_1A_KEY_FILE="none" # Set to key file path for automated unlock
39+
readonly STORAGE_1A_ENCRYPTION_TYPE="luks" # Options: "luks" or "bitlocker"
40+
41+
readonly STORAGE_1B_MOUNT="storage1b" # Mount point under /mnt/
42+
readonly STORAGE_1B_MAPPER="storage1b-data" # Device mapper name
43+
readonly STORAGE_1B_LVM_NAME="none" # Set to LVM volume name to enable LVM
44+
readonly STORAGE_1B_LVM_GROUP="vg-srv" # LVM group name (used if LVM volume is set)
45+
readonly STORAGE_1B_UUID="none" # Set to device UUID to enable (find with: sudo blkid)
46+
readonly STORAGE_1B_KEY_FILE="none" # Set to key file path for automated unlock
47+
readonly STORAGE_1B_ENCRYPTION_TYPE="luks" # Options: "luks" or "bitlocker"
3948

4049
# -----------------------------------------------------------------------------
41-
# Misc system definitions
50+
# Storage devices for Syncthing service 2
4251
# -----------------------------------------------------------------------------
4352

44-
readonly LUKS_MIN_VERSION="2"
53+
readonly STORAGE_2A_MOUNT="storage2a" # Mount point under /mnt/
54+
readonly STORAGE_2A_MAPPER="storage2a-data" # Device mapper name
55+
readonly STORAGE_2A_LVM_NAME="none" # Set to LVM volume name to enable LVM
56+
readonly STORAGE_2A_LVM_GROUP="vg-srv" # LVM group name (used if LVM volume is set)
57+
readonly STORAGE_2A_UUID="none" # Set to device UUID to enable (find with: sudo blkid)
58+
readonly STORAGE_2A_KEY_FILE="none" # Set to key file path for automated unlock
59+
readonly STORAGE_2A_ENCRYPTION_TYPE="luks" # Options: "luks" or "bitlocker"
60+
61+
readonly STORAGE_2B_MOUNT="storage2b" # Mount point under /mnt/
62+
readonly STORAGE_2B_MAPPER="storage2b-data" # Device mapper name
63+
readonly STORAGE_2B_LVM_NAME="none" # Set to LVM volume name to enable LVM
64+
readonly STORAGE_2B_LVM_GROUP="vg-srv" # LVM group name (used if LVM volume is set)
65+
readonly STORAGE_2B_UUID="none" # Set to device UUID to enable (find with: sudo blkid)
66+
readonly STORAGE_2B_KEY_FILE="none" # Set to key file path for automated unlock
67+
readonly STORAGE_2B_ENCRYPTION_TYPE="luks" # Options: "luks" or "bitlocker"
4568

46-
# set the value of unused parameters to "none"
47-
48-
readonly ST_USER="your-syncthing-user"
49-
readonly ST_SERVICE="syncthing@${ST_USER}.service"
69+
# -----------------------------------------------------------------------------
70+
# Network share configuration
71+
# -----------------------------------------------------------------------------
5072

51-
readonly DOCKER_SERVICE="<docker>.service"
73+
readonly NETWORK_SHARE_ADDRESS="none" # Set to share path to enable (e.g., "//server/share")
74+
readonly NETWORK_SHARE_MOUNT="none" # Set to mount name (e.g., "network")
75+
readonly NETWORK_SHARE_PROTOCOL="none" # Set to protocol: "cifs", "nfs", etc.
76+
readonly NETWORK_SHARE_CREDENTIALS="none" # Set to credentials file path
77+
readonly NETWORK_SHARE_OPTIONS="uid=1000,gid=1000,iocharset=utf8" # Mount options

0 commit comments

Comments
 (0)