mirror of
https://github.com/Matir/skel.git
synced 2026-05-25 21:19:09 -07:00
Cleanup install.sh
This commit is contained in:
62
install.sh
62
install.sh
@@ -12,22 +12,24 @@ HOME=${HOME:-$(cd ~ && pwd)}
|
|||||||
case $(uname) in
|
case $(uname) in
|
||||||
Linux)
|
Linux)
|
||||||
FINDTYPE="-xtype"
|
FINDTYPE="-xtype"
|
||||||
|
MD5CMD="md5sum"
|
||||||
;;
|
;;
|
||||||
Darwin|*BSD)
|
Darwin|*BSD)
|
||||||
FINDTYPE="-type"
|
FINDTYPE="-type"
|
||||||
|
MD5CMD="md5 -q"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Unknown OS: $(uname), guessing no GNU utils."
|
echo "Unknown OS: $(uname), guessing no GNU utils."
|
||||||
FINDTYPE="-type"
|
FINDTYPE="-type"
|
||||||
|
MD5CMD="md5sum"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
is_comment() {
|
is_comment() {
|
||||||
if [ "$(echo "${1}" | cut -c1-1)" = '#' ] ; then
|
case "${1}" in
|
||||||
true
|
\#*) return 0 ;;
|
||||||
else
|
*) return 1 ;;
|
||||||
false
|
esac
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
have_command() {
|
have_command() {
|
||||||
@@ -42,10 +44,8 @@ prerequisites() {
|
|||||||
*/zsh)
|
*/zsh)
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
if [ "$(id)" -ne 0 ] ; then
|
echo "Your login shell is not zsh. To change it, run:" >&2
|
||||||
echo 'Enter password to change shell.' >&2
|
echo "chsh -s $(command -v zsh)" >&2
|
||||||
fi
|
|
||||||
chsh -s "$(command -v zsh)"
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
@@ -144,22 +144,16 @@ ssh_key_already_installed() {
|
|||||||
if [ ! -f "$AK" ] ; then
|
if [ ! -f "$AK" ] ; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
local KEYFP="$(ssh-keygen -l -f "$1" 2>/dev/null | awk '{print $2}')"
|
# Extract the key data (field 2) from the key file, ignoring comments
|
||||||
local TMPF="$(mktemp)"
|
local key_data
|
||||||
local key
|
key_data=$(awk '/^ssh-/ {print $2}' "$1")
|
||||||
while read -r key ; do
|
if [ -z "${key_data}" ]; then
|
||||||
if is_comment "${key}" ; then
|
# Not a valid key file
|
||||||
continue
|
return 1
|
||||||
fi
|
fi
|
||||||
echo "$key" > "$TMPF"
|
# Use grep with fixed-string matching to see if the key is present.
|
||||||
local EFP="$(ssh-keygen -l -f "${TMPF}" 2>/dev/null | awk '{print $2}')"
|
# The exit code of grep is 0 on match, 1 on no match, which is perfect.
|
||||||
if [ "$EFP" = "$KEYFP" ] ; then
|
grep -F -q -- "${key_data}" "${AK}"
|
||||||
rm "$TMPF" 2>/dev/null
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
done < "${AK}"
|
|
||||||
rm "$TMPF" 2>/dev/null
|
|
||||||
return 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
install_ssh_keys() {
|
install_ssh_keys() {
|
||||||
@@ -270,7 +264,7 @@ setup_git_email() {
|
|||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
local domain="$(hostname -f | grep -E -o '[a-z0-9-]+\.[a-z0-9-]+$')"
|
local domain="$(hostname -f | grep -E -o '[a-z0-9-]+\.[a-z0-9-]+$')"
|
||||||
case "$(echo "${domain}" | md5sum | awk '{print $1}')" in
|
case "$(echo "${domain}" | ${MD5CMD} | awk '{print $1}')" in
|
||||||
b21a24d528346ef7d3932306ed96ede5|a5ed434a3f5089b489576cceab824f25)
|
b21a24d528346ef7d3932306ed96ede5|a5ed434a3f5089b489576cceab824f25)
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
@@ -377,8 +371,9 @@ install_main() {
|
|||||||
|
|
||||||
install_dconf() {
|
install_dconf() {
|
||||||
have_command dconf || return 1
|
have_command dconf || return 1
|
||||||
find "${BASEDIR}/dconf" -type f -printf '/%P\n' | while read -r dcpath ; do
|
find "${BASEDIR}/dconf" -type f | while read -r fullpath ; do
|
||||||
dconf load "${dcpath}/" < "${BASEDIR}/dconf/${dcpath}"
|
local dcpath="/${fullpath#"${BASE-DIR}/dconf/"}"
|
||||||
|
dconf load "${dcpath}/" < "${fullpath}"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -419,17 +414,6 @@ if [ ! -d "$BASEDIR" ] ; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if have_command dpkg-query ; then
|
|
||||||
HAVE_X=$(dpkg-query -s xserver-xorg 2>/dev/null | \
|
|
||||||
grep -c 'Status.*installed' \
|
|
||||||
|| true)
|
|
||||||
else
|
|
||||||
HAVE_X=0
|
|
||||||
fi
|
|
||||||
|
|
||||||
IS_KALI=$(grep -ci kali /etc/os-release 2>/dev/null || true)
|
|
||||||
ARCH=$(uname -m)
|
|
||||||
|
|
||||||
OPERATION=${1:-install}
|
OPERATION=${1:-install}
|
||||||
|
|
||||||
case $OPERATION in
|
case $OPERATION in
|
||||||
|
|||||||
Reference in New Issue
Block a user