Skip to content

Instantly share code, notes, and snippets.

@nobodypb
Created February 8, 2017 22:59
Show Gist options
  • Save nobodypb/fc3e70b535bcd95b5de7659d6fbda434 to your computer and use it in GitHub Desktop.
Save nobodypb/fc3e70b535bcd95b5de7659d6fbda434 to your computer and use it in GitHub Desktop.
Script for moving packages on a synology disk station from one volume to another - EXPERIMENTAL!
#!/bin/bash
SOURCE=/volume1
DEST=/volume2
APPDIR=\@appstore
ASK=true
while getopts ":y" opt; do
case $opt in
y)
ASK=false
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
echo "This will move packages from $SOURCE to $DEST"
echo ""
if [ ! -d $DEST/$APPDIR ]; then
mkdir $DEST/$APPDIR
chmod 777 $DEST/$APPDIR
echo "New app directory created"
fi
echo "Searching for packages on $SOURCE..."
for d in /var/packages/*
do
[ -d "$d" ] || continue
app=$(basename $d)
symlink=$d/target
if [ ! -e "$symlink" ]; then
echo "$app has no symlink"
continue
fi
if [ ! -e "$SOURCE/$APPDIR/$app" ]; then
echo "$app is not in source directory"
continue
fi
if [ ! "$(readlink $symlink)" -ef "$SOURCE/$APPDIR/$app" ]; then
echo "$app: Symlink doesn't point to source directory"
continue
fi
echo "Found $app"
file_warnings=$(find $d -type f -exec grep -l "$SOURCE" {} \;)
if [ ! -z $file_warnings ]; then
echo "Be careful!"
echo "The following files contain '$SOURCE':"
echo "$file_warnings"
fi
if $ASK; then
read -s -p "`echo $'\t'`Move $app? (y/n)`echo $'\n \b'`" -n 1 -r
[[ $REPLY =~ ^[Yy]$ ]] || continue
echo ""
fi
echo "`echo $'\t'`Moving $app..."
synopkgctl stop $app
cp -rp $SOURCE/$APPDIR/$app $DEST/$APPDIR/
rm -f $symlink
ln -s $DEST/$APPDIR/$app $symlink
mv $SOURCE/$APPDIR/$app $SOURCE/$APPDIR/__$app
synopkgctl start $app
echo "`echo $'\t'`Done. Backup in: $SOURCE/$APPDIR/__$app"
echo ""
done
echo "Done for all."
echo ""
echo "If you want to remove $SOURCE you should also move the following:"
echo ""
for f in /var/services/*
do
[ -L $f ] || continue
target=$(readlink $f)
if echo "$target" | grep -q $SOURCE; then
echo "System service symlink $f to $target"
fi
done
@superdale007
Copy link

Sooooo just to be clear here...If I want to move everything off of Vol1 and Vol2 to be on Vol3, I'd run this script twice (changing the source each time to vol1 then vol2)? After it's done, can I then delete vol1 and vol2 and add their space to vol3?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment