1#!/bin/bash -e
2#
3# patchtest-setup-sharedir: Setup a directory for storing mboxes and
4# repositories to be shared with the guest machine, including updates to
5# the repos if the directory already exists
6#
7# Copyright (C) 2023 BayLibre Inc.
8#
9# SPDX-License-Identifier: GPL-2.0-only
10#
11
12# poky repository
13POKY_REPO="https://git.yoctoproject.org/poky"
14
15# patchtest repository
16PATCHTEST_REPO="https://git.yoctoproject.org/patchtest"
17
18# the name of the directory
19SHAREDIR="patchtest_share"
20
21help()
22{
23    echo "Usage: patchtest-setup-sharedir [ -d | --directory SHAREDIR ]
24        [ -p | --patchtest PATCHTEST_REPO ]
25        [ -y | --poky POKY_REPO ]"
26    exit 2
27}
28
29while [ "$1" != "" ]; do
30    case $1 in
31    -d|--directory)
32        SHAREDIR=$2
33        shift 2
34        ;;
35    -p|--patchtest)
36        PATCHTEST_REPO=$2
37        shift 2
38        ;;
39    -y|--poky)
40        POKY_REPO=$2
41        shift 2
42        ;;
43    -h|--help)
44        help
45        ;;
46    *)
47        echo "Unknown option $1"
48        help
49        ;;
50    esac
51done
52
53# define MBOX_DIR where the patch series will be stored by
54# get-latest-series
55MBOX_DIR="${SHAREDIR}/mboxes"
56
57# Create SHAREDIR if it doesn't exist
58if [ ! -d "$SHAREDIR" ]; then
59    mkdir -p "${SHAREDIR}"
60    echo "Created ${SHAREDIR}"
61fi
62
63# Create the mboxes directory if it doesn't exist
64if [ ! -d "$MBOX_DIR" ]; then
65    mkdir -p "${MBOX_DIR}"
66    echo "Created ${MBOX_DIR}"
67fi
68
69# clone poky if it's not already present; otherwise, update it
70if [ ! -d "$POKY_REPO" ]; then
71    BASENAME=$(basename ${POKY_REPO})
72    git clone "${POKY_REPO}" "${SHAREDIR}/${BASENAME}"
73else
74    (cd "${SHAREDIR}/$BASENAME" && git pull)
75fi
76
77# clone patchtest if it's not already present; otherwise, update it
78if [ ! -d "$PATCHTEST_REPO" ]; then
79    BASENAME=$(basename ${PATCHTEST_REPO})
80    git clone "${PATCHTEST_REPO}" "${SHAREDIR}/${BASENAME}"
81else
82    (cd "${SHAREDIR}/$BASENAME" && git pull)
83fi
84