-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.sh
executable file
·78 lines (61 loc) · 2.4 KB
/
init.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
#!/usr/bin/env bash
# add code to bashrc file so deploy can be used
# check if alias exists, if not add it.
declare deployerAlias="dep"
declare auxilary="${HOME}/.bashrc_deployer_auxilary"
declare mainFile="${HOME}/.bashrc"
declare installationDirectory="/usr/local/bin"
currentDirectory=$(pwd)
if [[ ! -f $currentDirectory/init.sh ]]; then
echo 'This script needs to run from inside the deployer folder, aborting...'
elif [[ ! -f $mainFile ]]; then
echo "$mainFile file not found!"
else
echo 'Checking for deployer installation...'
echo 'Creating $auxilary file'
touch $auxilary
if [[ ! -f $installationDirectory/$deployerAlias ]]; then
echo 'Sorting out file permissions...'
chmod -R 0777 ./core
echo 'Creating symlink...'
if [[ ! -d $installationDirectory ]]; then
echo ">>> ERROR: Directory $installationDirectory does not exist!"
return;
fi
sudo ln -s $currentDirectory/core/loader.sh $installationDirectory/$deployerAlias
if [[ $? != 0 ]]; then
echo "ERROR>>> Was unable to create symlink! Check permissions on $installationDirectory"
fi
if [[ ! -f $currentDirectory/config/main.sh ]]; then
source $currentDirectory/core/vars/core.sh
echo 'Setup current project'
cp $currentDirectory/config/$projectFileDistributable $currentDirectory/config/$projectFile
fi
echo 'Adding alias reload to bashrc'
echo "alias reload='source $mainFile'" >> $auxilary
echo 'Adding alias project to bashrc'
echo "alias project=\"reload && cd \$(IFS=' ' read -ra chunks <<< \$($deployerAlias p); echo \${chunks[3]})\"" >> $auxilary
# Change the alias inside files so it works
sed -i'.bk' s/deployerAlias=.*/deployerAlias=$deployerAlias/ "$currentDirectory/core/loader.sh"
else
echo 'Already installed...'
fi
echo 'Detecting OS: '$OSTYPE
case $OSTYPE in
"darwin"* )
echo 'Supported OS';;
"linux"* )
echo 'Supported OS, adding aliases to bashrc file to normalise deployer environment'
echo '# Deployer aliases' >> $auxilary
echo "alias $deployerAlias='bash $deployerAlias'" >> $auxilary
echo '# End of deployer aliases and functions' >> $auxilary
echo 'Make sure the bashrc file is sourced before using the deployer command';;
* )
echo 'Unsupported OS';;
esac
echo "Adding $auxilary file path to $mainFile";
echo "source $auxilary" >> "$mainFile"
source "$mainFile"
echo "Use the '$deployerAlias' command to get started..."
fi
echo 'Done.'