summaryrefslogtreecommitdiff
path: root/setup.sh
blob: e271e4f81088366a6021051b7c087174e5f71a97 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env bash

set -e
BUILDCONF=conf/local.conf
BBLAYERS=conf/bblayers.conf

if [ "$1" != "--update" ]; then
  echo ""
  echo "Setting up git hooks..."
  ln -s ../../scripts/git-hooks/post-merge .git/hooks/post-merge || true
  ln -s ../../scripts/git-hooks/post-checkout .git/hooks/post-checkout || true
  ln -s ../../scripts/git-hooks/pre-commit .git/hooks/pre-commit || true
  ln -s ../../scripts/git-hooks/pre-push .git/hooks/pre-push || true
fi

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

# Apply patches
for f in $(ls patches) ; do
  if patch --dry-run -Np1 < patches/$f ; then
    patch -Np1 < patches/$f
  fi
done

# Remove yocto-linux bbappend
rm -f layers/meta-virtualization/recipes-kernel/linux/linux-yocto_*.bbappend

if [ "$1" != "--update" ]; then
  if [ ! -d build/conf ]; then
    mkdir -p build/conf
  fi

  echo ""
  response=y
  test -f ${BUILDCONF} && read -p "Overwrite ${BUILDCONF} with defaults? (y/N) " response
  if [[ $response =~ ^y$ || $response =~ ^yes$ ]]; then
    echo "Creating default bitbake configuration..."
    cp layers/meta-mlinux/contrib/local.conf conf/
  else
    echo "Leaving existing ${BUILDCONF} alone."
  fi

  root_pwd_hash=$(egrep '^MTADM_PASSWORD_HASH[[:space:]]*=' ${BUILDCONF} || true)
  if ((${#root_pwd_hash} == 0)) ; then
    if [[ "$MTADM_PASSWORD" ]] ; then
      pass=$MTADM_PASSWORD
    else
      pass=$(< /dev/urandom tr -dc _A-Z-a-z-0-9 2>/dev/null | head -c${1:-8};echo)
    fi
    salt="$(openssl rand -base64 128 2>/dev/null)"
    hash="$(openssl passwd -1 -salt "$salt" "$pass")"
    echo "MTADM_PASSWORD = \"$pass\"" >password.txt
    echo "HASH = \"$hash\"" >>password.txt
    sed -ri "/MTADM_PASSWORD_HASH[[:space:]]=/d" ${BUILDCONF} || true
    echo "MTADM_PASSWORD_HASH = \"$hash\"" >>${BUILDCONF}
    sed -ri "/MTADM_PASSWORD[[:space:]]=/d" ${BUILDCONF} || true
    echo "MTADM_PASSWORD = \"$pass\"" >>${BUILDCONF}
  fi
  
  echo ""
  response=y
  test -f $BBLAYERS && read -p "Overwrite $BBLAYERS with defaults? (y/N) " response
  if [[ $response =~ ^y$ || $response =~ ^yes$ ]]; then
    echo "Copying default bblayers..."
    OEROOT=$(pwd)
    sed -e "s?__OEROOT__?${OEROOT}?" conf/bblayers.conf.mlinux >$BBLAYERS
  else
    echo "Leaving existing $BBLAYERS alone."
  fi

  echo ""
  echo "Creating user-layer..."
  mkdir -p layers/user-layer/conf
  mkdir -p layers/user-layer/recipes-core

  echo ""
  response=y
  test -f layers/user-layer/conf/layer.conf && read -p "Overwrite layers/user-layer/conf/layer.conf with defaults? (y/N) " response
  if [[ $response =~ ^y$ || $response =~ ^yes$ ]]; then
    echo "Creating default user-layer configuration..."
    cp layers/meta-mlinux/contrib/user-layer.conf layers/user-layer/conf/layer.conf
  else
    echo "Leaving existing layers/user-layer/conf/layer.conf alone."
  fi

  echo ""
  echo "Creating directory structure..."
  mkdir -p build
  mkdir -p downloads
fi

echo ""
echo "Setup Done."
echo ""
echo "oe-init-build-env will configure the environment."
echo "Due to recent security changes in git, you must configure"
echo "the OEROOT directory as a safe directory."
echo ""
echo "To build mlinux-base-image:"
echo "   source oe-init-build-env"
echo "   git config --global --add safe.directory $OEROOT"
echo "   MACHINE=mtcdt bitbake mlinux-base-image"
echo "   or (requires Redpine sources)"
echo "   MACHINE=mtcdt bitbake mlinux-commissioning-image"
echo ""
echo "To build mlinux-mtcap-image:"
echo "   source oe-init-build-env"
echo "   git config --global --add safe.directory $OEROOT"
echo "   MACHINE=mtcap bitbake mlinux-mtcap-image"
echo "   or"
echo "   MACHINE=mtcap bitbake mlinux-mtcap-commissioning-image"