-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·224 lines (222 loc) · 10.9 KB
/
install.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/usr/bin/env bash
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
##@Version : 202207042244-git
# @Author : Jason Hempstead
# @Contact : [email protected]
# @License : LICENSE.md
# @ReadME : README.md
# @Copyright : Copyright: (c) 2021 Jason Hempstead, CasjaysDev
# @Created : Wednesday, Feb 10, 2021 02:00 EST
# @File : install.sh
# @Description : My custom scripts
# @TODO : MacOS fixes/Re-write function/*
# @Other :
# @Resource :
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
APPNAME="scripts"
USER="${SUDO_USER:-${USER}}"
HOME="${USER_HOME:-${HOME}}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set bash options
if [ "$1" == "--debug" ]; then shift 1 && set -xo pipefail && export SCRIPT_OPTS="--debug" && export _DEBUG="on"; fi
export PATH="/usr/local/share/CasjaysDev/scripts/bin:$PATH"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Import functions
CASJAYSDEVDIR="${CASJAYSDEVDIR:-/usr/local/share/CasjaysDev/scripts}"
SCRIPTSFUNCTDIR="${CASJAYSDEVDIR:-/usr/local/share/CasjaysDev/scripts}/functions"
SCRIPTSFUNCTFILE="${SCRIPTSAPPFUNCTFILE:-app-installer.bash}"
SCRIPTSFUNCTURL="${SCRIPTSAPPFUNCTURL:-https://github.com/dfmgr/installer/raw/main/functions}"
connect_test() { ping -c1 ${1:-1.1.1.1} &>/dev/null || curl --disable -LSIs --connect-timeout 3 --retry 0 --max-time 1 ${1:-1.1.1.1} 2>/dev/null | grep -e "HTTP/[0123456789]" | grep -q "200" -n1 &>/dev/null || return 1; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -f "$PWD/$SCRIPTSFUNCTFILE" ]; then
. "$PWD/$SCRIPTSFUNCTFILE"
elif [ -f "$SCRIPTSFUNCTDIR/$SCRIPTSFUNCTFILE" ]; then
. "$SCRIPTSFUNCTDIR/$SCRIPTSFUNCTFILE"
elif connect_test; then
curl -q -LSsf "$SCRIPTSFUNCTURL/$SCRIPTSFUNCTFILE" -o "/tmp/$SCRIPTSFUNCTFILE" || exit 1
. "/tmp/$SCRIPTSFUNCTFILE"
else
echo "Can not load the functions file: $SCRIPTSFUNCTDIR/$SCRIPTSFUNCTFILE" 1>&2
exit 90
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Define pre-install scripts
run_pre_install() {
return ${?:-0}
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Define custom functions
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Call the main function
systemmgr_install
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Make sure the scripts repo is installed
#scripts_check
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Defaults
APPNAME="${APPNAME:-scripts}"
APPDIR="/usr/local/share/CasjaysDev/scripts"
INSTDIR="/usr/local/share/CasjaysDev/scripts"
REPO_BRANCH=${GIT_REPO_BRANCH:-main}
REPO="$SYSTEMMGRREPO/installer"
REPORAW="$REPO/raw/$REPO_BRANCH"
APPVERSION="$(__appversion "$REPORAW/version.txt")"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Setup plugins
PLUGNAMES=""
PLUGDIR="/usr/local/share/CasjaysDev/apps/$SCRIPTS_PREFIX"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Require a version higher than
systemmgr_req_version "$APPVERSION"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Call the systemmgr function
systemmgr_install
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Script options IE: --help
show_optvars "$@"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Requires root - no point in continuing
sudoreq "sudo -HE $0 $*" # sudo required
#sudorun # sudo optional
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Do not update - add --force to overwrite
#installer_noupdate "$@"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# initialize the installer
systemmgr_run_init
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# end with a space
if if_os mac; then
APP="jq sudo curl wget cowsay fortune "
elif if_os linux; then
APP="ruby expect byobu killall setcap nethogs iftop iotop iperf rsync locate pass python rsync "
APP+="bash ifconfig jq sudo curl wget dialog html2text cowsay fortune hostname vnstat"
fi
PERL="CPAN "
PYTH="pip "
PIPS="speedtest-cli "
CPAN=""
GEMS=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# install packages - useful for package that have the same name on all oses
install_packages "$APP"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# install required packages using file
install_required "$APP"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# check for perl modules and install using system package manager
install_perl "$PERL"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# check for python modules and install using system package manager
install_python "$PYTH"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# check for pip binaries and install using python package manager
install_pip "$PIPS"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# check for cpan binaries and install using perl package manager
install_cpan "$CPAN"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# check for ruby binaries and install using ruby package manager
install_gem "$GEMS"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Other dependencies
dotfilesreq
dotfilesreqadmin
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Ensure directories exist
ensure_dirs
ensure_perms
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Backup if needed
if [ -d "$APPDIR" ]; then
execute "backupapp $APPDIR $APPNAME" "Backing up $APPDIR"
fi
# Main progam
if __am_i_online; then
if [ -d "$INSTDIR/.git" ]; then
execute "git_update $INSTDIR" "Updating $APPNAME configurations"
else
execute "git_clone $REPO $INSTDIR" "Installing $APPNAME configurations"
fi
# exit on fail
failexitcode $? "Git has failed"
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# run post install scripts
run_postinst() {
systemmgr_run_post
motdDir="/etc/casjaysdev/messages"
bannerDir="/etc/casjaysdev/banners"
verDir="/etc/casjaysdev/updates/versions"
bashCompDir="${COMPDIR:-/etc/bash_completion.d}"
fontdir="$(ls -A "$CASJAYSDEVSAPPDIR/fontmgr/" 2>/dev/null | wc -l)"
get_pam_files_to_edit="$(grep -shRl 'dir=/var/spool/mail' /etc/pam.d/*)"
[ -f "/etc/casjaysdev/.legal_updated" ] || [ "$RESET_LEGAL" != "yes" ] || { [ -f "$motdDir/legal/000.txt" ] && rm -Rf "$motdDir/legal/000.txt"; }
ln_rm "$SHARE/applications/"
git config --global pull.rebase 'true'
systemctl enable --now vnstat &>/dev/null
mkdir -p "$HOME/.local/backups/systemmgr/installer/pam"
mkdir -p "/usr/local/share/CasjaysDev/apps/fontmgr"
mkdir -p "$motdDir/motd" "$motdDir/issue" "$motdDir/legal" "$bannerDir" "$verDir"
[ "$fontdir" = "0" ] && sudo fontmgr install Hack all-the-icons fontawesome LigatureSymbols
[ -d "/var/lib/srv/$USER/public" ] || { mkdir -p "/var/lib/srv/$USER/public" && chmod 777 "/var/lib/srv/$USER/public"; }
[ -d "/var/lib/srv/$USER/docker" ] || { mkdir -p "/var/lib/srv/$USER/docker" && chmod 777 "/var/lib/srv/$USER/docker"; }
for app in $(ls "$CASJAYSDEVDIR/applications"); do
ln_sf "$CASJAYSDEVDIR/applications/$app" "$SYSSHARE/applications/$app"
done
if { [ ! -f "$motdDir/legal/000.txt" ] || [ ! -f "/etc/casjaysdev/.legal_updated" ]; }; then
echo "$(date)" >"/etc/casjaysdev/.legal_updated"
[ -f "$INSTDIR/templates/casjaysdev-legal.txt" ] && cp_rf "$INSTDIR/templates/casjaysdev-legal.txt" "$motdDir/legal/000.txt"
fi
[ -f "$bannerDir/ssh.txt" ] || touch "$bannerDir/ssh.txt"
[ -f "$bannerDir/rsync.txt" ] || touch "$bannerDir/rsync.txt"
date +"%b %d, %Y at %H:%M" | sudo tee -p "$verDir/date.scripts.txt" &>/dev/null
[ -f "$INSTDIR/version.txt" ] && cp_rf "$INSTDIR/version.txt" "$verDir/scripts.txt"
[ -f "$verDir/date.configs.txt" ] || date +"%b %d, %Y at %H:%M" | sudo tee -p "$verDir/date.configs.txt" &>/dev/null
[ -f "$verDir/configs.txt" ] || date +"${VERSION_DATE_FORMAT:-%Y%m%d%H%M-git}" | sudo tee -p "$verDir/configs.txt" &>/dev/null
[ -n "$(type -P hostname 2>/dev/null)" ] || { [ -x "/usr/local/bin/hostnamecli" ] && ln_sf "/usr/local/bin/hostnamecli" "/usr/local/bin/hostname"; }
ln_sf "$APPDIR" "$SYSSHARE/CasjaysDev/$SCRIPTS_PREFIX/$APPNAME"
ln_sf "$APPDIR" "$SYSSHARE/CasjaysDev/$SCRIPTS_PREFIX/installer"
for f in $get_pam_files_to_edit; do
cp -Rf "$f" "/root/.local/backups/systemmgr/installer/pam/$(basename -- "$f").bak" && sed --follow-symlinks -i 's|dir=~/Maildir||g' "$f"
done
for user in root apache nginx www-user daemon nobody $USER; do
if grep -qs "^$user" /etc/passwd; then
if [ ! -d "/var/lib/srv/$USER" ]; then
mkdir -p "/var/lib/srv/$USER"
chmod -f 777 "/var/lib/srv/$USER"
chown -f $user "/var/lib/srv/$USER"
grep -qs "^$user" /etc/group && chgrp -f $user "/var/lib/srv/$USER"
fi
fi
done
for file in multi_clipboard se sentaku tdrop; do
[ -f "/usr/local/bin/$file" ] || ln_sf "$APPDIR/sources/$file" "/usr/local/bin/$file"
done
for mgr in devenvmgr dfmgr dockermgr fontmgr iconmgr passmgr pkmgr systemmgr thememgr wallpapermgr; do
eval "$mgr" --config &>/dev/null
done
replace "$motdDir/" "MYHOSTIP_4" "$CURRENT_IP_4"
replace "$motdDir/" "MYHOSTIP_6" "${CURRENT_IP_6:-::1}"
replace "$motdDir/" "MY_FULL_HOSTNAME" "$(hostname -f)"
replace "$motdDir/" "MY_SHORT_HOSTNAME" "$(hostname -s)"
cmd_exists update-ip && update-ip &>/dev/null
cmd_exists update-motd && update-motd &>/dev/null
cmd_exists dockermgr && dockermgr --cron &>/dev/null
grep 'Defaults.*.env_reset' "/etc/sudoers" | grep -q '!' || sudo sed -i 's|env_reset|!env_reset|g' "/etc/sudoers"
grep 'Defaults.*.secure_path' "/etc/sudoers" && sudo sed -i 's|secure_path =.*|secure_path = "/usr/local/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/sbin:/bin"|g' "/etc/sudoers"
echo 'for f in '"$CASJAYSDEVDIR/completions"/*'; do source "$f" >/dev/null 2>&1; done' >"$bashCompDir/_my_scripts_completions"
printf '%s: %s\n' "$(__os_name)" "$(__os_version)" | sed 's| [lL]inux:||g' | sudo tee -p "$verDir/osversion.txt" &>/dev/null
printf '%s' '# update scripts \n5 4 * * * root '$APPDIR/bin/systemmgr' update scripts cron ssl >/var/log/systemmgr\n' | sudo tee -p "/etc/cron.d/systemmgr" &>/dev/null
printf '%s' '# Fix resolver \n*/5 * * * * root [ -f "/etc/resolv.conf" ] || echo nameserver 1.1.1.1 >/etc/resolv.conf\n' | sudo tee -p "/etc/cron.d/update-resolver" &>/dev/null
__os_fix_name "$verDir/osversion.txt"
}
#
execute "run_postinst" "Running post install scripts"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# create version file
systemmgr_install_version
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# exit
run_exit
# end