|
1 | 1 | #!/bin/bash
|
2 | 2 |
|
3 |
| -RED="\e[31m" |
4 |
| -GREEN="\e[32m" |
5 |
| -BLUE="\e[34m" |
6 |
| -YELLOW="\e[33m" |
7 |
| -ENDCOLOR="\e[0m" |
| 3 | +. "$WORKSPACE_PATH/tools/color.sh" |
8 | 4 |
|
9 |
| -echo -e "\n${BLUE}################################" |
10 |
| -echo -e "${BLUE}#### INSTALL.SH ####${ENDCOLOR}" |
11 |
| -echo -e "${BLUE}################################" |
| 5 | +cd "$WORKSPACE_PATH/.devcontainer/install" |
12 | 6 |
|
13 |
| -echo -e "\n${GREEN}> Configure virtual environment.${ENDCOLOR}\n" |
| 7 | +CONTAINER_TYPE=$(jq -r '.customizations.vscode.settings."container.type"' $WORKSPACE_PATH/.devcontainer/devcontainer.json); |
| 8 | +echo -e "\n${BLUE}You are about to initiate a project '${YELLOW}$CONTAINER_TYPE${BLUE}'.${ENDCOLOR}" |
14 | 9 |
|
15 |
| -sudo chgrp vscode /workspaces/app/.venv |
16 |
| -sudo chown vscode /workspaces/app/.venv |
17 |
| - |
18 |
| -git config --global --add safe.directory /workspaces/app |
19 |
| -git config --global core.eol lf |
20 |
| -git config --global core.autocrlf false |
21 |
| - |
22 |
| -python3 -m venv /workspaces/app/.venv |
23 |
| -PATH="/workspaces/app/.venv/bin:$PATH" |
24 |
| - |
25 |
| -echo -e "Done.\n" |
26 |
| - |
27 |
| -echo -e "${GREEN}> Update PIP tool.${ENDCOLOR}\n" |
28 |
| -pip install --upgrade pip |
29 |
| - |
30 |
| -echo -e "\n${GREEN}> Identify the packaging and dependency manager to install.${ENDCOLOR}\n" |
31 |
| - |
32 |
| -PIP_MANAGER=false |
33 |
| -POETRY_MANAGER=false |
34 |
| - |
35 |
| -NEW_POETRY_INSTALL=false |
36 |
| - |
37 |
| -FILE=/workspaces/app/requirements.txt |
38 |
| - |
39 |
| -if [ -f "$FILE" ]; |
40 |
| -then |
41 |
| - echo -e "PIP configuration file was found (requirements.txt).\n" |
42 |
| - PIP_MANAGER=true |
43 |
| -fi |
44 |
| - |
45 |
| -FILE=/workspaces/app/pyproject.toml |
46 |
| - |
47 |
| -if [ -f "$FILE" ]; |
48 |
| -then |
49 |
| - echo -e "POETRY configuration file was found (pyproject.toml).${ENDCOLOR}" |
50 |
| - POETRY_MANAGER=true |
51 |
| -fi |
52 |
| - |
53 |
| -if [ "$POETRY_MANAGER" = true ] && [ "$PIP_MANAGER" = true ]; |
54 |
| -then |
55 |
| - echo -e "${RED}> ERROR: You cannot define two packaging and dependency manager in the same time.${ENDCOLOR}\n" |
| 10 | +if [ ]; then |
| 11 | + echo -e "\n💥 ${RED}Installation was aborted. Specified container type '$CONTAINER_TYPE' is not supported.${ENDCOLOR}💥\n" |
56 | 12 | exit 1
|
57 | 13 | fi
|
58 | 14 |
|
59 |
| -if [ "$POETRY_MANAGER" = false ] && [ "$PIP_MANAGER" = false ]; |
60 |
| -then |
61 |
| - |
62 |
| - echo -e "${YELLOW}No packaging and dependency manager was found.${ENDCOLOR}" |
63 |
| - echo -e "${YELLOW}Type 'PIP' or 'POETRY' if you want to install a packaging and dependency manager !${ENDCOLOR}" |
64 |
| - echo -e "${YELLOW}Another option will install no packaging and dependency manager.${ENDCOLOR}" |
65 |
| - echo -e "${YELLOW}Your selection :${ENDCOLOR}" |
| 15 | +install_files=() |
66 | 16 |
|
67 |
| - read MANAGER |
68 |
| - echo -e "The following packaging and dependency manager will be installed : $MANAGER\n" |
69 |
| - |
70 |
| - if [ "${MANAGER^^}" = "POETRY" ] |
71 |
| - then |
72 |
| - POETRY_MANAGER=true |
73 |
| - NEW_POETRY_INSTALL=true |
| 17 | +while IFS= read -r -d $'\0' current_file ; do |
| 18 | + if ! grep -q "# ignored: $CONTAINER_TYPE" "$current_file"; then |
| 19 | + install_files+=("$current_file") |
74 | 20 | fi
|
| 21 | +done < <(find ./ -type f -name "*.sh" -print0) |
75 | 22 |
|
76 |
| - if [ "${MANAGER^^}" = "PIP" ] |
77 |
| - then |
78 |
| - PIP_MANAGER=true |
79 |
| - touch /workspaces/app/requirements.txt |
80 |
| - touch /workspaces/app/requirements-dev.txt |
81 |
| - fi |
| 23 | +install_files=($(printf "%s\n" "${install_files[@]}" | sort)) |
82 | 24 |
|
83 |
| -fi |
84 |
| - |
85 |
| -source /workspaces/app/.venv/bin/activate |
| 25 | +echo -e "${BLUE}We have found ${YELLOW}${#install_files[@]}${BLUE} installation files.${ENDCOLOR}" |
86 | 26 |
|
87 |
| -if [ "$PIP_MANAGER" = true ]; |
88 |
| -then |
| 27 | +for install_file in "${install_files[@]}"; do |
| 28 | + if [ -f "$install_file" ]; then |
89 | 29 |
|
90 |
| - echo -e "${GREEN}> Install dependencies with PIP.${ENDCOLOR}\n" |
| 30 | + echo -e "\n\e[104m Execute: $install_file \e[49m" |
91 | 31 |
|
92 |
| - # pip install keyring artifacts-keyring |
| 32 | + if [ ! -x "$install_file" ]; then |
| 33 | + chmod +x "$install_file" |
| 34 | + fi |
93 | 35 |
|
94 |
| - # cat <<EOF >> /workspaces/app/.venv/pip.conf |
95 |
| - # [global] |
96 |
| - # extra-index-url=https://pkgs.dev.azure.com/... |
97 |
| - # EOF |
| 36 | + ./"$install_file" |
98 | 37 |
|
99 |
| - pip install -r /workspaces/app/requirements-dev.txt |
100 |
| - pip install -r /workspaces/app/requirements.txt |
| 38 | + if [ "$?" -ge 1 ]; then |
| 39 | + echo -e "\n💥 ${RED}Installation was aborted. Check the errors displayed above.${ENDCOLOR}💥\n" |
| 40 | + exit 1 |
| 41 | + else |
| 42 | + echo -e "${YELLOW}... Press any key to continue ..." |
| 43 | + read -s -p " " -n 1 -r |
| 44 | + echo -e "${ENDCOLOR}" |
| 45 | + fi |
101 | 46 |
|
102 |
| -fi |
103 |
| - |
104 |
| -if [ "$POETRY_MANAGER" = true ]; |
105 |
| -then |
106 |
| - |
107 |
| - echo -e "${GREEN}> Install POETRY tool and install dependencies.${ENDCOLOR}\n" |
108 |
| - curl -sSL https://install.python-poetry.org | python3 - |
109 |
| - poetry completions bash >> ~/.bash_completion |
110 |
| - |
111 |
| - if [ "$POETRY_MANAGER" = true ]; |
112 |
| - then |
113 |
| - poetry init |
114 | 47 | fi
|
| 48 | +done |
115 | 49 |
|
116 |
| - poetry install |
117 |
| - |
118 |
| -fi |
119 |
| - |
120 |
| -chmod +x /workspaces/app/.devcontainer/check-post-install.sh |
121 |
| -/workspaces/app/.devcontainer/check-post-install.sh |
| 50 | +echo -e "🎉 ${YELLOW}Installation is finished!${ENDCOLOR}" |
| 51 | +echo -e "🎉 ${YELLOW}You can close all terminal windows and reload the project!${ENDCOLOR}\n" |
0 commit comments