Skip to content

Commit 25331e8

Browse files
author
Giles Westwood
committed
bring in nexus all repo upload fix
1 parent a8da74a commit 25331e8

10 files changed

Lines changed: 199 additions & 21 deletions

File tree

lib/asdf.sh

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,15 @@ sk-asdf-install(){
227227
-u | --plugin) if plugin and package are different
228228
-ug | --plugin_git_url) https url to github asdf plugin
229229
-s | --silent ) enable silent mode so nothing is output during the install
230+
-av | --any-version ) skip version checks when any version will do
230231
231232
Example:
232233
233234
234235
Options:
235236
" "$@" && return 1
236237

237-
local ppa=0 package_type='' repo='' repoform='' package=$binary version=latest dir='unset' file='unset' post_install='' plugin_git_url='' plugin='' silent=0
238+
local ppa=0 package_type='' repo='' repoform='' package=$binary version=latest dir='unset' file='unset' post_install='' plugin_git_url='' plugin='' silent=0 skip_version_check=0 needs_install=1
238239

239240
while :
240241
do
@@ -247,15 +248,20 @@ sk-asdf-install(){
247248
-d | --dir ) dir=$2; shift 2 ;;
248249
-f | --file ) file=$2; shift 2 ;;
249250
-s | --silent ) silent=1; shift ;;
251+
--any-version ) skip_version_check=1; shift ;;
250252
--verbose ) VERBOSE=$((VERBOSE+1)); shift ;;
251253
--) shift ; break ;;
252254
-*) echo "$FUNCNAME WARN: Unknown option (ignored): $1" >&2 ; shift ;;
253255
*) break ;;
254256
esac
255257
done
256258

259+
if [[ "$skip_version_check" -eq 1 ]] && command -v "$binary" >/dev/null 2>&1; then
260+
return 0
261+
fi
262+
257263
# Nasty hack to install plugins as well
258-
if ! grep -q $package <<< $(asdf plugin list 2>/dev/null);then
264+
if ! grep -q "$package" <<< $(asdf plugin list 2>/dev/null);then
259265
if [[ "$silent" -eq 1 ]]; then
260266
if sk-sys-is-root-no-output;then
261267
# FIXME: find out why we need sudo
@@ -280,11 +286,25 @@ sk-asdf-install(){
280286
fi
281287

282288
if [[ "$version" = 'latest' ]];then
283-
version=$(asdf latest $package)
289+
if ! version=$(asdf latest $package 2>/dev/null); then
290+
version=$(asdf list $package 2>/dev/null | tr -d '* ' | tail -n1) || true
291+
292+
if [[ -z "$version" ]]; then
293+
echo "WARN: sk-asdf-install could not determine a version for $package" >&2
294+
return 1
295+
fi
296+
fi
284297
fi
285298

286-
# install a package if it does not exist ( and handle the error) , or if it is the wrong version
287-
if ! grep -q $version <<< $(asdf current $package 2>/dev/null || true);then
299+
if [[ "$skip_version_check" -eq 0 ]]; then
300+
if grep -q $version <<< $(asdf current $package 2>/dev/null || true);then
301+
needs_install=0
302+
fi
303+
fi
304+
305+
if [[ "$needs_install" -eq 0 ]]; then
306+
return 0
307+
fi
288308

289309
if [[ "$silent" -eq 1 ]]; then
290310
asdf install $package $version >/dev/null 2>&1
@@ -297,8 +317,6 @@ sk-asdf-install(){
297317
asdf global $package $version
298318
fi
299319

300-
fi
301-
302320
}
303321

304322
sk-asdf-remove(){

lib/aws.sh

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ _sk_aws_host(){
1414
fi
1515
}
1616

17+
sk-aws-sso(){
18+
if [ -z "$1" ]; then
19+
echo "Please provide a profile name. Usage: sso profile_name"
20+
else
21+
aws sso login --profile "$1" && export AWS_PROFILE="$1"
22+
fi
23+
}
24+
1725
sk-aws-rds-failover(){
1826
sk_help "$FUNCNAME: <db instance> <region> <profile>" "$@" && return
1927
region=${2:-'eu-west-1'}
@@ -119,3 +127,108 @@ sk-aws-list-instances(){
119127
sk-pack-install -b aws -p awscli
120128
aws ec2 describe-instances | jq -r '.Reservations[].Instances[] | (.Tags[] | select(.Key=="Name").Value) + "\t" + .InstanceId' | sort
121129
}
130+
131+
sk-leapp(){
132+
current_dir=$(pwd)
133+
case $current_dir in
134+
*prod*) profile="orcid-prod" ;;
135+
*int*) profile="orcid-int" ;;
136+
*stage*) profile="orcid-stage" ;;
137+
*shared*) profile="orcid-shared" ;;
138+
*sbox*) profile="orcid-sbox" ;;
139+
*qa*) profile="orcid-qa" ;;
140+
*) echo "undetected env in current dir"; return ;;
141+
esac
142+
echo profile "$profile"
143+
sk-aws-sso-leapp $profile
144+
}
145+
146+
sk-aws-sso-leapp(){
147+
local profile="${1:-orcid-int}"
148+
149+
# Check if SSO session is still valid by trying to export credentials
150+
local creds=$(aws configure export-credentials --profile "$profile" --format process 2>/dev/null)
151+
152+
# If credentials export failed, we need to login
153+
if [ $? -ne 0 ] || [ -z "$creds" ]; then
154+
echo "SSO session expired or invalid, logging in..."
155+
aws sso login --sso-session orcid 2>&1 | grep -v "Attempting to automatically open\|If the browser does not open\|https://\|Then enter the code\|Successfully logged into"
156+
157+
# Try exporting credentials again after login
158+
creds=$(aws configure export-credentials --profile "$profile" --format process 2>/dev/null)
159+
160+
if [ $? -ne 0 ] || [ -z "$creds" ]; then
161+
echo "✗ Failed to export credentials after login"
162+
return 1
163+
fi
164+
fi
165+
166+
# Parse the credentials (process format is JSON)
167+
local access_key=$(echo "$creds" | jq -r '.AccessKeyId')
168+
local secret_key=$(echo "$creds" | jq -r '.SecretAccessKey')
169+
local session_token=$(echo "$creds" | jq -r '.SessionToken')
170+
local expiration=$(echo "$creds" | jq -r '.Expiration')
171+
172+
# Write to ~/.aws/credentials as [default] profile (Leapp-style)
173+
local creds_file=~/.aws/credentials
174+
175+
# Create ~/.aws directory if it doesn't exist
176+
mkdir -p ~/.aws
177+
178+
# Backup existing credentials
179+
if [ -f "$creds_file" ]; then
180+
cp "$creds_file" "${creds_file}.bak"
181+
fi
182+
183+
# Remove existing [default] section if it exists
184+
if grep -q "\[default\]" "$creds_file" 2>/dev/null; then
185+
# Remove the [default] section and everything until the next section or EOF
186+
awk 'BEGIN {skip=0} /^\[default\]/ {skip=1; next} /^\[.*\]/ {skip=0} !skip' "$creds_file" > "${creds_file}.tmp"
187+
mv "${creds_file}.tmp" "$creds_file"
188+
fi
189+
190+
# Prepend new default credentials at the top of the file
191+
{
192+
echo "[default]"
193+
echo "aws_access_key_id = ${access_key}"
194+
echo "aws_secret_access_key = ${secret_key}"
195+
echo "aws_session_token = ${session_token}"
196+
echo "# Profile: ${profile}"
197+
echo "# Expires: ${expiration}"
198+
echo ""
199+
cat "$creds_file" 2>/dev/null
200+
} > "${creds_file}.new"
201+
202+
mv "${creds_file}.new" "$creds_file"
203+
chmod 600 "$creds_file"
204+
205+
# Clear any profile override
206+
unset AWS_PROFILE
207+
208+
echo "✓ Switched to AWS profile: $profile"
209+
echo "✓ Credentials written to ~/.aws/credentials as [default]"
210+
echo "✓ Credentials expire: $expiration"
211+
}
212+
213+
# Simpler environment-only version
214+
sk-aws-sso-env(){
215+
local profile="${1:-orcid-int}"
216+
217+
aws sso login --profile "$profile" 2>&1 | grep -v "Attempting to automatically open\|If the browser does not open\|https://\|Then enter the code\|Successfully logged into" || return 1
218+
219+
eval $(aws configure export-credentials --profile "$profile" --format env 2>/dev/null)
220+
221+
# Clear AWS_PROFILE so it uses the exported credentials
222+
unset AWS_PROFILE
223+
224+
if [ -n "$AWS_ACCESS_KEY_ID" ]; then
225+
local expiration=$(aws configure export-credentials --profile "$profile" --format process 2>/dev/null | jq -r '.Expiration')
226+
echo "✓ Logged into AWS SSO"
227+
echo "✓ Credentials exported to environment"
228+
echo "✓ Source profile: $profile"
229+
echo "✓ Valid until: $expiration"
230+
else
231+
echo "✗ Failed to export credentials"
232+
return 1
233+
fi
234+
}

lib/config.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ sk-config-read(){
1010
1111
ENV variables
1212
Config file(s) first one found. based on:-
13-
1: ./
13+
1: ./ including .<config_filename>
1414
2: home dir including .<config_filename>
1515
3: /etc/
1616
4: /etc/config_file_no_extension_or_dot/
@@ -38,7 +38,7 @@ sk-config-read(){
3838

3939
undotted_file="${config_file#.}"
4040
config_base="${undotted_file%.*}"
41-
config_list="./$config_file ~/.$config_file ~/$config_file /etc/$config_file /etc/$config_base/$config_file"
41+
config_list="./$config_file ./.$config_file ~/.$config_file ~/$config_file /etc/$config_file /etc/$config_base/$config_file"
4242

4343
if config_found=$(_sk-config-selector $config_list);then
4444

lib/file.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@ sk-file-no-comments-no-blank(){
2222
grep -v "^#\|^$" $filename
2323
}
2424

25+
sk-file-larger-than-mb() {
26+
sk_help "Usage: $FUNCNAME <size_in_MB> <dir1> [dir2 ...]. Find files larger than x MB in specified directories." "$@" && return 1
27+
local size_mb=${1:-10}
28+
shift
29+
local dirs=("$@")
30+
if [[ ${#dirs[@]} -eq 0 ]]; then
31+
dirs=(".")
32+
fi
33+
find "${dirs[@]}" -type f -size +"${size_mb}M" -exec ls -lh {} \; | awk '{print $9, $5}'
34+
}
35+
2536
sk-file-older-than(){
2637
local file=${1:-/var/tmp/} days=${2:-1}
2738
sk_help "Usage: $FUNCNAME <file> <days>" "$@" && return 1

lib/git.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -778,8 +778,7 @@ sk-git-pull(){
778778

779779
_sk-git-keygen -r $repo -g $git_dir
780780

781-
git -C $git_dir pull --no-edit || true
782-
781+
git -C $git_dir pull --no-edit --no-rebase
783782
}
784783

785784
sk-git-clone-checkout-patch(){

lib/github.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ alias al=sk-github-actionlint
77
alias ghal=sk-github-actionlint
88

99
github_poke_slack_channel='tech-ops'
10-
github_version=2.54.0
10+
github_version=2.76.2
1111

1212

1313
sk-github-actionlint(){
@@ -352,7 +352,7 @@ alias ghw=sk-github-run-workflow-with-logs
352352

353353

354354
_sk-github-tf-parse-apply(){
355-
cat "$tf_apply_file" | grep 'Apply Plan' | cut -d' ' -f7-
355+
grep -E 'Apply complete!|Error:|no changes|Resources:' "$tf_apply_file" | sed 's/.*Z //' | sed 's/\[0m//g; s/\[1m//g; s/\[32m//g' | sort -u
356356
}
357357

358358
_sk-github-tf-parse-plan(){
@@ -587,6 +587,13 @@ sk-github-create-repo(){
587587

588588
}
589589

590+
sk-github-open(){
591+
sk_help "$FUNCNAME. Open the current repo in Chrome. Opens the PR if the current branch has one, otherwise the repo page." "$@" && return
592+
if ! gh pr view --web 2>/dev/null; then
593+
gh browse
594+
fi
595+
}
596+
590597
sk-github-dependabot-alerts(){
591598
sk_help "
592599
Usage: $FUNCNAME

lib/nexus.sh

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,10 @@ sk-nexus-uploadfile(){
318318

319319
if [[ "$repository" == 'private-release' ]];then
320320
apt_distro=$(sk-deb-distribution $upload_file)
321-
if [[ "$Architecture" == 'all' ]];then
322-
repository="private_apt_all"
323-
else
324-
repository="private_apt_${apt_distro}"
325-
fi
326-
321+
# arch:all is CPU-independent but still belongs to a release, so route it
322+
# to the per-distro repo like everything else (its per-arch indices
323+
# include arch:all packages). The old shared private_apt_all is retired.
324+
repository="private_apt_${apt_distro}"
327325
fi
328326

329327
echo_log curl --fail -u $NEXUS_USER:xxxx -X POST -H "Content-Type: multipart/form-data" --data-binary "@$upload_file" "$NEXUS_URL/repository/$repository/"

lib/pack.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,15 @@ sk-pack-install() {
106106
gem)
107107
$sudo_cmd gem install $package $version_cmd
108108
;;
109+
deb)
110+
wget $repo
111+
$sudo_cmd dpkg -i $(basename $repo)
112+
;;
109113
npm)
110114
# FIXME: allow ver to be configurable
111115
sk-asdf-install npm -p nodejs -v 18.7.0
112116
npm install --prefix ~ $package@$version
113117
;;
114-
115118
run)
116119
curl -s $repo | sudo bash
117120
;;

lib/ssl.sh

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,32 @@ sk-ssl-sig() {
1515
echo_log_run_logoutput openssl x509 -in ${1}* -fingerprint -noout
1616
}
1717

18+
sk-ssl-ca-list-java(){
19+
sk_help "Usage: $FUNCNAME <optional service for java_home> <optional_cacert_file> List all the subject names of the system wide ca store" "$@" && return
20+
local service=${1:-wibble}
21+
local cacerts_file=${2:-unset}
22+
23+
sk-java-home -s "$service"
24+
if [[ "$cacerts_file" != 'unset' ]];then
25+
CACERTS_FILE=$cacerts_file
26+
else
27+
CACERTS_FILE="$JAVA_HOME/lib/security/cacerts"
28+
fi
29+
echo "keytool -list -v -keystore "$CACERTS_FILE" -storepass changeit"
30+
keytool -list -v -keystore "$CACERTS_FILE" -storepass changeit
31+
}
32+
1833
sk-ssl-ca-list(){
1934
sk_help "Usage: $FUNCNAME </etc/ssl/certs/ca-certificates.crt> List all the subject names of the system wide ca store" "$@" && return
35+
if [[ "$PLATFORM" = Darwin ]];then
36+
default_cacerts_file=/etc/ssl/cert.pem
37+
else
38+
default_cacerts_file=/etc/ssl/certs/ca-certificates.crt
39+
fi
40+
41+
local cacerts_file="${1:-$default_cacerts_file}"
2042
awk -v cmd='openssl x509 -noout -subject' '
21-
/BEGIN/{close(cmd)};{print | cmd}' < /etc/ssl/certs/ca-certificates.crt
43+
/BEGIN/{close(cmd)};{print | cmd}' < $cacerts_file
2244
}
2345

2446
sk-ssl-text() {

lib/sys.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ alias pc="pre-commit"
77
alias pci="pre-commit install"
88
alias pca="sk-pre-commit-all"
99

10+
# FIXME: migrate to asdf
11+
sk-goreplay(){
12+
sk_help_noarg "$FUNCNAME: run and install goreplay tool. Example args --input-file solr_09_30_outage.log --output-http http://localhost:8983 " "$@" && return
13+
sk-pack-install -b ror -r https://github.com/buger/goreplay/releases/download/1.3.3/gor_1.3.3_amd64.deb -o deb
14+
gor $@
15+
}
16+
1017
sk-host-to-fqdn(){
1118
local host="${1:-localhost}"
1219
host "$host" | awk '/has address/ {print $1}'

0 commit comments

Comments
 (0)