-
Notifications
You must be signed in to change notification settings - Fork 1
/
install-idea.sh
executable file
·115 lines (97 loc) · 2.84 KB
/
install-idea.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
#!/bin/bash
idea_dist=""
default_idea_dir="/opt"
idea_installation_dir="$default_idea_dir"
function usage() {
echo ""
echo "This script will not download the Idea distribution. You must download Idea tar.gz distribution. Then use this script to install it."
echo "Usage: "
echo "install-idea.sh -f <idea_dist> [-p <idea_installation_dir>]"
echo ""
echo "-f: The idea tar.gz file."
echo "-p: IntelliJ Idea installation directory. Default: $default_idea_dir."
echo "-h: Display this help and exit."
echo ""
}
function confirm() {
# call with a prompt string or use a default
read -r -p "${1:-Are you sure?} [y/N] " response
case $response in
[yY][eE][sS] | [yY])
true
;;
*)
false
;;
esac
}
# Make sure the script is not running as root.
if [ "$UID" == "0" ]; then
echo "You must not be root to run $0. Try following"
echo "$0"
exit 9
fi
while getopts "f:p:h" opts; do
case $opts in
f)
idea_dist=${OPTARG}
;;
p)
idea_installation_dir=${OPTARG}
;;
h)
usage
exit 0
;;
\?)
usage
exit 1
;;
esac
done
if [[ ! -f $idea_dist ]]; then
echo "Please specify the Idea distribution file."
echo "Use -h for help."
exit 1
fi
# Validate Idea Distribution
idea_dist_filename=$(basename $idea_dist)
if [[ ${idea_dist_filename: -7} != ".tar.gz" ]]; then
echo "Idea distribution must be a valid tar.gz file."
exit 1
fi
# Create the default directory if user has not specified any other path
if [[ $idea_installation_dir == $default_idea_dir ]]; then
mkdir -p $idea_installation_dir
fi
#Validate idea directory
if [[ ! -d $idea_installation_dir ]]; then
echo "Please specify a valid Idea installation directory."
exit 1
fi
echo "Installing: $idea_dist_filename"
# Check Idea executable
idea_exec="$(tar -tzf $idea_dist | grep ^[^/]*/bin/idea.sh$ || echo "")"
if [[ -z $idea_exec ]]; then
echo "Could not find \"idea.sh\" executable in the distribution. Please specify a valid Idea distribution."
exit 1
fi
# Idea Directory with version
idea_dir="$(echo $idea_exec | cut -f1 -d"/")"
extracted_dirname=$idea_installation_dir"/"$idea_dir
# Extract Idea Distribution
if [[ ! -d $extracted_dirname ]]; then
echo "Extracting $idea_dist to $idea_installation_dir"
sudo tar -xof $idea_dist -C $idea_installation_dir
echo "Idea is extracted to $extracted_dirname"
else
echo "WARN: Idea was not extracted to $idea_installation_dir. There is an existing directory with the name \"$idea_dir\"."
if ! (confirm "Do you want to continue?"); then
exit 1
fi
fi
if [[ ! -f "${extracted_dirname}/bin/idea.sh" ]]; then
echo "ERROR: The path $extracted_dirname is not a valid Idea installation."
exit 1
fi
bash $extracted_dirname/bin/idea.sh