-
Notifications
You must be signed in to change notification settings - Fork 8
/
migrate.sh
75 lines (71 loc) · 1.53 KB
/
migrate.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
set -e
Dir(){
if [ ! -d /$TO/\@appstore ]; then
mkdir -p /$TO/\@appstore
fi
}
Help(){
printf '\n%s\n\t%s' '-f' 'Target(from) volume, should be in the form of volumeX'
printf '\n%s\n\t%s' '-t' 'Destination(to) volume, should be in the form of volumeX'
printf '\n%s\n\t%s' '-a' 'If specified, will migrate all packages in current directory(Warning: careful!)'
exit 1
}
All(){
Dir
for f in /$FROM/\@appstore/*
do
pkg="${f##*/}"
echo $pkg
/var/packages/$pkg/scripts/start-stop-status stop
mv /$FROM/\@appstore/$pkg /$TO/\@appstore
rm /var/packages/$pkg/target
ln -s /$TO/\@appstore/$pkg /var/packages/$pkg/target
ls -l /var/packages/$pkg
/var/packages/$pkg/scripts/start-stop-status start
done
exit 1
}
Run(){
Dir
for f in /$FROM/\@appstore/*
do
pkg="${f##*/}"
echo $pkg
read -p "proceed?(y/n) " pcd
if [ "$pcd" == "y" ]; then
/var/packages/$pkg/scripts/start-stop-status stop
mv /$FROM/\@appstore/$pkg /$TO/\@appstore
rm /var/packages/$pkg/target
ln -s /$TO/\@appstore/$pkg /var/packages/$pkg/target
ls -l /var/packages/$pkg
/var/packages/$pkg/scripts/start-stop-status start
else
break
fi
done
}
FROM='NONE'
TO='NONE'
opts=":f:t:ah"
while getopts $opts option
do
case ${option} in
f) FROM=${OPTARG};;
t) TO=${OPTARG};;
h)
Help
;;
a)
All
;;
\? ) echo "Unknown option: -$OPTARG" >&2; exit 1;;
: ) echo "Missing option argument for -$OPTARG" >&2; exit 1;;
* ) echo "Unimplemented option: -$OPTARG" >&2; exit 1;;
esac
done
if [ $FROM != 'NONE' ] && [ $TO != 'NONE' ]; then
Run
else
Help
fi