Added README.md and refactored install.sh
This commit is contained in:
parent
3d0ec7f2f6
commit
a13ceb3cb0
78
README.md
Normal file
78
README.md
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
# Anki Sync Server
|
||||||
|
|
||||||
|
This project sets up an Anki synchronization server in a Docker environment, making it easy to host your own Anki synchronization service.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- Dockerized Anki Sync Server.
|
||||||
|
- Entry point script for the server to facilitate user configuration.
|
||||||
|
- systemd service file for ease of management and auto-start of the Anki sync service.
|
||||||
|
- Installation script for automated setup.
|
||||||
|
- Sample environment file to set configurations.
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
- Docker
|
||||||
|
- Docker Compose
|
||||||
|
- Git
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
1. Clone this repository:
|
||||||
|
```bash
|
||||||
|
git clone https://git.rudefox.io/bj/anki-sync-server.git /var/lib/anki-server
|
||||||
|
cd /var/lib/anki-server
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Run the installation script (with root privileges):
|
||||||
|
```bash
|
||||||
|
sudo ./install.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Remember to set up the necessary environment variables in the `.env` file.
|
||||||
|
- For a quick start, a `sample.env` file has been provided.
|
||||||
|
|
||||||
|
4. Ensure that the `data` directory is created and has the appropriate permissions:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mkdir data
|
||||||
|
```
|
||||||
|
|
||||||
|
5. Start the service:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
systemctl start anki-sync-server
|
||||||
|
```
|
||||||
|
|
||||||
|
To enable auto-start on boot:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
systemctl enable anki-sync-server
|
||||||
|
```
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
Most of the server's configurations are managed through the `.env` file. After the initial setup, ensure to modify this file according to your requirements.
|
||||||
|
|
||||||
|
Here are some key environment variables:
|
||||||
|
|
||||||
|
- `ANKISYNCD_DATA_ROOT`: Path to the data root directory inside the container.
|
||||||
|
- `ANKISYNCD_AUTH_DB_PATH`: Path to the authentication database.
|
||||||
|
- `ANKISYNCD_SESSION_DB_PATH`: Path to the session database.
|
||||||
|
- `SYNC_USERS`: Users for the synchronization server.
|
||||||
|
- `ANKI_PORT`: Port on which the Anki server should run.
|
||||||
|
- `ANKI_VOLUME_PATH`: Local path for the volume storage.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
You can interact with the Anki sync server using the provided `ankictl.sh` script:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./ankictl.sh [options]
|
||||||
|
```
|
||||||
|
|
||||||
|
## Maintenance
|
||||||
|
|
||||||
|
- **Backup**: Ensure to backup your `data` directory regularly.
|
||||||
|
- **Updates**: To update the service, pull the latest changes from the repository and restart the service.
|
||||||
|
|
55
install.sh
55
install.sh
|
@ -1,45 +1,53 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Set variables
|
SERVICE_NAME=anki-sync-server
|
||||||
SERVICE_FILE="service/anki-sync-server.service"
|
|
||||||
SYSTEMD_DIR="/etc/systemd/system"
|
# Constants
|
||||||
|
DIR="${1:-$(pwd)}"
|
||||||
|
SERVICE_FILE_TEMPLATE="$DIR/service/anki-sync-server.service.template"
|
||||||
|
SYSTEMD_SERVICE_PATH="/etc/systemd/system/${SERVICE_NAME}.service"
|
||||||
ENV_SAMPLE="sample.env"
|
ENV_SAMPLE="sample.env"
|
||||||
ENV_TARGET=".env"
|
ENV_TARGET=".env"
|
||||||
|
|
||||||
|
# Check essential tools
|
||||||
|
if ! command -v systemctl &> /dev/null || ! command -v sed &> /dev/null; then
|
||||||
|
echo "Essential tools (systemctl or sed) are missing."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Check if root
|
# Check if root
|
||||||
if [[ $EUID -ne 0 ]]; then
|
if [[ $EUID -ne 0 ]]; then
|
||||||
echo "This script must be run as root."
|
echo "This script must be run as root."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Copy service file to systemd directory
|
# Check if service file template exists
|
||||||
if [ -e "$SERVICE_FILE" ]; then
|
if [ ! -e "$SERVICE_FILE_TEMPLATE" ]; then
|
||||||
cp -n "$SERVICE_FILE" "$SYSTEMD_DIR"
|
echo "Service file $SERVICE_FILE_TEMPLATE does not exist."
|
||||||
if [ $? -eq 0 ]; then
|
exit 1
|
||||||
echo "Service file copied successfully."
|
fi
|
||||||
|
|
||||||
|
# Check and copy service file
|
||||||
|
if ! cmp -s <(sed "s|{{DIR}}|$DIR|g" "$SERVICE_FILE_TEMPLATE") "$SYSTEMD_SERVICE_PATH"; then
|
||||||
|
cp "$SERVICE_FILE_TEMPLATE" "$SYSTEMD_SERVICE_PATH" && sed -i "s|{{DIR}}|$DIR|g" "$SYSTEMD_SERVICE_PATH"
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Failed to copy and modify the service file."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Daemon reloaded successfully."
|
|
||||||
else
|
|
||||||
echo "Failed to reload the daemon."
|
echo "Failed to reload the daemon."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "Failed to copy the service file."
|
echo "Service file is up-to-date. Skipping..."
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "Service file $SERVICE_FILE does not exist."
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Copy sample.env to .env if it does not already exist
|
# Check and copy .env file
|
||||||
if [ ! -e "$ENV_TARGET" ]; then
|
if [ ! -e "$ENV_TARGET" ]; then
|
||||||
if [ -e "$ENV_SAMPLE" ]; then
|
if [ -e "$ENV_SAMPLE" ]; then
|
||||||
cp "$ENV_SAMPLE" "$ENV_TARGET"
|
cp "$ENV_SAMPLE" "$ENV_TARGET"
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo ".env file created successfully."
|
|
||||||
else
|
|
||||||
echo "Failed to create .env file."
|
echo "Failed to create .env file."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
@ -48,12 +56,9 @@ if [ ! -e "$ENV_TARGET" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo ".env file already exists, skipping."
|
echo ".env file already exists. Skipping..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Remind user to create data directory
|
|
||||||
echo "Remember to create the data directory on your local machine."
|
|
||||||
|
|
||||||
# Script completed successfully
|
# Script completed successfully
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
|
|
|
@ -4,11 +4,11 @@ Requires=docker.service
|
||||||
After=docker.service
|
After=docker.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
WorkingDirectory=/var/lib/anki
|
WorkingDirectory={{DIR}}
|
||||||
ExecStart=/usr/local/bin/docker-compose up
|
ExecStart=/usr/local/bin/docker-compose up
|
||||||
ExecStop=/usr/local/bin/docker-compose down
|
ExecStop=/usr/local/bin/docker-compose down
|
||||||
Restart=always
|
Restart=always
|
||||||
EnvironmentFile=/var/lib/anki/.env
|
EnvironmentFile={{DIR}}/.env
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
Loading…
Reference in New Issue
Block a user