-
Notifications
You must be signed in to change notification settings - Fork 0
/
osx-layer.sh
executable file
·102 lines (90 loc) · 3.29 KB
/
osx-layer.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash
if [ -z "$ENC_PASSWORD" ]; then
echo "\$ENC_PASSWORD is a required environment variable!!"
exit 1
fi
NAME=${NAME:-amazon-cloud-drive}
PLACE_SYMLINK_AT=${1:-$HOME/Desktop/}
IMPORT_DIR=${IMPORT_DIR:-/import}
SSH_PORT=1234
# helps host manage guest (container)
SSH_OPTS="NoHostAuthenticationForLocalhost=yes"
PWD=$(pwd)
which sshfs > /dev/null
if [[ $? -gt 0 ]]; then
echo "sshfs must be installed on the host (osx) system"
exit 1
fi
echo "# !!Warning!!
# - this script will replace any existing docker image tagged name:$NAME
# - this script will replace any existing docker container named $NAME
# Replacing the container will ONLY clear the following:
# - OSX filesystem metadata that exist as 'attrib' changes to inotifywait
# - Any data that has not yet synced from the existing container to ACD..
# just don't run this shortly after any large file additions to share.
# - this script will kill any running sshfs processes on host (osx)
# As an assurance against sshfs bug. If you have other sshfs mounts (you
# don't), they will need to be reestablished.
"
read -r -p "Are you sure? [Y/n]" RESPONSE
RESPONSE=$(echo $RESPONSE | tr "[:upper:]" "[:lower:]")
echo $RESPONSE
if [[ ! $RESPONSE =~ ^(yes|y| ) ]]; then
exit 1;
fi
PUB_KEY="$HOME/.ssh/id_rsa.pub"
if [ ! -f "$PUB_KEY" ]; then
echo "pub key must exist for script. Trying $PUB_KEY"
exit 1;
fi
# this resolves infrequent bug w/ dissociated mountpoint. stops SSHFS manually.
pkill -9 sshfs
umount -f $PWD/$NAME > /dev/null 2>&1 || true
docker rm -f $NAME > /dev/null 2>&1 || true
# build image used by container
docker build -t name:$NAME .
echo "spinning up docker container"
# (runs daemonized, privileged inotify container for acd with $NAME)
# Note: attrib goes nuts on OSX where filesystem metadata is vastly utilized
# to enable: "SYNC_MONITORS=create,modify,attrib,move,delete"
docker run \
-d --name $NAME -p $SSH_PORT:22 \
-e "NAME=$NAME" \
-e "ENC_PASSWORD=$ENC_PASSWORD" \
-e "IMPORT_DIR=$IMPORT_DIR" \
-e "KEY=$IMPORT_DIR/ACD_DATA_KEY" \
-e "OAUTH_DATA=$IMPORT_DIR/oauth_data" \
-e "SYNC_MONITORS=create,modify,move,delete" \
-v $PWD$IMPORT_DIR:$IMPORT_DIR \
-w $IMPORT_DIR \
--privileged --cap-add=ALL \
name:$NAME /bin/bash \
-c "$IMPORT_DIR/infinite-encrypted-backup.sh"
# echo PUB_KEY into container for ssh access
INSERT_KEY="mkdir -p /root/.ssh"
INSERT_KEY+=" && chmod 700 /root/.ssh"
INSERT_KEY+=" && touch /root/.ssh/authorized_keys"
INSERT_KEY+=" && chmod 640 /root/.ssh/authorized_keys"
INSERT_KEY+=" && echo '$(cat $PUB_KEY)' >> /root/.ssh/authorized_keys"
echo "Waiting for docker container..."
docker exec -it $NAME /bin/bash -c "$INSERT_KEY"
while test $? -gt 0
do
sleep 3 && docker exec -it $NAME /bin/bash -c "$INSERT_KEY"
done
# try ssh until it is available, sshfs once it is
echo "Waiting for ssh..."
ssh -p $SSH_PORT -q -o $SSH_OPTS root@localhost exit
while test $? -gt 0
do
sleep 3 && ssh -p $SSH_PORT -q -o $SSH_OPTS root@localhost exit
done
# touch file to sshfs dir to test
echo "Mount Amazon Cloud Drive FUSE directory on host machine @ $PWD/$NAME"
rm -rf $NAME
mkdir $NAME
sshfs -p $SSH_PORT -o $SSH_OPTS root@localhost:/$NAME $NAME
# symlink to desktop
echo "Creating symlink @ $PLACE_SYMLINK_AT$NAME"
rm -rf $PLACE_SYMLINK_AT$NAME
ln -s $PWD/$NAME/ $PLACE_SYMLINK_AT