├── README.md ├── Makefile ├── .gitignore ├── LICENSE └── service.sh /README.md: -------------------------------------------------------------------------------- 1 | bitcasa 2 | ======= 3 | 4 | Tools to maintain bitcasa. 5 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | start: 2 | bash service.sh start 3 | .PHONY: start 4 | 5 | stop: 6 | bash service.sh stop 7 | .PHONY: stop 8 | 9 | install: 10 | bash service.sh install 11 | .PHONY: install 12 | 13 | uninstall: 14 | bash service.sh uninstall 15 | .PHONY: uninstall 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Compiled Dynamic libraries 8 | *.so 9 | *.dylib 10 | *.dll 11 | 12 | # Compiled Static libraries 13 | *.lai 14 | *.la 15 | *.a 16 | *.lib 17 | 18 | # Executables 19 | *.exe 20 | *.out 21 | *.app 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Kentaro IMAJO 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /service.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | : ${SERVICE:=bitcasa} 4 | : ${CPU:=100} 5 | : ${MEMORY:=100M} 6 | : ${DISK:=5G} 7 | 8 | set -e -u 9 | 10 | if ! test "$(whoami)" = 'root'; then 11 | echo 'this script must run as root.' >&2 12 | exit 1 13 | fi 14 | 15 | bitcasa::mount() { 16 | if ! mountpoint -q "/storage/${SERVICE}/mount"; then 17 | if [ ! -f "/storage/${SERVICE}/image.dmg" ]; then 18 | echo "install ${SERVICE}: './service.sh install'" >&2 19 | exit 1 20 | fi 21 | e2fsck -y -f "/storage/${SERVICE}/image.dmg" 22 | resize2fs "/storage/${SERVICE}/image.dmg" "${DISK}" 23 | mount -t auto -o loop "/storage/${SERVICE}/image.dmg" \ 24 | "/storage/${SERVICE}/mount" 25 | fi 26 | chown root:root "/storage/${SERVICE}/mount" 27 | } 28 | 29 | bitcasa::start() { 30 | bitcasa::mount 31 | if mountpoint -q "/storage/${SERVICE}/service"; then return; fi 32 | local cache_dir="/storage/${SERVICE}/mount/cache" 33 | local password="$(cat "/storage/${SERVICE}/mount/password.txt")" 34 | mkdir -p "${cache_dir}" "/storage/${SERVICE}/service" 35 | bitcasa "$(cat "/storage/${SERVICE}/mount/user.txt")" \ 36 | "/storage/${SERVICE}/service" \ 37 | -o "password=${password},cachedir=${cache_dir}" 38 | } 39 | 40 | bitcasa::stop() { 41 | if mountpoint -q "/storage/${SERVICE}/service"; then 42 | fuser --kill "/storage/${SERVICE}/service" || true 43 | umount -f "/storage/${SERVICE}/service" || true 44 | if mountpoint -q "/storage/${SERVICE}/service"; then 45 | echo "failed to unmount: /storage/${SERVICE}/service" >&2 46 | exit 1 47 | fi 48 | fi 49 | if mountpoint -q "/storage/${SERVICE}/mount"; then 50 | fuser --kill "/storage/${SERVICE}/mount" || true 51 | umount -f "/storage/${SERVICE}/mount" || true 52 | if mountpoint -q "/storage/${SERVICE}/mount"; then 53 | echo "failed to unmount: /storage/${SERVICE}/mount" >&2 54 | exit 1 55 | fi 56 | fi 57 | } 58 | 59 | bitcasa::install() { 60 | if ! which wget >/dev/null 2>/dev/null; then 61 | apt-get update -qq && apt-get -y install wget 62 | fi 63 | if ! which uuidgen >/dev/null 2>/dev/null; then 64 | apt-get update -qq && apt-get -y install uuid-runtime 65 | fi 66 | if ! which bitcasa >/dev/null 2>/dev/null; then 67 | echo "deb http://dist.bitcasa.com/release/apt debian main" \ 68 | > /etc/apt/sources.list.d/bitcasa-release.list 69 | wget -O- http://dist.bitcasa.com/release/bitcasa-releases.gpg.key \ 70 | | apt-key add - 71 | apt-get update -qq && apt-get -y install bitcasa 72 | fi 73 | bitcasa::mount 74 | read -p "What's your email address for bitcasa? " user 75 | echo -n "${user}" >"/storage/${SERVICE}/mount/user.txt" 76 | read -p "What's your password for bitcasa? " password 77 | echo -n "${password}" >"/storage/${SERVICE}/mount/password.txt" 78 | } 79 | 80 | bitcasa::uninstall() { 81 | bitcasa::stop 82 | while true; do 83 | read -p "Do you really want to remove /storage/${SERVICE}? [yes/no] " yn 84 | if [ "${yn}" == 'yes' ]; then break; fi 85 | case "${yn}" in 86 | [Nn]*) exit;; 87 | *) echo "Please type 'Yes' or 'No'.";; 88 | esac 89 | done 90 | if [ -d "/storage/${SERVICE}" ]; then 91 | rm -rf "/storage/${SERVICE}" 92 | fi 93 | } 94 | 95 | command="$1" 96 | shift 97 | case "${command}" in 98 | 'start') bitcasa::start "$@";; 99 | 'stop') bitcasa::stop;; 100 | 'install') bitcasa::install;; 101 | 'uninstall') bitcasa::uninstall;; 102 | *) echo "no such command: ${command}" >&2;; 103 | esac 104 | --------------------------------------------------------------------------------