Skip to content

Instantly share code, notes, and snippets.

@da-moon
Last active March 12, 2020 20:35
Show Gist options
  • Save da-moon/bf93290a79772092c6f7a80e1afdc07e to your computer and use it in GitHub Desktop.
Save da-moon/bf93290a79772092c6f7a80e1afdc07e to your computer and use it in GitHub Desktop.
#!/bin/sh
uname -snrvm
#!/bin/bash
export PATH="${PATH:+$PATH:}/bin:/usr/bin:/usr/local/bin"
[ -r /etc/lsb-release ] && . /etc/lsb-release
[ -r /etc/scw-release ] && . /etc/scw-release
if [ -z "$DISTRIB_DESCRIPTION" ] && [ -x /usr/bin/lsb_release ]; then
# Fall back to using the very slow lsb_release utility
DISTRIB_DESCRIPTION=$(lsb_release -s -d)
fi
date=`date`
load=`cat /proc/loadavg | awk '{print $1}'`
root_usage=`df -h / | awk '/\// {print $(NF-1)}'`
memory_usage=`free -m | awk '/Mem:/ { total=$2 } /buffers\/cache/ { used=$3 } END { printf("%3.1f%%", used/total*100)}'`
swap_usage=`free -m | awk '/Swap/ { printf("%3.1f%%", "exit !$2;$3/$2*100") }'`
users=`users | wc -w`
time=`uptime | grep -ohe 'up .*' | sed 's/,/\ hours/g' | awk '{ printf $2" "$3 }'`
processes=`ps aux | wc -l`
ip=$(scw-metadata --cached PRIVATE_IP)
public_ip=$(scw-metadata --cached PUBLIC_IP_ADDRESS)
metadata() {
scw-metadata --cached "$1"
}
volume_metadata() {
device=$1
key=$2
scw-metadata --cached "VOLUMES_${device}_${key}"
}
KERNEL_VERSION=$(uname -r)
if [[ $KERNEL_VERSION =~ ^3\.2\.[35][24].* ]]; then
KERNEL_TITLE="- Marvell"
fi
[ -f /etc/motd.head ] && cat /etc/motd.head || true
printf "\n"
printf "Welcome on %s (%s %s %s %s)\n" "${IMAGE_DESCRIPTION}" "$(uname -o)" "${KERNEL_VERSION}" "$(uname -m)" "$KERNEL_TITLE"
printf "\n"
printf "System information as of: %s\n" "$date"
printf "\n"
printf "System load:\t%s\t\tInt IP Address:\t%s %s\n" $load $ip
printf "Memory usage:\t%s\t\tPub IP Address:\t%s\n" $memory_usage $public_ip
printf "Usage on /:\t%s\t\tSwap usage:\t%s\n" $root_usage $swap_usage
printf "Local Users:\t%s\t\tProcesses:\t%s\n" $users $processes
printf "Image build:\t%s\tSystem uptime:\t%s\n" "${IMAGE_RELEASE}" "$time"
for i in {0..16}; do
metadata VOLUMES_${i} | grep " " >/dev/null || continue
SIZE=$(( $(volume_metadata $i SIZE) / 1000 / 1000 / 1000 ))G
volume_export_uri="$(volume_metadata $i EXPORT_URI)"
if [ "$(echo "$volume_export_uri" | cut -d: -f1)" = "nbd" ]; then
device_name="nbd$i"
else
device_name="$(echo "$volume_export_uri" | sed s@device://dev/@@)"
fi
printf "Disk %s:\t%s\n" "$device_name" "$(volume_metadata $i VOLUME_TYPE) ${SIZE}"
done
printf "\n"
printf "Documentation:\t%s\n" "$IMAGE_DOC_URL"
printf "Community:\t%s\n" "$IMAGE_HELP_URL"
printf "Image source:\t%s\n" "$IMAGE_SOURCE_URL"
printf "\n"
[ -f /etc/motd.tail ] && cat /etc/motd.tail || true
for item in $(ls | grep ".java") ; do echo "// Author Damoon Azarpazhooh 500664523" | cat - $item > temp && mv temp $item ; done;
#!/bin/sh
# https://askubuntu.com/questions/786998/how-to-use-existing-ssh-key-on-my-newly-installed-ubuntu/787005
cp /path/to/my/key/id_rsa ~/.ssh/id_rsa
cp /path/to/my/key/id_rsa.pub ~/.ssh/id_rsa.pub
# change permissions on file
sudo chmod 600 ~/.ssh/id_rsa
sudo chmod 600 ~/.ssh/id_rsa.pub
# start the ssh-agent in the background
eval $(ssh-agent -s)
# make ssh agent to actually use copied key
ssh-add ~/.ssh/id_rsa
#!/bin/sh
git commit -m "prepare for v1.0.0 release"
git tag v0.0.2
git push origin master --tags
https://askubuntu.com/questions/854332/how-to-connect-android-7-1-to-ubuntu-linux-with-usb
https://unix.stackexchange.com/questions/31947/how-to-add-a-newline-to-the-end-of-a-file
#!/bin/sh
ls | grep -e .vhd | xargs -I '{}' cp '{}' ~/target/
https://superuser.com/questions/386199/how-to-remove-duplicated-files-in-a-directory
sudo find /tmp -type d -name 'go-build*' -prune -exec rm -rf {} +
#!/usr/bin/env bash
# https://stackoverflow.com/questions/2709458/how-to-replace-spaces-in-file-names-using-a-bash-script
find . -depth -name "* *" -execdir rename 's/ /_/g' "{}" \;
https://natelandau.com/boilerplate-shell-script-template/
https://gitlab.com/jaymoulin/docker-google-music-downloader
https://medium.com/@seclectech/linux-containers-vms-on-your-chromebooks-from-vmc-to-alpine-88bccdc78fdf
https://github.com/DennisLfromGA/CBC-Projects/wiki/Crostini:-setup-lxd-client-in-penguin-container
https://discuss.linuxcontainers.org/t/using-lxd-on-your-chromebook/3823
source: https://discuss.linuxcontainers.org/t/using-lxd-on-your-chromebook/3823
ctrl-alt-t to access crosh
vsh termina (or vmc start termina)
lxc config set core.https_address :8443
lxc config set core.trust_password some-password
# create an Ubuntu container
lxc launch ubuntu:18.04 c1
# copy the lxc command from it
lxc file pull c1/usr/bin/lxc /tmp/lxc
# copy it to penguin
lxc file push /tmp/lxc penguin/usr/local/bin/
rm /tmp/lxc
lxc delete c1
# note the host ip (HOSTIP here after) in the ipv4.address line
lxc network show lxdbr0
open termina
lxc remote add chromeos HOSTIP
(use the password some-password used for lxc config...)
lxc remote set default chromeos
all done.
test if it works:
lxc list
# https://unix.stackexchange.com/questions/1555/how-can-i-move-files-by-type-recursively-from-a-directory-and-its-sub-directorie
find ./ -type f -name '*.mp3' -exec mv -i {} ./target \;
#!/usr/bin/env bash
#https://stackoverflow.com/questions/5927369/recursively-look-for-files-with-a-specific-extension
#https://stackoverflow.com/questions/2087001/how-can-i-process-the-results-of-find-in-a-bash-script
for i in $(find . -type f -name "*.mp4");do parentname="$(dirname "$i")" name=$(basename "$i" .mp4); echo "$parentname $name"; done
for i in $(find . -type f -name "*.url");do rm "$i"; done
for i in $(find . -type f -name "License.pdf");do rm "$i"; done
for i in *;do trimmed="$(echo "$i" | sed -r 's/^.*]_
//')"; mv "$i" "$trimmed"; done
#!/bin/sh
find . -name "node_modules" -type d -prune -exec rm -rf '{}' +
# clone all repos of an organization
ORG=hashicorp;LANG=ruby;curl curl https://api.github.com/search/repositories?q=""+language:$LANG+org:$ORG | grep -o 'git@[^"]*' | xargs -L1 git clone
#Canonical repo name
ORG=gorilla;LANG=go;curl -s https://api.github.com/search/repositories?q=""+language:$LANG+org:$ORG | grep -Po "github.com\/$ORG\/\w.*(?=\.git)" | sort -u | xargs -L1
#go get all repositories
ORG=gorilla;LANG=go;curl -s https://api.github.com/search/repositories?q=""+language:$LANG+org:$ORG | grep -Po "github.com\/$ORG\/\w.*(?=\.git)" | sort -u | xargs printf -- '-v -u -d %s/...\n' |xargs -L1 go get
for pid in $(ps | grep "screen" | awk '{print $1}'); do kill -9 $pid; done
https://askubuntu.com/questions/100052/modify-the-ssh-welcome-message-to-include-system-ip-address
/etc/update-motd.d
#!/bin/sh
# description "executable which retrieves server metadata (TEXT)"
# author "Scaleway <[email protected]>"
export PATH="${PATH:+$PATH:}/usr/bin:/bin"
CACHE_FILE=/run/scw-metadata.cache
METADATA_IP=${METADATA_IP:-169.254.42.42}
METADATA_URL=${METADATA_URL:-"http://${METADATA_IP}/conf"}
if [ "$1" = "--cached" -a -f $CACHE_FILE ]; then
shift
BODY=$(cat $CACHE_FILE)
else
[ "$1" = "--cached" ] && shift
if hash curl 2>/dev/null; then
# Using curl
CODE=0
while [ $CODE -ne 200 ]; do
RESPONSE=$(curl --noproxy '*' --silent --write-out "\n%{http_CODE}\n" $METADATA_URL)
CODE=$(echo "$RESPONSE" | sed -n '$p')
BODY=$(echo "$RESPONSE" | sed '$d')
if [ $CODE -eq 200 ]; then
echo "$BODY" > /run/scw-metadata.cache
ln -s scw-metadata.cache /run/oc-metadata.cache 2>/dev/null
break
fi
sleep 5
done
else
# Using wget
for i in 1 2 3 4 5; do
BODY=$(wget --no-proxy --quiet -O- $METADATA_URL)
echo "$BODY" | grep PRIVATE_IP >/dev/null
if [ $? -eq 0 ]; then
echo "$BODY" > /run/scw-metadata.cache
ln -s scw-metadata.cache /run/oc-metadata.cache 2>/dev/null
break
fi
sleep 2
done
fi
fi
if [ "$#" -ne 1 ]; then
echo "$BODY"
else
key="$1"
echo "$BODY" | grep "^$key=" | sed "s/^[^=]*=//;s/^['\"]//;s/['\"]$//"
fi
docker run -it --rm browsh/browsh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment