Add readme, license, install/remove script

This commit is contained in:
2025-10-28 21:25:47 +01:00
parent a0b97a856a
commit aa8851aca0
5 changed files with 228 additions and 1 deletions

7
LICENSE Normal file
View File

@@ -0,0 +1,7 @@
Copyright 2025 Aurélie DELHAIE
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

74
README.md Normal file
View File

@@ -0,0 +1,74 @@
# mirror-sync
## Description
Seamless Mirror-Sync: Your Effortless Repository Synchronization Engine
Unlock true simplicity for keeping your mirrors aligned. Mirror-Sync is a clean, high-performance Go tool built to automate the replication of repositories with minimal fuss — no manual toil, no drift, no surprises.
### Why youll love it
- 📦 Plug-and-play: Drop the binary in, point it at your source & destination, configure via environment variables, and youre done.
- 🔁 Reliable mirroring: Whether youre syncing from one endpoint to another or maintaining multiple mirrors, Mirror-Sync keeps everything in step with precision.
- 🛠 Modern and lean: Written in Go with a minimal shell build wrapper, its designed for speed, simplicity and low-footprint deployment (Linux, containers, whatever you like).
In short
Mirror-Sync takes the headache out of repository mirroring. Set it up once, configure it easily, and forget about it — while knowing your mirrors stay consistent, aligned and up-to-date.
(Generated by AI because nobody will see it anyway)
## How to build
```sh
./build.sh --target-current
```
## How to install
```sh
./install.sh
```
### and uninstall
```sh
./uninstall.sh
```
## Make a project
- Step 1 : Make an empty directory
```sh
mkdir my-project
cd my-project
```
- Step 2 : Make a file named `git-compose.yaml`
```sh
nano git-compose.yaml
```
- Step 3 : Add the following content
```yaml
repositories:
my-repo:
storage:
source:
url: "https://git.example.com/user/repo"
mirror:
url: "https://github.com/user/repo"
authentication:
token: ""
schedule: "* * * * *"
```
- Step 4 : Apply the configuration
```sh
mirrorsync apply
```

View File

@@ -1,11 +1,13 @@
#!/bin/bash
MAKE_PACKAGE=false
TARGET_CURRENT=false
usage() {
echo "Usage: $0 [OPTIONS]"
echo "Options:"
echo " --package Make a delivery package instead of plain binary"
echo " --target-current Target the current OS/arch for the build"
}
# Function to handle options and arguments
@@ -15,6 +17,9 @@ handle_options() {
--package)
MAKE_PACKAGE=true
;;
--target-current)
TARGET_CURRENT=true
;;
*)
echo "Invalid option: $1" >&2
usage
@@ -32,6 +37,33 @@ if [ ! -d "./build" ]; then
mkdir ./build
fi
if [ "$TARGET_CURRENT" == "true" ]; then
GOOS=$(go env GOOS)
GOARCH=$(go env GOARCH)
echo "* Compiling daemon for $GOOS/$GOARCH..."
if [ "$MAKE_PACKAGE" == "true" ]; then
CGO_ENABLED=0 GORISCV64=rva22u64 GOAMD64=v3 GOARM64=v8.2 go build -o build/mirrorsyncd -a ./cmd/server
tar -czf build/daemon.tar.gz build/mirrorsyncd
rm build/mirrorsyncd
else
CGO_ENABLED=0 GORISCV64=rva22u64 GOAMD64=v3 GOARM64=v8.2 go build -o build/mirrorsyncd -a ./cmd/server
fi
echo "* Compiling client for $GOOS/$GOARCH..."
if [ "$MAKE_PACKAGE" == "true" ]; then
CGO_ENABLED=0 GORISCV64=rva22u64 GOAMD64=v3 GOARM64=v8.2 go build -o build/mirrorsync -a ./cmd/cli
tar -czf build/client.tar.gz build/mirrorsync
rm build/mirrorsync
else
CGO_ENABLED=0 GORISCV64=rva22u64 GOAMD64=v3 GOARM64=v8.2 go build -o build/mirrorsync -a ./cmd/cli
fi
exit 0
fi
### FROM HERE, BUILD ALL
## SERVER
platforms=("linux/amd64" "linux/arm64" "linux/riscv64" "linux/ppc64le" "windows/amd64" "darwin/amd64" "darwin/arm64")

44
install.sh Executable file
View File

@@ -0,0 +1,44 @@
#!/bin/bash
if [ $UID -ne "0" ]; then
echo "error: must be root" 1>&2
exit 1
fi
./build.sh --target-current
mkdir -p /var/lib/mirror-sync/
mkdir -p /opt/mirror-sync
id mirror-sync 1>/dev/null 2>&1
if [ $? -ne 0 ]; then
useradd -r -M -d /var/lib/mirror-sync/ mirror-sync
fi
cp ./build/mirrorsyncd /opt/mirror-sync/mirrorsyncd
cp ./build/mirrorsync /usr/local/bin/mirrorsync
chmod ugo+x /usr/local/bin/mirrorsync
chmod 740 /opt/mirror-sync/mirrorsyncd
chown -R mirror-sync:mirror-sync /opt/mirror-sync
chown -R mirror-sync:mirror-sync /var/lib/mirror-sync
cat <<EOF > /etc/systemd/system/mirrorsync.service
[Unit]
Description=mirrorsync daemon
After=network.target
[Service]
WorkingDirectory=/var/lib/mirror-sync
ExecStart=/opt/mirror-sync/mirrorsyncd
User=mirror-sync
Group=mirror-sync
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
echo "done installing!"

70
uninstall.sh Executable file
View File

@@ -0,0 +1,70 @@
#!/bin/bash
PURGE=false
usage() {
echo "Usage: $0 [OPTIONS]"
echo "Options:"
echo " --purge Remove also data"
}
# Function to handle options and arguments
handle_options() {
while [ $# -gt 0 ]; do
case $1 in
--purge)
PURGE=true
;;
*)
echo "Invalid option: $1" >&2
usage
exit 1
;;
esac
shift
done
}
# Main script execution
handle_options "$@"
if [ $UID -ne "0" ]; then
echo "error: must be root" 1>&2
exit 1
fi
if [ "$PURGE" == "true" ]; then
rm -r /var/lib/mirror-sync
if [ $? -ne 0 ]; then
echo "failed to remove data" 1>&2
fi
fi
rm -r /opt/mirror-sync
if [ $? -ne 0 ]; then
echo "failed to uninstall" 1>&2
exit 1
fi
rm -r /usr/local/bin/mirrorsync
if [ $? -ne 0 ]; then
echo "failed to uninstall" 1>&2
exit 1
fi
userdel mirror-sync
if [ $? -ne 0 ]; then
echo "failed to uninstall" 1>&2
exit 1
fi
rm -r /etc/systemd/system/mirrorsync.service
if [ $? -ne 0 ]; then
echo "failed to uninstall" 1>&2
exit 1
fi
systemctl disable mirrorsync.service 1>/dev/null 2>&1
systemctl daemon-reload
echo "done uninstalling!"