-
Notifications
You must be signed in to change notification settings - Fork 1
/
install-scratch-files.sh
executable file
·132 lines (108 loc) · 4.08 KB
/
install-scratch-files.sh
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash
##############################################################
# Script Name : Install Scratch Files
# Description : Clones the Scratch-VM and Scratch-GUI
# repositories to the parent folder, if they do
# not already exist. The script also takes care
# of the installation of the different repos.
##############################################################
ITALIC="\033[3m"
GREEN="\033[92m"
YELLOW="\033[93m"
CLEAR="\033[0m"
installation_folder=".."
##############################################################
# Function clone_repository()
# Clones a github repository in a given folder if the repo is
# not already cloned.
#
# ARGUMENTS:
# $1: repo link
# $2: folder
#
# OUTPUTS:
# Some echos of the progress of the script
##############################################################
clone_repository() {
repo_name=$(basename -s .git "$1")
echo -e "Cloning ${ITALIC}${YELLOW}$repo_name${CLEAR}"
if [ -d "$2/$repo_name" ]; then
# code if found
echo -e "${GREEN}Repository already installed!${CLEAR}\n"
else
# code if not found
echo -e "${YELLOW}Repository not installed!${CLEAR}"
git clone "$1" "$2/$repo_name"
echo -e "${GREEN}Repository has been installed!${CLEAR}\n"
fi
}
# Cloning vm & gui repos
# if VM:
# if GUI:
# nothing to do, exit script
# else:
# install GUI
# else:
# if GUI
# install VM
# else:
# install VM & GUI
if [ -d "$installation_folder/scratch-vm" ]
then
if [ -d "$installation_folder/scratch-gui" ]
then
echo -e "${GREEN}Nothing to do${CLEAR}"
echo -e "Script found scratch-vm & scratch-gui repositories in ${installation_folder}/ folder."
echo -e "If you have not installed these folders using the Poppy script, you have three choices to continue the installation:"
echo -e "- Delete the existing folders to get a fresh start and then re-run this script (install-scratch-files)."
echo -e "- Change the installation folder to reclone the Scratch folders elsewhere"
echo -e "- Install the folders by hand, following the steps described in the README, in the manual installation section."
exit 0
else
echo -e "${YELLOW}> Installing GUI${CLEAR}"
clone_repository "https://github.com/LLK/scratch-gui.git" $installation_folder
fi
else
if [ -d "$installation_folder/scratch-gui" ]
then
echo -e "${YELLOW}> Installing VM${CLEAR}"
clone_repository "https://github.com/LLK/scratch-vm.git" $installation_folder
else
echo -e "${YELLOW}> Installing VM & GUI${CLEAR}"
clone_repository "https://github.com/LLK/scratch-vm.git" $installation_folder
clone_repository "https://github.com/LLK/scratch-gui.git" $installation_folder
fi
fi
echo -e "\n${GREEN}All repositories are downloaded!${CLEAR}\n"
# Installing nvm
echo -e "${YELLOW}Installing nvm...${CLEAR}"
cd "$installation_folder/scratch-vm" || exit 2
curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh -o install_nvm.sh
bash install_nvm.sh
source ~/.profile
rm install_nvm.sh
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
nvm install 10.21.0
nvm use 10.21.0
echo -e "${GREEN}NVM installed!${CLEAR}\n"
# Installing scratch-vm node modules
echo -e "${YELLOW}Installing scratch-vm node modules...${CLEAR}"
npm install
echo -e "${GREEN}scratch-vm node modules installed!${CLEAR}\n"
# Linking scratch-vm
echo -e "${YELLOW}Linking scratch-vm...${CLEAR}"
npm link
echo -e "${GREEN}scratch-vm linked!${CLEAR}\n"
# Changing directory to scratch-gui
cd ../scratch-gui || exit 2
# Installing scratch-gui node modules
echo -e "${YELLOW}Installing scratch-gui node modules...${CLEAR}"
npm install
echo -e "${GREEN}scratch-gui node modules installed!${CLEAR}\n"
# Installing scratch-vm node modules
echo -e "${YELLOW}Linking scratch-gui to scratch-vm...${CLEAR}"
npm link scratch-vm
echo -e "${GREEN}scratch-gui linked to scratch-vm!${CLEAR}\n"
# Success message
echo -e "${GREEN}Installation of scratch files complete!${CLEAR}"