Added modiciation from a parallel project

This commit is contained in:
Gal Szkolnik 2022-10-23 18:10:30 -04:00
parent e14d5f3566
commit 278be5a6c6
24 changed files with 492 additions and 143 deletions

View file

@ -0,0 +1,20 @@
#! /usr/bin/env bash
GH_PROJECT="${1}"
GH_DL_TAG="${2:-latest}"
GH_FILTER="${3:-deb}"
if [[ ! "$GH_FILTER" =~ '(' ]]; then
GH_FILTER="contains(\"${GH_FILTER}\")"
fi
SRC_URL=https://api.github.com/repos/${GH_PROJECT}/releases/${GH_DL_TAG}
DL_URL=$( \
curl -sL curl ${SRC_URL} \
| jq -r " \
.assets[] \
| select(.browser_download_url \
| ${GH_FILTER} ) \
| .browser_download_url \
")
[[ -n "$DL_URL" ]] \
&& printf "%s\n" $DL_URL \
|| return 1 2>/dev/null || exit 1

View file

@ -0,0 +1,13 @@
#! /usr/bin/env bash
LIMIT=${1:-10}
REV_LIST="$(git rev-list --objects --all)"
find $(git rev-parse --git-dir)/objects/pack -type f -name "pack-*.idx" \
| while read pack; do
git verify-pack -v "$pack" | sort -nrk 3 | head -${LIMIT}
done | sort -nrk 3 | head -${LIMIT} \
| while read blobinfo; do
blob=$(echo "$blobinfo" | cut -f1 -d' ')
printf "%s %12s %s\n" $(echo "$blobinfo" | cut -f1,5 -d' ') "$(echo "$REV_LIST" | grep "$blob" | cut -f2 -d' ';)"
done
unset REV_LIST

View file

@ -0,0 +1,15 @@
#! /usr/bin/env bash
DL_URL="${1}"
DL_FILENAME="${2:-${DL_URL##*/}}"
DL_DIR=$(mktemp -dt)
cd "$DL_DIR"
# Download the .deb file
wget "$DL_URL"
# Install the package
sudo dpkg -i "${DL_FILENAME}"
# Clean up
rm "${DL_FILENAME}"
cd /
rmdir "$DL_DIR"

View file

@ -1,53 +0,0 @@
#! /usr/bin/env bash
set -e
### based on the code shared at https://community.teamviewer.com/English/discussion/comment/116988/#Comment_116988
clear
cat <<EOF
===================================================="
Latest TeamViewer QuickSupport Downloader & Launcher"
====================================================
Refreshing local versino fo TeamViewer QS
EOF
TVQS=${TVQS:-$1}
#RemoteFile=https://dl.teamviewer.com/download/linux/teamviewer_amd64.deb
#RemoteFile=https://download.teamviewer.com/download/linux/teamviewer_amd64.deb
#RemoteFile=https://download.teamviewer.com/download/version_11x/teamviewer_qs.tar.gz
# Prefer dl.teamviewer.com as it provides the `content-length` header
RemoteFile=https://dl.teamviewer.com/download/version_11x/teamviewer_qs.tar.gz
RemoteSize="$(curl -sI "$RemoteFile" | grep -i '^Content-Length:.*$' | awk '{sub("\r",""); print $2} ')"
LocalFile=~/Downloads/TeamViewerQS.tgz
if [ "${TVQS}" == "gal" ]; then
RemoteFileCustom='https://customdesignservice.teamviewer.com/download/linux/v15/6fnv7gb/TeamViewerQS.tar.gz'
RemoteSizeCustom="$(curl -sI "$RemoteFileCustom" | grep -i '^Content-Length:.*$' | awk '{sub("\r",""); print $2} ')"
if [[ "$RemoteSize" -gt "0" ]]; then
LocalFile=~/Downloads/TeamViewerQS-gal.tgz
RemoteFile=$RemoteFileCustom
RemoteSize=$RemoteSizeCustom
fi
fi
LocalSize="$(wc -c "$LocalFile" 2>/dev/null | awk '{ print $1 }')"
if [[ ! -r "${LocalFile}" ]] || [ "$LocalSize" != "$RemoteSize" ]; then
echo "Downloading file into $LocalFile..."
curl -Lo "$LocalFile" "$RemoteFile"
else
echo "$LocalFile exists and is same size as on server, using existing file..."
fi
rm -fR /tmp/tvqs 2>&1 > /dev/null
mkdir -p /tmp/tvqs
pushd /tmp/tvqs > /dev/null
tar xzf "$LocalFile"
cd teamviewerqs
echo "Launching TeamViewer Quick Support in the background from $PWD, it should startup in a few seconds..."
./teamviewer &
sleep 8
popd
printf "TeamViewer launched, you might want to hit <ENTER> if you don't see the prompt\n\n"

View file

@ -1,4 +1,5 @@
#! /usr/bin/env bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
USER_HOME=$HOME
[[ -n "${SUDO_USER}" ]] && USER_HOME="$(eval "echo ~${SUDO_USER}")"
. ${SHRC_D:-$USER_HOME/.pqb.shrc.d}/01_util.functions

View file

@ -0,0 +1,84 @@
#! /usr/bin/env bash
SHOW_ALIASES=0
SHOW_FUNCTIONS=0
SHOW_MEMBASED=0
SHOW_SCRIPTS=0
NAME="${0##*/}"
eval set -- $(getopt --name "$NAME" --options 'afmsh' --longoptions aliases,functions,membased,scripts,all,help -- "${@}")
ARG_COUNT=0
SHOW_USAGE=0
while [[ $# -gt 0 ]]
do
opt="$1";
#expose next argument
shift;
case "$opt" in
'--' ) break 2;;
'-h'|'-?' )
opt='--help' ;;
'-a' )
opt='--aliases' ;;
'-f' )
opt='--functions' ;;
'-m' )
opt='--membased' ;;
'-s' )
opt='--scripts' ;;
esac
((ARG_COUNT++))
case "$opt" in
'--help' ) SHOW_USAGE=1; break 2;;
'--aliases' )
SHOW_ALIASES=1 ;;
'--functions' )
SHOW_FUNCTIONS=1 ;;
'--membased' )
SHOW_MEMBASED=1 ;;
'--scripts' )
SHOW_SCRIPTS=1 ;;
*) echo >&2 "Invalid option: $@"; exit 1;;
esac
done
# If no args, show_usage
[[ $ARG_COUNT -eq 0 ]] && SHOW_SCRIPTS=0
if [[ "$SHOW_USAGE" == "1" ]]; then
printf "%s\n" \
"${0##*/}: ${0##*/} [-afhms] [--aliases] [--functions] [--help] [--membased] [--script]" \
" List POLARISqb productivity and helpdesk commands supplied by ITOps" \
"" \
" Options:" \
" -a | --aliases List aliases defined in Pqb startup scripts" \
" -f | --functions List functions defined in Pqb startup scripts" \
" -h | --help Display this usage message" \
" -m | --membased List all memory based commands (aka, aliases " \
" and functions)." \
" -s | --scripts List Pqb supplied utility scripts" \
" This is the default when no arguments are passed" \
""
return 2>/dev/null || exit
fi
FILTER=""
if [[ "$SHOW_ALIASES" == "1" || "$SHOW_MEMBASED" == "1" ]]; then
FILTER+="^\W*alias\|"
fi
if [[ "$SHOW_FUNCTIONS" == "1" || "$SHOW_MEMBASED" == "1" ]]; then
FILTER+="^\W*functions\|"
fi
if [[ -n "$FILTER" ]]; then
FILTER=${FILTER%\\|*}
find ~/.pqb.shrc.d -type f \
| xargs grep "${FILTER}" \
| sed 's/^.*\.d\///; s/:.*function /:(f) /; s/() {.*$//; s/:.*alias /:(a) /; s/=.*$//;'
fi
[[ "$SHOW_ALIASES" == "0" && "$SHOW_MEMBASED" == "0" && "$SHOW_MEMBASED" == "0" ]] && SHOW_SCRIPTS=1
if [[ "$SHOW_SCRIPTS" == "1" ]]; then
find ~/.local/bin -executable -type f -name "pqb*" -printf "%f\n"
fi

View file

@ -0,0 +1,70 @@
#! /usr/bin/env bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
USER_HOME=$HOME
[[ -n "${SUDO_USER}" ]] && USER_HOME="$(eval "echo ~${SUDO_USER}")"
source $(ls -1 ~/.*.shrc | head -1); [[ -z "${SHRC_D}" ]] && { echo "ERROR: Couldn't load ~/.*.shrc script!" 1>&2; return 1 2>/dev/null; exit 1; }
source ${SHRC_D}/${SHELL##*/}.pre/21_aliases
source ${SHRC_D}/01_util.functions
source ${SHRC_D}/97_chezmoi_aliases
set -e
require_sudo \
|| eval $(error 3 "POLARISqb: Not in sudo group, skipping $(basename $0)")
printf "%s\n" \
"POLARISqb Workstation/Laptop Owner initialization tool" \
"" \
"The machine will be initialized with the following values unless" \
"specified otherwise:" \
"" \
$(cz-import-data) \
""
eval "$(cz-import-data)"
if [[ -z "${CZ_PQB_DATA_LOCAL_USER_NAME}" ]]; then eval $(error 1 \
"local_user_name not defined in 'cehzmoi data', " "please run 'chezmoi init' or 'chezmoi edit-config' to fix, then try again"
); fi
if [[ -n "$(getent passwd ${CZ_PQB_DATA_LOCAL_USER_NAME})" ]]; then eval $(error 2 \
"User '${CZ_PQB_DATA_LOCAL_USER_NAME}' already exists, aborting."
); fi
#gecos field: "Full_Name,Room_Number,Work_Phone,Home_Phone,Other"
sudo adduser --disabled-password --gecos "${CZ_PQB_DATA_LOCAL_OWNER_NAME},,,,${CZ_PQB_DATA_EMAIL}" ${CZ_PQB_DATA_LOCAL_USER_NAME}
sudo adduser ${CZ_PQB_DATA_LOCAL_USER_NAME} sudo
INITIAL_PASSWORD='password'
printf "${CZ_PQB_DATA_LOCAL_USER_NAME}:${INITIAL_PASSWORD}" | sudo chpasswd
NEW_USER_HOME=$( eval "printf ~${CZ_PQB_DATA_LOCAL_USER_NAME}" )
if [[ -z "${NEW_USER_HOME}" ]]; then eval $(error 3 \
"Something is wrong, couldn't find the home dir for ${CZ_PQB_DATA_LOCAL_USER_NAME}!"
); fi
NEW_HOSTNAME="${CZ_PQB_DATA_LOCAL_USER_NAME}-pqb"
[[ "$(hostname)" != "${NEW_HOSTNAME}" ]] && sudo hostname $NEW_HOSTNAME
_CZ_REMOTE_URL=$(chezmoi git -- remote get-url origin)
_CZ_REMOTE_BRANCH=$(chezmoi git -- branch --show-current)
_CZ_DATA_PAIRS="$(cz-import-data promptString)"
cat ~/.config/chezmoi/chezmoi.toml | env sudo -u ${CZ_PQB_DATA_LOCAL_USER_NAME} -- sh -c "mkdir -p ~/.config/chezmoi; cat - > ~/.config/chezmoi/chezmoi.toml"
sudo -u ${CZ_PQB_DATA_LOCAL_USER_NAME} -- sh -c "cd ~; $(curl -fsLS chezmoi.io/get)" -- init --promptString="${_CZ_DATA_PAIRS}" --apply --branch "${_CZ_REMOTE_BRANCH}" "${_CZ_REMOTE_URL}"
echo "Chezmoi complete"
CUR_USER=$SUDO_USER
[[ -z "$CUR_USER" ]] && CUR_USER=$USER
# setup local git config values
git config --global --get user.email > /dev/null || git config --global user.email "${CUR_USER}@${NEW_HOSTNAME}"
git config --global --get user.name > /dev/null || git config --global user.name $(getent passwd $USER | cut -d':' -f5 | cut -d',' -f1)
sudo -u ${CZ_PQB_DATA_LOCAL_USER_NAME} -- sh -c "cd ~; git config --global user.email '${CZ_PQB_DATA_EMAIL}' && git config --global user.name '${CZ_PQB_DATA_LOCAL_OWNER_NAME}'"
sudo chage -d0 ${CZ_PQB_DATA_LOCAL_USER_NAME}
#${CZ_PQB_DATA_EMAIL}
#${CZ_PQB_DATA_LOCAL_OWNER_NAME}
#${CZ_PQB_DATA_LOCAL_USER_NAME}