initial
This commit is contained in:
365
bin/bash2048.sh
Executable file
365
bin/bash2048.sh
Executable file
@ -0,0 +1,365 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#important variables
|
||||
declare -ia board # array that keeps track of game status
|
||||
declare -i pieces # number of pieces present on board
|
||||
declare -i score=0 # score variable
|
||||
declare -i flag_skip # flag that prevents doing more than one operation on
|
||||
# single field in one step
|
||||
declare -i moves # stores number of possible moves to determine if player lost
|
||||
# the game
|
||||
declare ESC=$'\e' # escape byte
|
||||
declare header="Bash 2048 v1.1 (https://github.com/mydzor/bash2048)"
|
||||
|
||||
declare -i start_time=$(date +%s)
|
||||
|
||||
#default config
|
||||
declare -i board_size=4
|
||||
declare -i target=2048
|
||||
declare -i reload_flag=0
|
||||
declare config_dir="$HOME/.bash2048"
|
||||
|
||||
#for colorizing numbers
|
||||
declare -a colors
|
||||
colors[2]=33 # yellow text
|
||||
colors[4]=32 # green text
|
||||
colors[8]=34 # blue text
|
||||
colors[16]=36 # cyan text
|
||||
colors[32]=35 # purple text
|
||||
colors[64]="33m\033[7" # yellow background
|
||||
colors[128]="32m\033[7" # green background
|
||||
colors[256]="34m\033[7" # blue background
|
||||
colors[512]="36m\033[7" # cyan background
|
||||
colors[1024]="35m\033[7" # purple background
|
||||
colors[2048]="31m\033[7" # red background (won with default target)
|
||||
|
||||
exec 3>/dev/null # no logging by default
|
||||
|
||||
trap "end_game 0 1" INT #handle INT signal
|
||||
|
||||
#simplified replacement of seq command
|
||||
function _seq {
|
||||
local cur=1
|
||||
local max
|
||||
local inc=1
|
||||
case $# in
|
||||
1) let max=$1;;
|
||||
2) let cur=$1
|
||||
let max=$2;;
|
||||
3) let cur=$1
|
||||
let inc=$2
|
||||
let max=$3;;
|
||||
esac
|
||||
while test $max -ge $cur; do
|
||||
printf "$cur "
|
||||
let cur+=inc
|
||||
done
|
||||
}
|
||||
|
||||
# print currect status of the game, last added pieces are marked red
|
||||
function print_board {
|
||||
clear
|
||||
printf "$header pieces=$pieces target=$target score=$score\n"
|
||||
printf "Board status:\n" >&3
|
||||
printf "\n"
|
||||
printf '/------'
|
||||
for l in $(_seq 1 $index_max); do
|
||||
printf '+------'
|
||||
done
|
||||
printf '\\\n'
|
||||
for l in $(_seq 0 $index_max); do
|
||||
printf '|'
|
||||
for m in $(_seq 0 $index_max); do
|
||||
if let ${board[l*$board_size+m]}; then
|
||||
if let '(last_added==(l*board_size+m))|(first_round==(l*board_size+m))'; then
|
||||
printf '\033[1m\033[31m %4d \033[0m|' ${board[l*$board_size+m]}
|
||||
else
|
||||
printf "\033[1m\033[${colors[${board[l*$board_size+m]}]}m %4d\033[0m |" ${board[l*$board_size+m]}
|
||||
fi
|
||||
printf " %4d |" ${board[l*$board_size+m]} >&3
|
||||
else
|
||||
printf ' |'
|
||||
printf ' |' >&3
|
||||
fi
|
||||
done
|
||||
let l==$index_max || {
|
||||
printf '\n|------'
|
||||
for l in $(_seq 1 $index_max); do
|
||||
printf '+------'
|
||||
done
|
||||
printf '|\n'
|
||||
printf '\n' >&3
|
||||
}
|
||||
done
|
||||
printf '\n\\------'
|
||||
for l in $(_seq 1 $index_max); do
|
||||
printf '+------'
|
||||
done
|
||||
printf '/\n'
|
||||
}
|
||||
|
||||
# Generate new piece on the board
|
||||
# inputs:
|
||||
# $board - original state of the game board
|
||||
# $pieces - original number of pieces
|
||||
# outputs:
|
||||
# $board - new state of the game board
|
||||
# $pieces - new number of pieces
|
||||
function generate_piece {
|
||||
while true; do
|
||||
let pos=RANDOM%fields_total
|
||||
let board[$pos] || {
|
||||
let value=RANDOM%10?2:4
|
||||
board[$pos]=$value
|
||||
last_added=$pos
|
||||
printf "Generated new piece with value $value at position [$pos]\n" >&3
|
||||
break;
|
||||
}
|
||||
done
|
||||
let pieces++
|
||||
}
|
||||
|
||||
# perform push operation between two pieces
|
||||
# inputs:
|
||||
# $1 - push position, for horizontal push this is row, for vertical column
|
||||
# $2 - recipient piece, this will hold result if moving or joining
|
||||
# $3 - originator piece, after moving or joining this will be left empty
|
||||
# $4 - direction of push, can be either "up", "down", "left" or "right"
|
||||
# $5 - if anything is passed, do not perform the push, only update number
|
||||
# of valid moves
|
||||
# $board - original state of the game board
|
||||
# outputs:
|
||||
# $change - indicates if the board was changed this round
|
||||
# $flag_skip - indicates that recipient piece cannot be modified further
|
||||
# $board - new state of the game board
|
||||
function push_pieces {
|
||||
case $4 in
|
||||
"up")
|
||||
let "first=$2*$board_size+$1"
|
||||
let "second=($2+$3)*$board_size+$1"
|
||||
;;
|
||||
"down")
|
||||
let "first=(index_max-$2)*$board_size+$1"
|
||||
let "second=(index_max-$2-$3)*$board_size+$1"
|
||||
;;
|
||||
"left")
|
||||
let "first=$1*$board_size+$2"
|
||||
let "second=$1*$board_size+($2+$3)"
|
||||
;;
|
||||
"right")
|
||||
let "first=$1*$board_size+(index_max-$2)"
|
||||
let "second=$1*$board_size+(index_max-$2-$3)"
|
||||
;;
|
||||
esac
|
||||
let ${board[$first]} || {
|
||||
let ${board[$second]} && {
|
||||
if test -z $5; then
|
||||
board[$first]=${board[$second]}
|
||||
let board[$second]=0
|
||||
let change=1
|
||||
printf "move piece with value ${board[$first]} from [$second] to [$first]\n" >&3
|
||||
else
|
||||
let moves++
|
||||
fi
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
let ${board[$second]} && let flag_skip=1
|
||||
let "${board[$first]}==${board[second]}" && {
|
||||
if test -z $5; then
|
||||
let board[$first]*=2
|
||||
let "board[$first]==$target" && end_game 1
|
||||
let board[$second]=0
|
||||
let pieces-=1
|
||||
let change=1
|
||||
let score+=${board[$first]}
|
||||
printf "joined piece from [$second] with [$first], new value=${board[$first]}\n" >&3
|
||||
else
|
||||
let moves++
|
||||
fi
|
||||
}
|
||||
}
|
||||
|
||||
function apply_push {
|
||||
printf "\n\ninput: $1 key\n" >&3
|
||||
for i in $(_seq 0 $index_max); do
|
||||
for j in $(_seq 0 $index_max); do
|
||||
flag_skip=0
|
||||
let increment_max=index_max-j
|
||||
for k in $(_seq 1 $increment_max); do
|
||||
let flag_skip && break
|
||||
push_pieces $i $j $k $1 $2
|
||||
done
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
function check_moves {
|
||||
let moves=0
|
||||
apply_push up fake
|
||||
apply_push down fake
|
||||
apply_push left fake
|
||||
apply_push right fake
|
||||
}
|
||||
|
||||
function key_react {
|
||||
let change=0
|
||||
read -d '' -sn 1
|
||||
test "$REPLY" = "$ESC" && {
|
||||
read -d '' -sn 1 -t1
|
||||
test "$REPLY" = "[" && {
|
||||
read -d '' -sn 1 -t1
|
||||
case $REPLY in
|
||||
A) apply_push up;;
|
||||
B) apply_push down;;
|
||||
C) apply_push right;;
|
||||
D) apply_push left;;
|
||||
esac
|
||||
}
|
||||
} || {
|
||||
case $REPLY in
|
||||
k) apply_push up;;
|
||||
j) apply_push down;;
|
||||
l) apply_push right;;
|
||||
h) apply_push left;;
|
||||
|
||||
w) apply_push up;;
|
||||
s) apply_push down;;
|
||||
d) apply_push right;;
|
||||
a) apply_push left;;
|
||||
esac
|
||||
}
|
||||
}
|
||||
|
||||
function save_game {
|
||||
rm -rf "$config_dir"
|
||||
mkdir "$config_dir"
|
||||
echo "${board[@]}" > "$config_dir/board"
|
||||
echo "$board_size" > "$config_dir/board_size"
|
||||
echo "$pieces" > "$config_dir/pieces"
|
||||
echo "$target" > "$config_dir/target"
|
||||
# echo "$log_file" > "$config_dir/log_file"
|
||||
echo "$score" > "$config_dir/score"
|
||||
echo "$first_round" > "$config_dir/first_round"
|
||||
}
|
||||
|
||||
function reload_game {
|
||||
printf "Loading saved game...\n" >&3
|
||||
|
||||
if test ! -d "$config_dir"; then
|
||||
return
|
||||
fi
|
||||
board=(`cat "$config_dir/board"`)
|
||||
board_size=(`cat "$config_dir/board_size"`)
|
||||
board=(`cat "$config_dir/board"`)
|
||||
pieces=(`cat "$config_dir/pieces"`)
|
||||
first_round=(`cat "$config_dir/first_round"`)
|
||||
target=(`cat "$config_dir/target"`)
|
||||
score=(`cat "$config_dir/score"`)
|
||||
|
||||
fields_total=board_size*board_size
|
||||
index_max=board_size-1
|
||||
}
|
||||
|
||||
function end_game {
|
||||
# count game duration
|
||||
end_time=$(date +%s)
|
||||
let total_time=end_time-start_time
|
||||
|
||||
print_board
|
||||
printf "Your score: $score\n"
|
||||
|
||||
printf "This game lasted "
|
||||
|
||||
`date --version > /dev/null 2>&1`
|
||||
if [[ "$?" -eq 0 ]]; then
|
||||
date -u -d @${total_time} +%T
|
||||
else
|
||||
date -u -r ${total_time} +%T
|
||||
fi
|
||||
|
||||
stty echo
|
||||
let $1 && {
|
||||
printf "Congratulations you have achieved $target\n"
|
||||
exit 0
|
||||
}
|
||||
let test -z $2 && {
|
||||
read -n1 -p "Do you want to overwrite saved game? [y|N]: "
|
||||
test "$REPLY" = "Y" || test "$REPLY" = "y" && {
|
||||
save_game
|
||||
printf "\nGame saved. Use -r option next to load this game.\n"
|
||||
exit 0
|
||||
}
|
||||
test "$REPLY" = "" && {
|
||||
printf "\nGame not saved.\n"
|
||||
exit 0
|
||||
}
|
||||
}
|
||||
printf "\nYou have lost, better luck next time.\033[0m\n"
|
||||
exit 0
|
||||
}
|
||||
|
||||
function help {
|
||||
cat <<END_HELP
|
||||
Usage: $1 [-b INTEGER] [-t INTEGER] [-l FILE] [-r] [-h]
|
||||
|
||||
-b specify game board size (sizes 3-9 allowed)
|
||||
-t specify target score to win (needs to be power of 2)
|
||||
-l log debug info into specified file
|
||||
-r reload the previous game
|
||||
-h this help
|
||||
|
||||
END_HELP
|
||||
}
|
||||
|
||||
|
||||
#parse commandline options
|
||||
while getopts "b:t:l:rh" opt; do
|
||||
case $opt in
|
||||
b ) board_size="$OPTARG"
|
||||
let '(board_size>=3)&(board_size<=9)' || {
|
||||
printf "Invalid board size, please choose size between 3 and 9\n"
|
||||
exit -1
|
||||
};;
|
||||
t ) target="$OPTARG"
|
||||
printf "obase=2;$target\n" | bc | grep -e '^1[^1]*$'
|
||||
let $? && {
|
||||
printf "Invalid target, has to be power of two\n"
|
||||
exit -1
|
||||
};;
|
||||
r ) reload_flag="1";;
|
||||
h ) help $0
|
||||
exit 0;;
|
||||
l ) exec 3>$OPTARG;;
|
||||
\?) printf "Invalid option: -"$opt", try $0 -h\n" >&2
|
||||
exit 1;;
|
||||
: ) printf "Option -"$opt" requires an argument, try $0 -h\n" >&2
|
||||
exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
#init board
|
||||
let fields_total=board_size*board_size
|
||||
let index_max=board_size-1
|
||||
for i in $(_seq 0 $fields_total); do board[$i]="0"; done
|
||||
let pieces=0
|
||||
generate_piece
|
||||
first_round=$last_added
|
||||
generate_piece
|
||||
|
||||
#load saved game if flag is set
|
||||
if test $reload_flag = "1"; then
|
||||
reload_game
|
||||
fi
|
||||
|
||||
while true; do
|
||||
print_board
|
||||
key_react
|
||||
let change && generate_piece
|
||||
first_round=-1
|
||||
let pieces==fields_total && {
|
||||
check_moves
|
||||
let moves==0 && end_game 0 #lose the game
|
||||
}
|
||||
done
|
18
bin/changelog
Executable file
18
bin/changelog
Executable file
@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
echo ""
|
||||
echo "CHANGELOG"
|
||||
git tag -l | sort -u -r | while read TAG ; do
|
||||
echo
|
||||
if [ $NEXT ];then
|
||||
echo [$NEXT]
|
||||
else
|
||||
echo "[Current]"
|
||||
fi
|
||||
GIT_PAGER=cat git log --no-merges --format=" * %s" $TAG..$NEXT
|
||||
NEXT=$TAG
|
||||
done
|
||||
FIRST=$(git tag -l | head -1)
|
||||
echo
|
||||
echo [$FIRST]
|
||||
GIT_PAGER=cat git log --no-merges --format=" * %s" $FIRST
|
||||
|
66
bin/christtree.sh
Executable file
66
bin/christtree.sh
Executable file
@ -0,0 +1,66 @@
|
||||
#!/bin/bash
|
||||
trap "tput reset; tput cnorm; exit" 2
|
||||
clear
|
||||
tput civis
|
||||
lin=2
|
||||
col=$(($(tput cols) / 2))
|
||||
c=$((col-1))
|
||||
est=$((c-2))
|
||||
color=0
|
||||
tput setaf 2; tput bold
|
||||
|
||||
for ((i=1; i<40; i+=2))
|
||||
{
|
||||
tput cup $lin $col
|
||||
for ((j=1; j<=i; j++))
|
||||
{
|
||||
echo -n \*
|
||||
}
|
||||
let lin++
|
||||
let col--
|
||||
}
|
||||
|
||||
tput sgr0; tput setaf 3
|
||||
|
||||
for ((i=1; i<=2; i++))
|
||||
{
|
||||
tput cup $((lin++)) $c
|
||||
echo 'mWm'
|
||||
}
|
||||
new_year=$(date +'%Y')
|
||||
let new_year++
|
||||
tput setaf 1; tput bold
|
||||
tput cup $lin $((c - 6)); echo MERRY CHRISTMAS
|
||||
tput cup $((lin + 1)) $((c - 10)); echo And lots of CODE in $new_year
|
||||
let c++
|
||||
k=1
|
||||
|
||||
while true; do
|
||||
for ((i=1; i<=155; i++)) {
|
||||
[ $k -gt 1 ] && {
|
||||
tput setaf 2; tput bold
|
||||
tput cup ${linea[$[k-1]$i]} ${columna[$[k-1]$i]}; echo \*
|
||||
unset linea[$[k-1]$i]; unset columna[$[k-1]$i]
|
||||
}
|
||||
|
||||
li=$((RANDOM % 19 + 3))
|
||||
inicio=$((c-li+2))
|
||||
fin=$((c+li+2))
|
||||
co=$((RANDOM % (li-2) * 2 + 1 + inicio))
|
||||
tput setaf $color; tput bold
|
||||
tput cup $li $co
|
||||
echo o
|
||||
linea[$k$i]=$li
|
||||
columna[$k$i]=$co
|
||||
color=$(((color+1)%8))
|
||||
sh=1
|
||||
for l in C O D E
|
||||
do
|
||||
tput cup $((lin+1)) $((c+sh))
|
||||
echo $l
|
||||
let sh++
|
||||
sleep 0.01
|
||||
done
|
||||
}
|
||||
k=$((k % 2 + 1))
|
||||
done
|
3
bin/crpass
Executable file
3
bin/crpass
Executable file
@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
dd if=/dev/urandom bs=24 count=1 2>/dev/null | base64
|
366
bin/gogs
Executable file
366
bin/gogs
Executable file
@ -0,0 +1,366 @@
|
||||
#!/bin/bash
|
||||
# Interact with the GOGS API
|
||||
# Copyright (c) 2017 Matthew Downey (mattddowney@gmail_NOSPAM_.com)
|
||||
# Relased under the MIT License
|
||||
# See https://raw.githubusercontent.com/mattddowney/gogs-bash/master/LICENSE for the complete license text
|
||||
|
||||
action=${1:-"help"}
|
||||
|
||||
# preseed for checks
|
||||
response_code=0
|
||||
|
||||
# ensure GOGS_ROOT_URL is set
|
||||
if [ -z $GOGS_ROOT_URL ]
|
||||
then
|
||||
printf "Need to set GOGS_ROOT_URL environment variable\n" >&2
|
||||
printf "\tIE: https://try.gogs.io\n" >&2
|
||||
|
||||
response_code=1
|
||||
fi
|
||||
|
||||
# ensure GOGS_TOKEN is set
|
||||
if [ -z $GOGS_TOKEN ]
|
||||
then
|
||||
printf "Need to set GOGS_TOKEN environment variable\n" >&2
|
||||
printf "\tThis can be obtained at $GOGS_ROOT_URL/user/settings/applications\n" >&2
|
||||
|
||||
response_code=1
|
||||
fi
|
||||
|
||||
# exit if either of the environment variables above are not set
|
||||
if [ $response_code -ne 0 ]
|
||||
then
|
||||
exit $response_code
|
||||
fi
|
||||
|
||||
# create a GOGS repository
|
||||
# https://github.com/gogits/go-gogs-client/wiki/Administration-Repositories#create-a-new-repository
|
||||
create-repo() {
|
||||
local user_name=$1 # name of the user / organization where the repo will be created
|
||||
local repo_name=$2 # name of the repo to be created
|
||||
|
||||
# ensure user_name is passed in
|
||||
if [ -z $user_name ]
|
||||
then
|
||||
response_code=1
|
||||
fi
|
||||
|
||||
# ensure repo_name is passed in
|
||||
if [ -z $repo_name ]
|
||||
then
|
||||
response_code=1
|
||||
fi
|
||||
|
||||
# print help and exit either of the variables above are not passed in
|
||||
if [ $response_code -ne 0 ]
|
||||
then
|
||||
help "create-repo"
|
||||
|
||||
exit $response_code
|
||||
fi
|
||||
|
||||
printf "--" "---> Creating GOGS repository\n"
|
||||
printf "--" "---> User/Org Name: $user_name\n"
|
||||
printf "--" "---> Repo Name: $repo_name\n"
|
||||
|
||||
local body=$(cat <<-END
|
||||
{
|
||||
"name": "$repo_name",
|
||||
"private": false
|
||||
}
|
||||
END
|
||||
)
|
||||
|
||||
curl -H "Content-Type: application/json" \
|
||||
-H "Authorization: token $GOGS_TOKEN" \
|
||||
-d "$body" \
|
||||
-v $GOGS_ROOT_URL/api/v1/admin/users/$user_name/repos
|
||||
}
|
||||
|
||||
# create a GOGS webhook
|
||||
# https://github.com/gogits/go-gogs-client/wiki/Repositories-Webhooks#create-a-hook
|
||||
create-webhook() {
|
||||
local user_name=$1 # name of the user / organization that owns the repo where the webhook will be created
|
||||
local repo_name=$2 # name of the repo where the webhook will be created
|
||||
local webhook_url=$3 # the url for the webhook that will be created
|
||||
local secret=$4 # optional secret that will be passed in the X-Gogs-Signature header
|
||||
|
||||
# ensure user_name is passed in
|
||||
if [ -z $user_name ]
|
||||
then
|
||||
response_code=1
|
||||
fi
|
||||
|
||||
# ensure repo_name is passed in
|
||||
if [ -z $repo_name ]
|
||||
then
|
||||
response_code=1
|
||||
fi
|
||||
|
||||
# ensure that webhook_url is passed in
|
||||
if [ -z $webhook_url ]
|
||||
then
|
||||
response_code=1
|
||||
fi
|
||||
|
||||
# print help and exit either of the variables above are not passed in
|
||||
if [ $response_code -ne 0 ]
|
||||
then
|
||||
help "create-webhook"
|
||||
|
||||
exit $response_code
|
||||
fi
|
||||
|
||||
printf "--" "---> Creating GOGS webhook\n"
|
||||
printf "--" "---> Repo Name: $repo_name\n"
|
||||
printf "--" "---> Webhook URL: $webhook_url\n"
|
||||
|
||||
local body=$(cat <<-END
|
||||
{
|
||||
"type": "gogs",
|
||||
"config": {
|
||||
"content_type": "json",
|
||||
"url": "$webhook_url"
|
||||
},
|
||||
"events": [ "create", "push" ],
|
||||
"active": true
|
||||
}
|
||||
END
|
||||
)
|
||||
|
||||
# add secret to body if one is passed in
|
||||
if [ -n $secret ]
|
||||
then
|
||||
body=$(echo "$body" | jq ".config.secret=\"$secret\"")
|
||||
fi
|
||||
|
||||
curl -H "Content-Type: application/json" \
|
||||
-H "Authorization: token $GOGS_TOKEN" \
|
||||
-d "$body" \
|
||||
-v $GOGS_ROOT_URL/api/v1/repos/$user_name/$repo_name/hooks
|
||||
}
|
||||
|
||||
# delete a GOGS webhook for a repo
|
||||
# https://github.com/gogits/go-gogs-client/wiki/Repositories-Webhooks#delete-a-hook
|
||||
delete-webhook() {
|
||||
local user_name=$1
|
||||
local repo_name=$2
|
||||
local webhook_id=$3
|
||||
|
||||
# ensuer user_name is passed in
|
||||
if [ -z $user_name ]
|
||||
then
|
||||
response_code=1
|
||||
fi
|
||||
|
||||
# ensure repo_name is passed in
|
||||
if [ -z $repo_name ]
|
||||
then
|
||||
response_code=1
|
||||
fi
|
||||
|
||||
# ensure webhook_id is passed in
|
||||
if [ -z $webhook_id ]
|
||||
then
|
||||
response_code=1
|
||||
fi
|
||||
|
||||
# print help and exit any of the variables above are not passed in
|
||||
if [ $reponse_code -ne 0 ]
|
||||
then
|
||||
help "delete-webhook"
|
||||
|
||||
exit $response_code
|
||||
fi
|
||||
|
||||
printf "--" "---> Deleting GOGS webhook\n"
|
||||
printf "--" "---> User Name: $user_name\n"
|
||||
printf "--" "---> Repo Name: $repo_name\n"
|
||||
printf "--" "---> Webhook Id: $webhook_id\n"
|
||||
|
||||
curl -H "Authorization: token $GOGS_TOKEN" \
|
||||
-X DELETE \
|
||||
-v $GOGS_ROOT_URL/api/v1/repos/$user_name/$repo_name/hooks/$webhook_id
|
||||
}
|
||||
|
||||
# print environment information
|
||||
env() {
|
||||
printf "GOGS_ROOT_URL=$GOGS_ROOT_URL\n"
|
||||
printf "GOGS_TOKEN=$GOGS_TOKEN\n"
|
||||
}
|
||||
|
||||
# get a list of GOGS repos for a user
|
||||
# https://github.com/gogits/go-gogs-client/wiki/Repositories#list-user-repositories
|
||||
get-user-repos() {
|
||||
local user_name=$1 # name of the user who's repos to list
|
||||
|
||||
# ensure user_name is passed in
|
||||
if [ -z $user_name ]
|
||||
then
|
||||
help "get-user-repos"
|
||||
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf "--" "---> Getting list of GOGS repos\n"
|
||||
printf "--" "---> User Name: $user_name\n"
|
||||
|
||||
curl -H "Content-Type: application/json" \
|
||||
-H "Authorization: token $GOGS_TOKEN" \
|
||||
-v $GOGS_ROOT_URL/api/v1/users/$user_name/repos
|
||||
}
|
||||
|
||||
# get a list of GOGS webhooks for a repo
|
||||
# https://github.com/gogits/go-gogs-client/wiki/Repositories-Webhooks#list-hooks
|
||||
get-webhooks() {
|
||||
local user_name=$1 # name of the user / organization that owns the repo
|
||||
local repo_name=$2 # name of the repo to list webhooks for
|
||||
|
||||
# ensure user_name is passed in
|
||||
if [ -z $user_name ]
|
||||
then
|
||||
response_code=1
|
||||
fi
|
||||
|
||||
# ensure repo_name is passed in
|
||||
if [ -z $repo_name ]
|
||||
then
|
||||
response_code=1
|
||||
fi
|
||||
|
||||
# print help and exit either of the variables above are not passed in
|
||||
if [ $response_code -ne 0 ]
|
||||
then
|
||||
help "get-webhooks"
|
||||
|
||||
exit $response_code
|
||||
fi
|
||||
|
||||
printf "--" "---> Getting list of GOGS webhooks\n"
|
||||
printf "--" "---> User Name: $user_name\n"
|
||||
printf "--" "---> Repo Name: $repo_name\n"
|
||||
|
||||
curl -H "Authorization: token $GOGS_TOKEN" \
|
||||
-v $GOGS_ROOT_URL/api/v1/repos/$user_name/$repo_name/hooks
|
||||
}
|
||||
|
||||
# print help
|
||||
help() {
|
||||
local prog_name=$(echo "$0" | rev | cut -d'/' -f1 | rev)
|
||||
local topic=$1
|
||||
|
||||
case "$topic" in
|
||||
create-repo)
|
||||
cat <<-END
|
||||
Create a GOGS repository.
|
||||
|
||||
Usage:
|
||||
|
||||
$prog_name $1 <user_name> <repo_name>
|
||||
|
||||
Arguments:
|
||||
|
||||
user_name name of the user or organization where the repo will be created
|
||||
repo_name name of the repository to be created
|
||||
END
|
||||
;;
|
||||
|
||||
create-webhook)
|
||||
cat <<-END
|
||||
Create a GOGS webhook.
|
||||
|
||||
Usage:
|
||||
|
||||
$prog_name $1 <user_name> <repo_name> <webhook_url> [secret]
|
||||
|
||||
Arguments:
|
||||
|
||||
user_name name of the user / organizationo that owns the repo where the webhook will be created
|
||||
repo_name name of the repo where the webhook will be created
|
||||
webhook_url the url for the webhook that will be created
|
||||
secret optional secret that will be passed in the X-Gogs-Signature header
|
||||
END
|
||||
;;
|
||||
|
||||
delete-webhook)
|
||||
cat <<-END
|
||||
Delete a GOGS webhook.
|
||||
|
||||
Usage:
|
||||
|
||||
$prog_name $1 <user_name> <repo_name> <webhook_id>
|
||||
|
||||
Arguments:
|
||||
|
||||
user_name name of the user / organizationo that owns the repo containing the webhook
|
||||
repo_name name of the repo that contains the webhook
|
||||
webhook_id id of the webhook that will be deleted
|
||||
END
|
||||
;;
|
||||
|
||||
env)
|
||||
cat <<-END
|
||||
Prints environment variables needed by this script.
|
||||
|
||||
Variables:
|
||||
|
||||
GOGS_ROOT_URL The url of the GOGS server
|
||||
(IE: https://try.gogs.io)
|
||||
|
||||
GOGS_TOKEN Application token configured in GOGS
|
||||
(Obtained from $GOGS_ROOT_URL/user/settings/applications)
|
||||
END
|
||||
;;
|
||||
|
||||
get-user-repos)
|
||||
cat <<-END
|
||||
Get a list of GOGS repos for a user.
|
||||
|
||||
Usage:
|
||||
|
||||
$prog_name $1 <user_name>
|
||||
|
||||
Arguments:
|
||||
|
||||
user_name name of the user who's repos to list
|
||||
END
|
||||
;;
|
||||
|
||||
get-webhooks)
|
||||
cat <<-END
|
||||
Get a list of GOGS webhooks for a repo.
|
||||
|
||||
Usage:
|
||||
|
||||
$prog_name $1 <user_name> <repo_name>
|
||||
|
||||
Arguments:
|
||||
|
||||
user_name name of the user / organization that owns the repo
|
||||
repo_name name of the repo to list webhooks for
|
||||
END
|
||||
;;
|
||||
|
||||
*)
|
||||
cat <<-END
|
||||
$prog_name is a tool for interacting with the GOGS API.
|
||||
|
||||
Usage:
|
||||
$prog_name command [arguments]
|
||||
|
||||
The commands are:
|
||||
|
||||
create-repo create a repository
|
||||
create-webhook create a webhook
|
||||
delete-webhook delete a webhook
|
||||
env print environment information
|
||||
get-user-repos get a list of repos for a user
|
||||
get-webhooks get a list of webhooks for a repo
|
||||
|
||||
Use "$prog_name help [command]" for more information about a command.
|
||||
END
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
"$action" "${@:2}"
|
1326
bin/jsawk
Executable file
1326
bin/jsawk
Executable file
File diff suppressed because one or more lines are too long
14
bin/make_archive
Executable file
14
bin/make_archive
Executable file
@ -0,0 +1,14 @@
|
||||
#!/bin/bash -x
|
||||
|
||||
ARCHDIR="/home/paramah/Backups"
|
||||
GIT=`which git`
|
||||
PROJEKT=${PWD##*/}
|
||||
DATE=`date +%Y-%m-%d`
|
||||
|
||||
dir=$ARCHDIR/$PROJEKT
|
||||
|
||||
if [[ ! -e $dir ]]; then
|
||||
mkdir $dir
|
||||
fi
|
||||
|
||||
$GIT archive master --format=zip --output=$ARCHDIR/$PROJEKT/$DATE.zip
|
121
bin/pipes.sh
Executable file
121
bin/pipes.sh
Executable file
@ -0,0 +1,121 @@
|
||||
#!/usr/bin/env bash
|
||||
# pipes.sh: Animated pipes terminal screensaver.
|
||||
#
|
||||
# This modified version is maintained at:
|
||||
#
|
||||
# https://github.com/livibetter/pipes.sh
|
||||
|
||||
VERSION=0.1.1
|
||||
|
||||
M=32768
|
||||
p=1
|
||||
f=75 s=13 r=2000 t=0
|
||||
w=$(tput cols) h=$(tput lines)
|
||||
# ab -> idx = a*4 + b
|
||||
# 0: up, 1: right, 2: down, 3: left
|
||||
# 00 means going up , then going up -> ┃
|
||||
# 12 means going right, then going down -> ┓
|
||||
sets=(
|
||||
"┃┏ ┓┛━┓ ┗┃┛┗ ┏━"
|
||||
"│╭ ╮╯─╮ ╰│╯╰ ╭─"
|
||||
"│┌ ┐┘─┐ └│┘└ ┌─"
|
||||
"║╔ ╗╝═╗ ╚║╝╚ ╔═"
|
||||
"|+ ++-+ +|++ +-"
|
||||
"|/ \/-\ \|/\ /-"
|
||||
)
|
||||
v=()
|
||||
RNDSTART=0
|
||||
NOCOLOR=0
|
||||
|
||||
OPTIND=1
|
||||
while getopts "p:t:f:s:r:RChv" arg; do
|
||||
case $arg in
|
||||
p) ((p=(OPTARG>0)?OPTARG:p));;
|
||||
t) ((OPTARG>=0 && OPTARG<${#sets[@]})) && V+=($OPTARG);;
|
||||
f) ((f=(OPTARG>19 && OPTARG<101)?OPTARG:f));;
|
||||
s) ((s=(OPTARG>4 && OPTARG<16 )?OPTARG:s));;
|
||||
r) ((r=(OPTARG>=0)?OPTARG:r));;
|
||||
R) RNDSTART=1;;
|
||||
C) NOCOLOR=1;;
|
||||
h) echo -e "Usage: $(basename $0) [OPTION]..."
|
||||
echo -e "Animated pipes terminal screensaver.\n"
|
||||
echo -e " -p [1-]\tnumber of pipes (D=1)."
|
||||
echo -e " -t [0-$((${#sets[@]} - 1))]\ttype of pipes, can be used more than once (D=0)."
|
||||
echo -e " -f [20-100]\tframerate (D=75)."
|
||||
echo -e " -s [5-15]\tprobability of a straight fitting (D=13)."
|
||||
echo -e " -r LIMIT\treset after x characters, 0 if no limit (D=2000)."
|
||||
echo -e " -R \t\trandom starting point."
|
||||
echo -e " -C \t\tno color."
|
||||
echo -e " -h\t\thelp (this screen)."
|
||||
echo -e " -v\t\tprint version number.\n"
|
||||
exit 0;;
|
||||
v) echo "$(basename -- "$0") $VERSION"
|
||||
exit 0
|
||||
esac
|
||||
done
|
||||
|
||||
# set default values if not by options
|
||||
((${#V[@]})) || V=(0)
|
||||
|
||||
# Attempt to workaround for Bash versions < 4, such as 3.2 on Mac:
|
||||
# https://gist.github.com/livibetter/4689307/#comment-892368
|
||||
# Untested--in conduction of using shebang `env bash`--should fall back to
|
||||
# `sleep`
|
||||
printf -v SLEEP "read -t0.0$((1000/f)) -n 1"
|
||||
if $SLEEP &>/dev/null; (($? != 142)); then
|
||||
printf -v SLEEP "sleep 0.0$((1000/f))"
|
||||
fi
|
||||
|
||||
cleanup() {
|
||||
# clear up standard input
|
||||
read -t 0 && cat </dev/stdin>/dev/null
|
||||
|
||||
# terminal has no smcup and rmcup capabilities
|
||||
((FORCE_RESET)) && reset && exit 0
|
||||
|
||||
tput rmcup
|
||||
tput cnorm
|
||||
stty echo
|
||||
((NOCOLOR)) && echo -ne '\e[0m'
|
||||
exit 0
|
||||
}
|
||||
trap cleanup HUP TERM
|
||||
trap 'break 2' INT
|
||||
|
||||
for (( i=1; i<=p; i++ )); do
|
||||
c[i]=$((i%8)) n[i]=0 l[i]=0
|
||||
((x[i]=RNDSTART==1?RANDOM*w/32768:w/2))
|
||||
((y[i]=RNDSTART==1?RANDOM*h/32768:h/2))
|
||||
v[i]=${V[${#V[@]} * RANDOM / M]}
|
||||
done
|
||||
|
||||
stty -echo
|
||||
tput smcup || FORCE_RESET=1
|
||||
tput civis
|
||||
tput clear
|
||||
# any key press exits the loop and this script
|
||||
while REPLY=; $SLEEP; [[ -z $REPLY ]] ; do
|
||||
for (( i=1; i<=p; i++ )); do
|
||||
# New position:
|
||||
((${l[i]}%2)) && ((x[i]+=-${l[i]}+2,1)) || ((y[i]+=${l[i]}-1))
|
||||
|
||||
# Loop on edges (change color on loop):
|
||||
((${x[i]}>w||${x[i]}<0||${y[i]}>h||${y[i]}<0)) && ((c[i]=RANDOM%8, v[i]=V[${#V[@]}*RANDOM/M]))
|
||||
((x[i]=(x[i]+w)%w))
|
||||
((y[i]=(y[i]+h)%h))
|
||||
|
||||
# New random direction:
|
||||
((n[i]=RANDOM%s-1))
|
||||
((n[i]=(${n[i]}>1||${n[i]}==0)?${l[i]}:${l[i]}+${n[i]}))
|
||||
((n[i]=(${n[i]}<0)?3:${n[i]}%4))
|
||||
|
||||
# Print:
|
||||
tput cup ${y[i]} ${x[i]}
|
||||
[[ $NOCOLOR == 0 ]] && echo -ne "\033[1;3${c[i]}m"
|
||||
echo -n "${sets[v[i]]:l[i]*4+n[i]:1}"
|
||||
l[i]=${n[i]}
|
||||
done
|
||||
((r>0 && t*p>=r)) && tput reset && tput civis && t=0 || ((t++))
|
||||
done
|
||||
|
||||
cleanup
|
Reference in New Issue
Block a user