33# General systems functions
44#
55# -------------------------------------------------------------------------------
6+ alias pc=" pre-commit"
7+ alias pci=" pre-commit install"
8+ alias pca=" sk-pre-commit-all"
9+
10+ sk-group-user-uid-highest (){
11+ group_name=" ${1:- wibble} "
12+
13+ # List all users in the group
14+ group_users=$( getent group " $group_name " | awk -F: ' {print $4}' | tr ' ,' ' \n' )
15+
16+ # Initialize the highest UID variable
17+ highest_uid=-1
18+
19+ # Loop through each user and find their UID
20+ for user in $group_users ; do
21+ user_uid=$( id -u " $user " )
22+ if [ " $user_uid " -gt " $highest_uid " ]; then
23+ highest_uid=$user_uid
24+ fi
25+ done
26+
27+ # Output the highest UID
28+ echo " The highest UID in the group '$group_name ' is: $highest_uid "
29+ }
30+
31+ sk-pushover (){
32+ sk-config-read -c .pushover.conf
33+ curl -s \
34+ --form-string " token=${APP_TOKEN} " \
35+ --form-string " user=${USER_KEY} " \
36+ --form-string " message=$@ " \
37+ https://api.pushover.net/1/messages.json
38+ }
39+
40+ sk-hostname-noid (){
41+ hostname | awk -F ' -' ' {print $1"-"$2"-"$3"-"$4}'
42+ }
43+
44+ sk-motd (){
45+ sudo bash -c ' run-parts /etc/update-motd.d/ > /var/run/motd.dynamic'
46+ cat /var/run/motd.dynamic
47+ }
48+
49+ sk-cron-is (){
50+ if [ -t 1 ] ; then
51+ false
52+ else
53+ true
54+ fi
55+ }
56+
57+ sk-interactive (){
58+ if [ -t 1 ] ; then
59+ true
60+ else
61+ false
62+ fi
63+ }
64+
65+ sk-jinjafier () {
66+ sk_help_noarg " $FUNCNAME : <properties_file>. Convert a properties files into a jina2 template" " $@ " && return
67+ local propfile=${1:- example.properties}
68+
69+ sk-asdf-install jinjafier -p jinjafier -v latest --plugin_git_url https://github.com/ORCID/asdf-jinjafier.git --silent
70+ jinjafier $propfile
71+ }
72+
73+ sk-dos2unix (){
74+ sk-pack-install dos2unix -p dos2unix
75+ dos2unix $@
76+ }
77+
78+ sk-restic-restore-all-latest (){
79+ for restore_script in ` sudo ls -1 /root/restic/ | grep restore | grep -v auto` ; do
80+ echo " /root/restic/$restore_script "
81+ sudo /root/restic/$restore_script
82+ done
83+ }
84+
85+ sk-restic-path-list (){
86+ sk_help " Usage: Extract path name from each restore file" " $@ " && return
87+ sudo ls -1 /root/restic/ | grep restore | grep -v auto | perl -pe ' s/restore-//g'
88+ }
89+
90+ sk-restic-path-list-first (){
91+ sk_help " Usage: Extract path name from each restore file and list the first one only" " $@ " && return
92+ sudo ls -1 /root/restic/ | grep restore | grep -v auto | perl -pe ' s/restore-//g' | head -1
93+ }
94+
95+ sk-restic-restore-snapshot-id (){
96+ sk_help_noarg " Usage: <snapshot_id> <path>(first) Restore a specific snapshot id" " $@ " && return
97+ local restic_backup_path=${2:- $(sk-restic-path-list-first)}
98+ local access_file=$( sudo ls -1 /root/restic/ | grep access | grep $restic_backup_path )
99+ echo /root/restic/$access_file
100+ source <( sudo cat /root/restic/$access_file )
101+ restic restore " $1 "
102+ }
103+
104+ sk-restic-snapshot-list (){
105+ sk_help " Usage: <snapshot_id> <path>(first) Restore a specific snapshot id" " $@ " && return
106+ local restic_backup_path=${2:- $(sk-restic-path-list-first)}
107+ local access_file=$( sudo ls -1 /root/restic/ | grep access | grep $restic_backup_path )
108+ source <( sudo cat /root/restic/$access_file )
109+ echo /root/restic/$access_file
110+ restic snapshots
111+ }
112+
113+ sk-restic-unlock (){
114+ access_file=$( sudo ls -1 /root/restic/ | grep access | tail -1)
115+ source <( sudo cat /root/restic/$access_file )
116+ echo " restic unlock"
117+ restic unlock
118+ }
119+
120+ sk-pre-commit-dir (){
121+ sk_help_noarg " $FUNCNAME : <dir>. Run pre-commit on all files in a dir" " $@ " && return
122+ git ls-files -- $1 | xargs pre-commit run --files
123+ }
124+
125+ sk-pre-commit-all (){
126+ pre-commit run --all-files
127+ }
6128
7129sk-ntp-fix (){
8130 sudo service chrony stop
@@ -27,6 +149,25 @@ sk-sys-cores(){
27149 fi
28150}
29151
152+ sk-awk (){
153+ if [[ " $PLATFORM " == ' Darwin' ]]; then
154+ sk-pack-install gawk -p gawk
155+ gawk $@
156+ else
157+ awk $@
158+ fi
159+ }
160+
161+
162+ sk-grep (){
163+ if [[ " $PLATFORM " == ' Darwin' ]]; then
164+ sk-pack-install ggrep -p grep
165+ ggrep $@
166+ else
167+ grep $@
168+ fi
169+ }
170+
30171sk-datediff-setup (){
31172 if [[ " $PLATFORM " == ' Darwin' ]]; then
32173 sk-pack-install datediff -p dateutils
@@ -35,6 +176,37 @@ sk-datediff-setup(){
35176 fi
36177}
37178
179+ # needs to run as sudo
180+ sk-tcptraceroute-port (){
181+ if [[ " $PLATFORM " == ' Darwin' ]]; then
182+ sk-pack-install tcptraceroute
183+ sudo tcptraceroute $@
184+ else
185+ sk-pack-install traceroute
186+ sudo traceroute -T $@
187+ fi
188+ }
189+
190+ sk-tcptraceroute (){
191+ if [[ " $PLATFORM " == ' Darwin' ]]; then
192+ sk-pack-install tcptraceroute
193+ tcptraceroute $@
194+ else
195+ sk-pack-install traceroute
196+ traceroute -T $@
197+ fi
198+ }
199+
200+ sk-traceroute (){
201+ if [[ " $PLATFORM " == ' Darwin' ]]; then
202+ sk-pack-install gtraceroute -p inetutils
203+ gtraceroute $@
204+ else
205+ sk-pack-install traceroute
206+ traceroute $@
207+ fi
208+ }
209+
38210sk-sed (){
39211 if [[ " $PLATFORM " == ' Darwin' ]]; then
40212 sk-pack-install gsed -p gnu-sed
@@ -44,6 +216,33 @@ sk-sed(){
44216 fi
45217}
46218
219+ sk-readlink-f (){
220+ if [[ " $PLATFORM " == ' Darwin' ]]; then
221+ sk-pack-install greadlink -p coreutils
222+ greadlink -f $@
223+ else
224+ readlink -f $@
225+ fi
226+ }
227+
228+ sk-readlink-e (){
229+ if [[ " $PLATFORM " == ' Darwin' ]]; then
230+ sk-pack-install greadlink -p coreutils
231+ greadlink -e $@
232+ else
233+ readlink -e $@
234+ fi
235+ }
236+
237+ sk-realpath (){
238+ if [[ " $PLATFORM " == ' Darwin' ]]; then
239+ sk-pack-install grealpath -p coreutils
240+ grealpath $@
241+ else
242+ realpath $@
243+ fi
244+ }
245+
47246# bring macos into compat with linux
48247sk-date (){
49248 if [[ " $PLATFORM " == ' Darwin' ]]; then
0 commit comments