-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathsetup.sh
executable file
·149 lines (132 loc) · 3.92 KB
/
setup.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env bash
INSTALL_DIR="/usr/local/bin"
CONFIG_DIR="$HOME/.config/ronema"
SRC_DIR="src"
function copy_files() {
local source_path=$1
local destination_path=$2
local item=$3
if cp -r "$source_path/$item" "$destination_path"; then
echo "Copied $item to $destination_path."
else
echo "Error: Failed to copy $item to $destination_path."
exit 1
fi
}
function copy_main_script() {
local source_path=$1
local destination_path=$2
if [ ! -w "$destination_path" ]; then
echo "Info: You do not have write permissions for $destination_path."
echo "Attempting to use sudo to copy and change permissions."
sudo cp "$source_path/ronema" "$destination_path"
sudo chmod +x "$destination_path/ronema"
echo "Changed permissions of ronema to executable using sudo."
else
cp "$source_path/ronema" "$destination_path"
chmod +x "$destination_path/ronema"
echo "Copied ronema to $destination_path."
echo "Changed permissions of ronema to executable."
fi
}
function install() {
mkdir -p "$CONFIG_DIR"
copy_main_script "$SRC_DIR" "$INSTALL_DIR"
for item in languages themes icons ronema.conf; do
copy_files "$SRC_DIR" "$CONFIG_DIR" "$item"
done
echo "Ronema has been successfully installed"
echo "Configuration files are stored in $CONFIG_DIR."
echo "You can execute 'ronema' to run the program."
}
function uninstall() {
local remove_conf=false
while getopts ":h-:" opt; do
case $opt in
-)
case $OPTARG in
remove_config)
remove_conf=true
;;
*)
echo "Invalid option: --$OPTARG" >&2
exit 1
;;
esac
;;
h)
echo "Usage: $0 uninstall [--remove_config]" >&2
exit
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
sudo rm -f "$INSTALL_DIR/ronema"
if [ "$remove_conf" = true ]; then
sudo rm -rf "$CONFIG_DIR"
fi
echo "Ronema has been successfully uninstalled."
if [ "$remove_conf" = true ]; then
echo "Configuration files have been removed."
else
echo "Configuration files remain in $CONFIG_DIR."
fi
}
function update() {
local override_conf=false
while getopts ":h-:" opt; do
case $opt in
-)
case $OPTARG in
override_conf)
override_conf=true
;;
*)
echo "Invalid option: --$OPTARG" >&2
exit 1
;;
esac
;;
h)
echo "Usage: $0 update [--override_conf]" >&2
exit
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
copy_main_script "$SRC_DIR" "$INSTALL_DIR"
for item in languages themes icons; do
copy_files "$SRC_DIR" "$CONFIG_DIR" "$item"
done
if [ "$override_conf" = true ]; then
copy_files "$SRC_DIR" "$CONFIG_DIR" "ronema.conf"
else
echo "Skipping copying ronema.conf as --override_conf option is not provided."
fi
echo "Ronema has been successfully updated."
echo "Configuration files are stored in $CONFIG_DIR."
echo "You can execute 'ronema' to run the program."
}
case "$1" in
install)
install
;;
uninstall)
shift
uninstall "$@"
;;
update)
shift
update "$@"
;;
*)
echo "Usage: $0 {install|uninstall [--remove_config]|update [--override_conf]}" >&2
exit 1
;;
esac