-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
executable file
·127 lines (90 loc) · 2.92 KB
/
update.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
#!/bin/bash
echo "PrivateAsk update script started"
baseGitDir=$PWD
function usage {
cat << EOT
Usage : $0 [options]
Options:
-h -? --help Display this message
-y --yes Do not ask any questions, auto respond yes to all
This script is part of PrivateAsk, an open source project by Anestis Varsamidis
Source at http://github.com/anestv/pa
EOT
}
# Handle command line arguments
for opt in $*; do
case "$opt" in
-h|-\?|--help) usage; exit 0;;
-y|--yes) alwaysYes="y";;
*) echo "Unknown option: $opt Run $0 --help for help"; exit 1;;
esac
done
# Args: 1: (string) Prompt / question to user
# 2: (int) 1 to run $3 if user said yes, 0 to run $3 if user didn't say yes
# 3: (string) commands to execute
# Example: ask_user_yes_no "Build Semantic?" 1 "echo Building"
# Example: ask_user_yes_no "Do you really want to continue?" 0 "echo Exiting; exit 0"
function ask_user_yes_no {
if [ "$alwaysYes" = "y" ]; then
true
else
echo -e "$1 (y/n)"
read ans
[[ "$ans" =~ ^[yY]([eE][sS])?$ ]] # we will use its retrn code
fi
if (( $2 ^ $? )); then
eval $3
fi
}
# warning, we only tested on Ubuntu
source /etc/lsb-release
if [ "$DISTRIB_ID" != "Ubuntu" ]; then
ask_user_yes_no "This script has only been tested in Ubuntu 14.04. Continue?"\
0 "exit 0"
fi
echo
# prints error if program not installed
function check_program_installed {
# set to 0 initially
local error=0
# set to 1 if not found
type $1 >/dev/null 2>&1 || { local error=1; }
if [ $error = 1 ]; then
echo "ERROR: $1 is not installed. Please install $1 and try again"
exit 1
fi
}
# check dependencies
check_program_installed git
check_program_installed npm
check_program_installed composer
# check for uncommited changes
git diff --exit-code --quiet
if [ $? != 0 ]; then
ask_user_yes_no "It seems some files at your working directory have uncommitted changes.
It is recommended to commit your changes. Continue without committing?"\
0 "exit 0"
fi
echo "Running composer install..."
composer install --no-interaction
# install (or update) Semantic UI
echo "Installing Seamntic UI ..."
npm install semantic-ui
cd node_modules/semantic-ui
echo "Running npm install..."
npm install
ask_user_yes_no "npm install usually resets src/site/ and dist/. Do you want to git checkout?"\
1 "git checkout dist/ src/site/ src/theme.config semantic.json"
ask_user_yes_no "Remove unneeded folders (examples, src/_site, test)?"\
1 "rm -rf examples src/_site test"
cd src/themes
ask_user_yes_no "Do you want to remove Semantic's unused theme folders?"\
1 "find * -maxdepth 0 ! -name 'default' -type d -exec rm -rf {} +"
# remove all except default
cd ../..
ask_user_yes_no "Do you want to build Semantic UI? Recommended if updated"\
1 "gulp build"
# note, we are still on node_modules/semantic-ui
echo
echo "Script complete!"
echo "Some useless files may have been created (e.g. composer.lock)"