-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.bsh
executable file
·78 lines (69 loc) · 3.29 KB
/
install.bsh
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
#!/bin/bash
######################################################################
######################################################################
## Author: Adam Michael Danischewski
## GitHub: https://github.com/AdamDanischewski/cf
## Created: 2019-11-12
## Version: v1.05
## Last Modified: 2019-12-07
## Issues: If you find any issues emai1 me at <my first name> (dot)
## <my last name> (at) gmail (dot) com.
##
## Description: simple cf installer / remover
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
##
## Released under Creative Commons License: CC BY-SA 4.0
## https://creativecommons.org/licenses/by-sa/4.0/
########################################################################
#######################################################################
declare CP_CMD="$(type -P cp)"
declare RM_CMD="$(type -P rm)"
declare RMDIR_CMD="$(type -P rmdir)"
declare MKDIR_CMD="$(type -P mkdir)"
declare SUDO_CMD="$(type -P sudo)"
declare GZIP_CMD="$(type -P gzip)"
declare each=""
declare user=""
declare STARTCOLOR="\033[38;2;" ## ANSI TrueColor RGB triplet prefix
declare ENDCOLOR="\033[0m" ## End ANSI color
declare ERROR_COLOR="${STARTCOLOR}255;0;0m"
declare USAGE_COLOR1="${STARTCOLOR}0;190;190m"
declare USAGE_COLOR2="${STARTCOLOR}108;179;251m"
declare USAGE_COLOR3="${STARTCOLOR}215;107;21m"
declare USAGE_COLOR4="${STARTCOLOR}206;68;67m"
declare USAGE_COLOR5="${STARTCOLOR}110;218;24m"
declare USAGE_COLOR6="${STARTCOLOR}218;254;25m"
declare USAGE_COLOR7="${STARTCOLOR}218;254;218m"
if [[ "${1}" =~ ^-[^R] ]]; then
printf "${USAGE_COLOR1}%s${ENDCOLOR} ${USAGE_COLOR6}%s${ENDCOLOR} ${USAGE_COLOR2}%s${ENDCOLOR}\n" "Usage:" "install" "[-R (remove)]"
printf "${USAGE_COLOR5}%s${ENDCOLOR}\n" " ** Installs or removes the cf program."
exit 0
fi
if [[ "${1}" =~ ^-R ]]; then
printf "${USAGE_COLOR3}%s${ENDCOLOR}\n" "Removing cf ..."
## First try to get rid of any aliases generated by cf.
for each in root /home/*; do
user="$(basename "$each")"
printf "${USAGE_COLOR1}%s${ENDCOLOR}\n" "Removing cf generated aliases for ${user} ..."
"$SUDO_CMD" -u "$user" /usr/bin/cf -R 2>/dev/random
done
"$SUDO_CMD" "$RM_CMD" -f /usr/bin/cf /usr/lib/colorfiles /usr/share/man/man1/cf.1.gz /usr/share/man/man1/cf_config.1.gz 2>/dev/random
"$SUDO_CMD" "$RMDIR_CMD" -rf /etc/cf 2>/dev/random
printf "${USAGE_COLOR5}%s${ENDCOLOR} ${USAGE_COLOR6}%s${ENDCOLOR} ${USAGE_COLOR2}%s${ENDCOLOR}\n" 'Done!!' "cf" 'has been removed!'
else
printf "${USAGE_COLOR5}%s${ENDCOLOR}\n" "Copying cf files to targets ..."
"$SUDO_CMD" "$CP_CMD" ./cf /usr/bin
"$SUDO_CMD" "$CP_CMD" ./colorfiles /usr/lib
"$SUDO_CMD" "$MKDIR_CMD" -p /etc/cf
printf "${USAGE_COLOR5}%s${ENDCOLOR}\n" "Copying default cf config ..."
"$SUDO_CMD" "$CP_CMD" ./cf_default.conf /etc/cf/
printf "${USAGE_COLOR5}%s${ENDCOLOR}\n" "Gzip'ing man pages ..."
"$SUDO_CMD" "$GZIP_CMD" -9 -n cf.1 cf_config.1 2>/dev/random
printf "${USAGE_COLOR5}%s${ENDCOLOR}\n" "Copying man pages ..."
"$SUDO_CMD" "$CP_CMD" cf.1.gz cf_config.1.gz /usr/share/man/man1/
printf "${USAGE_COLOR5}%s${ENDCOLOR} ${USAGE_COLOR2}%s${ENDCOLOR} ${USAGE_COLOR6}%s${ENDCOLOR}\n" 'Done!!' "Try running:" "cf -?"
fi
exit 0