-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathinstall_script_tools.sh
executable file
·77 lines (63 loc) · 2.09 KB
/
install_script_tools.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
#! /bin/bash
PIHOME=/home/pi
DEXTER=Dexter
LIB=lib
DEXTER_PATH=$PIHOME/$DEXTER/$LIB/$DEXTER
DEXTER_SCRIPT=$DEXTER_PATH/script_tools
selectedbranch=master
################################################
######## Run a series of checks ################
################################################
# called way down bellow
check_if_run_with_pi() {
## if not running with the pi user then exit
if [ $(id -ur) -ne $(id -ur pi) ]; then
echo "script_tools installer script must be run with \"pi\" user. Exiting."
exit 2
fi
}
check_dependencies() {
command -v git >/dev/null 2>&1 || { echo "installing git"; sudo apt install git -y; }
}
################################################
########### Parse arguments ####################
################################################
parse_arguments() {
# iterate through bash arguments
for i; do
case "$i" in
develop|feature/*|hotfix/*|fix/*|DexterOS*|v*)
selectedbranch="$i"
;;
esac
done
}
################################################
######## Cloning script_tools #################
################################################
clone_scriptools(){
# create folders recursively if they don't exist already
# can't use <<functions_library.sh>> here because there's no
# cloned script_tools yet at this part of the install script
pushd $PIHOME > /dev/null
sudo mkdir -p $DEXTER_PATH
sudo chown pi:pi -R $PIHOME/$DEXTER
popd > /dev/null
# it's simpler and more reliable (for now) to just delete the repo and clone a new one
# otherwise, we'd have to deal with all the intricacies of git
sudo rm -rf $DEXTER_SCRIPT
pushd $DEXTER_PATH > /dev/null
git clone --quiet --depth=1 -b $selectedbranch https://github.com/DexterInd/script_tools.git
cd $DEXTER_SCRIPT
# useful in case we need it
current_branch=$(git branch | grep \* | cut -d ' ' -f2-)
popd > /dev/null
}
################################################
######## Aggregating all function calls ########
################################################
check_if_run_with_pi
parse_arguments "$@"
check_dependencies
clone_scriptools
exit 0