summaryrefslogtreecommitdiffstats
path: root/linhes/linhes-dev/lh_sync.sh
diff options
context:
space:
mode:
Diffstat (limited to 'linhes/linhes-dev/lh_sync.sh')
-rwxr-xr-xlinhes/linhes-dev/lh_sync.sh126
1 files changed, 126 insertions, 0 deletions
diff --git a/linhes/linhes-dev/lh_sync.sh b/linhes/linhes-dev/lh_sync.sh
new file mode 100755
index 0000000..053aaba
--- /dev/null
+++ b/linhes/linhes-dev/lh_sync.sh
@@ -0,0 +1,126 @@
+#!/bin/bash
+
+#This script will create and synchronize a local package mirror with the repository
+#(as defined below) on linhes.org, and will also update the database.
+#This script uses a shared account on linhes.org.
+#DO NOT change the account name and don't ask for the password,
+#instead setup ssh keys and run ssh-agent.
+
+if [ -e /etc/makepkg.conf ]
+then
+ . /etc/makepkg.conf
+else
+ echo "Couldn't find /etc/makepkg.conf"
+fi
+
+LOCAL_DIR=/data/dev
+REMOTE_DIR=/srv/www/repo
+PKGROOT=$LOCAL_DIR/pkg_repo/$CARCH
+
+function sync_dirs {
+ REMOTE=$1
+ LOCAL=$2
+ echo "--------------------------------------------------------"
+ echo " Syncing $3 packages with linhes.org"
+ echo "--------------------------------------------------------"
+ echo "Remote: $REMOTE"
+ echo "Local: $LOCAL"
+ case $4 in
+ resync)
+ rclone bisync :sftp,host=linhes.org,user=reposync:$REMOTE $LOCAL --verbose --resync --copy-links
+ ;;
+ force)
+ rclone bisync :sftp,host=linhes.org,user=reposync:$REMOTE $LOCAL --verbose --force --copy-links
+ ;;
+ *)
+ rclone bisync :sftp,host=linhes.org,user=reposync:$REMOTE $LOCAL --verbose --copy-links
+ ;;
+ esac
+
+ if [ ! $? = 0 ]
+ then
+ echo "############################################"
+ echo "## ERRORS OCCURED ##"
+ echo "############################################"
+ exit 1
+ fi
+
+ #update the local database
+ if [ "$4" == "update_db" ]
+ then
+ echo "--------"
+ echo "Updating the whole package db..."
+ echo "--------"
+ lh_update_db_repo.sh $LOCAL $3
+
+ echo "--------"
+ echo "Pushing the package db to linhes.org"
+ echo "--------"
+ rclone bisync :sftp,host=linhes.org,user=reposync:$REMOTE $LOCAL --verbose --copy-links
+ fi
+
+ echo "--------------------------------------------------------"
+ echo " Finished syncing $3 packages"
+ echo "--------------------------------------------------------"
+}
+
+function source_sync () {
+ echo "--------------------------------------------------------"
+ echo " Syncing $1 sources"
+ echo "--------------------------------------------------------"
+ REMOTE_SRC=$REMOTE_DIR/src_packages/$1/
+ LOCAL_SRC=$LOCAL_DIR/pkg_repo/src_packages/$1/
+ echo "Remote: $REMOTE_SRC"
+ echo "Remote: $LOCAL_SRC"
+ case $2 in
+ resync)
+ rclone bisync :sftp,host=linhes.org,user=reposync:$REMOTE_SRC $LOCAL_SRC --verbose --resync --copy-links
+ ;;
+ force)
+ rclone bisync :sftp,host=linhes.org,user=reposync:$REMOTE_SRC $LOCAL_SRC --verbose --force --copy-links
+ ;;
+ *)
+ rclone bisync :sftp,host=linhes.org,user=reposync:$REMOTE_SRC $LOCAL_SRC --verbose --copy-links
+ ;;
+ esac
+ echo "--------------------------------------------------------"
+ echo " Finished syncing $3 sources"
+ echo "--------------------------------------------------------"
+}
+
+function pacman_sync () {
+ echo "running 'pacman -Sy' to sync repos"
+ sudo pacman -Sy
+}
+
+#---------------------------------------------------------------
+case $1 in
+ testing)
+ sync_dirs $REMOTE_DIR/$CARCH/linhes-testing/ $PKGROOT/linhes-testing/ linhes-testing $2
+ source_sync linhes-testing $2
+ pacman_sync
+ ;;
+ release)
+ sync_dirs $REMOTE_DIR/$CARCH/linhes/ $PKGROOT/linhes/ linhes $2
+ source_sync linhes $2
+ pacman_sync
+ ;;
+ source)
+ if [ x = x$2 ]
+ then
+ echo "Missing source repository [testing|release]"
+ exit 1
+ fi
+ source_sync $1 $2
+ pacman_sync
+ ;;
+ *)
+ echo "Invalid Options"
+ echo "lh_sync.sh (testing|release|source[testing|release]) (update_db|resync|force)"
+ echo
+ echo "force: force rclone to sync when too many deletes are detected"
+ echo "resync: overwrites the local package and source repos with ones from linhes.org"
+ echo "update_db: recreate the db files in the repo and syncs to linhes.org"
+ echo "EXAMPLE: lh_sync.sh testing update_db <= will sync the testing repo with linhes.org update the local database and resync with linhes.org"
+ ;;
+esac