-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
executable file
·127 lines (92 loc) · 2.31 KB
/
install
File metadata and controls
executable file
·127 lines (92 loc) · 2.31 KB
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
help(){
echo " ------- Options -------"
echo " -f, --file filename content of file is getting used"
echo " -h, --help to see help"
}
usage(){
echo "Usage: $0 [-h] [-f <filename>]" 1>&2
}
exit_abnormal() {
usage
exit
}
# : wants argument
VALID_ARGS=$(getopt -o hf: --long help,file: -- "$@")
if [[ $? -ne 0 ]]; then
exit 1;
fi
eval set -- "$VALID_ARGS"
while [ : ]; do
case "$1" in
-f | --file)
f="TRUE"
fvalue="$2"
shift 2
;;
-h | --help)
usage
echo ""
help
exit
;;
--) shift;
break
;;
esac
done
if [ "$f" == "TRUE" ] ; then
if [ ! -f "$fvalue" ]; then
echo "$fvalue does not exist."
exit 1
fi
fi
# Use '/usr/local/', because /usr/ is for the system and /usr/local/ is for the user and not system related
LIB_FILE="/usr/local/lib" # the directory for the library
BIN_FILE="/usr/local/bin" # the directory for the binary
NEW_NAME=".cd.."
echo "start installing cd.. ..."
CUR_PATH="$(pwd)"
PARENT="$(dirname "$CUR_PATH")"
IMAGE_PATH="$CUR_PATH/default.txt"
if [ "$f" == "TRUE" ] ; then
IMAGE_PATH="$fvalue"
fi
if [ ! -f "$CUR_PATH/cd.." ]; then
echo "$CUR_PATH/cd.. does not exist."
exit 1
fi
if [ -f "$BIN_FILE/cd.." ]; then
echo "$BIN_FILE/cd.. already exists"
exit 1
fi
{
echo -n "Creating $NEW_NAME ..." &&
sudo mkdir "$PARENT/$NEW_NAME" &&
echo "Done" &&
echo -n "moving cd.. to $NEW_NAME ..." &&
sudo mv "$CUR_PATH/cd.." "$PARENT/$NEW_NAME" &&
echo "Done" &&
echo -n "moving remove to $NEW_NAME ..." &&
sudo mv "$CUR_PATH/remove" "$PARENT/$NEW_NAME" &&
echo "Done" &&
echo -n "creating $LIB_FILE/cd.. ..." &&
sudo mkdir $LIB_FILE/cd.. &&
echo "Done" &&
echo -n "moving image to $LIB_FILE/cd.. ..." &&
sudo mv "$IMAGE_PATH" $LIB_FILE/cd.. &&
echo "Done" &&
echo -n "moving colorful_print to $LIB_FILE/cd.. ..." &&
sudo mv "$CUR_PATH/colorful_print" $LIB_FILE/cd.. &&
echo "Done" &&
echo -n "creating softlink $BIN_FILE/cd.. ..." &&
sudo ln -s "$PARENT/$NEW_NAME/cd.." "$BIN_FILE/cd.." &&
echo "Done"
} || { # catch
echo "Error"
exit 1
}
FILES_COUNT="$(ls | wc -l)"
echo "deleting..."
rm -rf "$CUR_PATH"
exit 1