aboutsummaryrefslogtreecommitdiff
path: root/inception
blob: 394f29e5e46d48cb0f6bf03e93115a46e61df646 (plain)
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
#!/bin/bash
#
# The inception.
#

# Parameters
BASENAME="`basename $0`"
DIRNAME="$(cd `dirname $0` &> /dev/null && pwd)"

# Main
if [ -z "$1" ]; then
  echo "usage: $BASENAME <action> [options]"
elif [ "$1" == "init" ]; then
  (
    cd $DIRNAME

    echo "Initializing submodules..."
    git submodule update --init --recursive

    if [ ! -e "$HOME/.dotfiles" ]; then
      echo "Cloning default dotfiles..."
      ./metadot/metadot clone default
    else
      echo "Updating dotfiles..."
      ./metadot/metadot update
    fi

    echo "Checking latest tag..."
    cd $HOME/.dotfiles
    $DIRNAME/utils-git/git-check-tag

    echo "Checking out the latest tag..."
    $DIRNAME/utils-git/git-checkout-tag

    echo "Checking dotfiles..."
    $DIRNAME/metadot/metadot version
  )

  echo ""
  echo "Please manually verify dotfiles version and tag from the above output."
  echo "If everything is fine, proceed running this command again with the 'load' parameter."
elif [ "$1" == "load" ]; then
  (
    cd $DIRNAME

    echo "Loading all dotfiles..."
    ./metadot/metadot load --all
    ./metadot/metadot deps --all
  )

  echo "Done. Logout and login again to apply all changes."
elif [ "$1" == "install" ]; then
  # We could just do that, but we shall make sure that code was verified
  #$0 init
  #$0 load
  echo "Please README!"
elif [ "$1" == "deploy" ]; then
  if [ ! -z "$2" ]; then
    REMOTE="$2"
    MODULES="`$DIRNAME/metadot/metadot list | xargs`"

    # Sync apps
    if [ -e "$HOME/apps" ]; then
      rsync -avz --delete $HOME/apps/ $REMOTE:apps/
    fi

    # Sync dotfiles
    if [ -e "$HOME/.dotfiles" ]; then
      rsync -avz --delete $HOME/.dotfiles/ $REMOTE:.dotfiles/
    fi

    # Sync loaded modules
    ssh -T $REMOTE <<EOF
    ##### BEGIN REMOTE SCRIPT #####
    for module in $MODULES; do
      \$HOME/apps/metadot/metadot load \$module
    done
    ##### END REMOTE SCRIPT #######
EOF
  fi
elif [ "$1" == "version" ]; then
  ( cd $DIRNAME && git log -n 1 )
elif [ "$1" == "fetch" ]; then
  ( cd $DIRNAME && git fetch --all && git log -n 1 --branches=origin/master )
elif [ "$1" == "merge" ]; then
  ( cd $DIRNAME && git merge origin/master && git submodule update --init --recursive )
fi