summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiusto <giusto@Macbook-M1-Max.local>2024-07-25 09:33:12 +0800
committerGiusto <giusto@Macbook-M1-Max.local>2024-07-25 09:33:12 +0800
commit421f0b1693d668a2d450b909db18eeb67328db7a (patch)
treef5ee27157b6d8c40eeacd8820b7275e9d5b999bd
create a directory to contain only script that fill my own needs
-rw-r--r--.DS_Storebin0 -> 6148 bytes
-rwxr-xr-xblog-zola.sh119
-rwxr-xr-xblog.sh89
-rwxr-xr-xcalculate_salarybin0 -> 600808 bytes
-rwxr-xr-xdata_decrypt.sh34
-rwxr-xr-xdata_encrypt.sh30
-rwxr-xr-xmkproj.sh82
7 files changed, 354 insertions, 0 deletions
diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 0000000..f4fabc9
--- /dev/null
+++ b/.DS_Store
Binary files differ
diff --git a/blog-zola.sh b/blog-zola.sh
new file mode 100755
index 0000000..c620789
--- /dev/null
+++ b/blog-zola.sh
@@ -0,0 +1,119 @@
+#!/usr/bin/env sh
+
+######################################################################
+# @author : garhve (dev@garhve.com)
+# @file : blog
+# @created : Friday Dec 09, 2022 16:09:42 CST
+#
+# @description : simplify blog publishing, it only can use in blog dir
+######################################################################
+
+# usage: prog funct
+
+push() {
+ read -r -p "Do you want to push?[y/n] " ans
+ if [ "$ans" == 'y' ]; then
+ zola build
+ git add .
+ if [ ! -z "$(git status | grep 'Changes to be committed')" ]; then
+ read -r -p "commit message: " msg
+ git commit -m "$msg"
+ git push origin main
+ fi
+ echo -e "push done"
+ fi
+}
+
+edit() {
+ path="content/post"
+
+ # --- get editing file
+ choice=1
+ declare -a arr
+ for file in $path/*; do
+ [[ "$file" == *"_index.md" ]] && continue
+ echo -ne "($choice)\x1b[0;32m${file##*/}\x1b[0m " # n get rid of trailing new line, e strip backslash
+ arr[$choice]="$file"
+ choice=$((choice+1))
+ done
+ echo ""
+ read -r -p "please choose file by number you want to edit from above: " num
+ [[ "$num" == "q" ]] && exit 0
+ vim "${arr[$num]}"
+ # --- end
+ echo -e "edit done\n"
+
+ push
+ echo -e "\nall done"
+}
+
+new() {
+ read -r -p "blog name: " name
+ path="content/post/$name"
+
+ if [ ! -f "$path".md ]; then
+
+ # get basic format
+ d="$(date +%F)"
+ echo -ne "\x1b[32m"
+ echo -n "existing categories: "
+ grep -wrn content -e "categories" | \
+ awk -F = '{ print $2 }' | \
+ sort | uniq | paste -s -d ' '
+ echo -ne "\x1b[0m"
+ read -r -p "category: " category
+ echo -ne "\x1b[32m"
+ echo -n "existing tags: "
+ grep -wrn content -e "tags" | \
+ awk -F = '{ print $2 }' | \
+ sort | uniq | paste -s -d ' '
+ echo -ne "\x1b[0m"
+ read -r -p "tag: " tags
+ read -r -p "math support [y/n]: " m
+ if [ "${m,,}" == 'y' ]; then
+ math_support="true"
+ else
+ math_support="false"
+ fi
+
+ cat << EOF > "$path".md
++++
+title = "$name"
+date = $d
+[taxonomies]
+categories = ["$category"]
+tags = ["$tags"]
+[extra]
+math = $math_support
++++
+EOF
+
+ [ "$?" -eq 0 ] && echo "creation done"
+ [ "$?" -ne 0 ] && echo "creation fail, please check error" && exit 1
+
+ else
+ echo "File exist"
+ fi
+
+ read -r -p "do you want to edit now?[y/n] " ans
+ [ "${ans,,}" == 'y' ] && vim "$path.md" && echo "edit done"
+
+ push
+
+ echo -e "\nall done"
+}
+
+list() {
+ echo -e "\x1b[1;34mList content:\x1b[0m"
+ tree ./content/post
+}
+
+
+funct="new/edit/push/ls"
+
+[ $# -lt 1 ] && echo "usage: $(basename $0) $funct"
+
+[ $1 == "new" ] && new
+[ $1 == "edit" ] && edit
+[ $1 == "push" ] && push
+[ $1 == "ls" ] && list
diff --git a/blog.sh b/blog.sh
new file mode 100755
index 0000000..98be50b
--- /dev/null
+++ b/blog.sh
@@ -0,0 +1,89 @@
+#!/usr/bin/env sh
+
+######################################################################
+# @author : garhve (dev@garhve.com)
+# @file : blog
+# @created : Friday Dec 09, 2022 16:09:42 CST
+#
+# @description : simplify blog publishing, it only can use in blog dir
+######################################################################
+
+# usage: prog funct [en/cn]
+
+push() {
+ read -r -p "Do you want to push?[y/n] " ans
+ if [ "$ans" == 'y' ]; then
+ hugo
+ cd "public"
+ git add .
+ if [ ! -z "$(git status | grep 'Changes to be committed')" ]; then
+ read -r -p "commit message: " msg
+ git commit -m "$msg"
+ git push origin main
+ fi
+ echo -e "push done"
+ fi
+}
+
+edit() {
+ # --- define path
+ [ -z "$1" ] || [ "$1" == "en" ] && lang="en"
+ [ "$1" == "cn" ] && lang="cn"
+ path="content/$lang/posts"
+ # --- end
+
+ # --- get editing file
+ choice=1
+ declare -a arr
+ for file in $path/*; do
+ echo -ne "($choice)\x1b[0;32m${file##*/}\x1b[0m " # n get rid of trailing new line, e strip backslash
+ arr[$choice]="$file"
+ choice=$((choice+1))
+ done
+ echo ""
+ read -r -p "please choose file by number you want to edit from above [$lang]: " num
+ vim "${arr[$num]}"
+ # --- end
+ echo -e "edit done\n"
+
+ push
+ echo -e "\nall done"
+}
+
+new() {
+ read -r -p "blog name: " name
+ post="posts/$name"
+
+ [ -z "$1" ] || [ "$1" == "en" ] && lang="en"
+ [ "$1" == "cn" ] && lang="cn"
+ path="content/$lang/posts"
+ hugo new "${post}.md"
+ [ "$?" -eq 0 ] && echo "creation done"
+ [ "$?" -ne 0 ] && echo "creation fail, please check error" && exit 1
+
+ [ "$lang" == "cn" ] && mv "content/en/posts/$name.md" "$path/$name.md"
+
+ read -r -p "do you want to edit now?[y/n] " ans
+ [ "${ans,,}" == 'y' ] && vim "$path/$name.md" && echo "edit done"
+
+ push
+
+ echo -e "\nall done"
+}
+
+list() {
+ echo -e "List \x1b[1;34mEN\x1b[0m content:"
+ tree ./content/en/posts
+ echo -e "List \x1b[1;33mCN\x1b[0m content:"
+ tree ./content/cn/posts
+}
+
+
+funct="new/edit/push/ls"
+
+[ $# -lt 1 ] && echo "usage: $(basename $0) $funct [en/cn]"
+
+[ $1 == "new" ] && new "$2"
+[ $1 == "edit" ] && edit "$2"
+[ $1 == "push" ] && push
+[ $1 == "ls" ] && list
diff --git a/calculate_salary b/calculate_salary
new file mode 100755
index 0000000..c39b78c
--- /dev/null
+++ b/calculate_salary
Binary files differ
diff --git a/data_decrypt.sh b/data_decrypt.sh
new file mode 100755
index 0000000..6d5b477
--- /dev/null
+++ b/data_decrypt.sh
@@ -0,0 +1,34 @@
+#!/usr/bin/env sh
+
+######################################################################
+# @author : Garhve (garhve@gmail.com)
+# @file : decrypt
+# @created : Wednesday Jan 10, 2024 01:09:07 CST
+#
+# @description : decrypt files that encrypt by gpg
+######################################################################
+
+for file in $@
+do
+ # get suffix
+ suffix=$(echo "$file" | rev | cut -d '.' -f1 | rev)
+ # get no suffix name
+ f_no_suffix="${file%.*}"
+
+ # check either name is ending with gpg or a*
+ if [ $suffix = "gpg" ]; then
+ # if end with gpg, decrypt directly
+ gpg --output "${f_no_suffix}" --decrypt "$file"
+
+ tar zxvf "${f_no_suffix}" && rm $f_no_suffix
+ else
+ # else join the parts before decrypt
+ cat ${f_no_suffix}.* > "$f_no_suffix"
+
+ # get name without gpg suffix
+ f_no_gpg="${f_no_suffix%.*}"
+ gpg --output "${f_no_gpg}" --decrypt "$f_no_suffix"
+
+ tar zxvf "$f_no_gpg" && rm $f_no_gpg $f_no_suffix
+ fi
+done
diff --git a/data_encrypt.sh b/data_encrypt.sh
new file mode 100755
index 0000000..5a85359
--- /dev/null
+++ b/data_encrypt.sh
@@ -0,0 +1,30 @@
+#!/usr/bin/env sh
+
+######################################################################
+# @author : Garhve (garhve@gmail.com)
+# @file : encrypt
+# @created : Tuesday Jan 09, 2024 22:06:31 CST
+#
+# @description : encrypt file/directory with gpg
+######################################################################
+
+recipient=garhve
+
+for file in $@
+do
+ cfile="${file}.tar.gz" #file.tar.gz
+ gfile="${cfile}.gpg" #file.tar.gz.gpg
+
+ tar zcvf "$cfile" "$file" && gunzip -t "$cfile"
+ gpg --output "${gfile}" --recipient $recipient --encrypt "${cfile}"
+
+ rm "$cfile"
+ # split file if the size is larger than 1G
+ size=$(du -sh "${gfile}" | awk -F '\t' '{print $1}')
+ s_suffix="${size:0-1}"
+
+ if [ $s_suffix = 'G' ]; then
+ split -b 1G "$gfile" "${gfile}."
+ rm "$gfile"
+ fi
+done
diff --git a/mkproj.sh b/mkproj.sh
new file mode 100755
index 0000000..75f41f9
--- /dev/null
+++ b/mkproj.sh
@@ -0,0 +1,82 @@
+#!/usr/bin/env sh
+
+######################################################################
+# @author : pico (pico@$HOSTNAME)
+# @file : mkproj
+# @created : Tuesday Dec 06, 2022 13:33:51 CST
+#
+# @description : shell script to simplify cgit
+######################################################################
+
+NC='\x1b[0m'
+BLUE='\x1b[0;34m'
+YELLOW='\033[0;33m'
+RED='\x1b[0;31m'
+
+path="$HOME/.local/git"
+config="$HOME/.config/git/git_template/hooks"
+work="$HOME/git"
+
+echo "Start making bare repo"
+echo -e "The repo will be located in $BLUE$path$NC"
+read -r -p "Enter the repo name: " repo
+
+repo="${repo:-null}"
+[ "${repo}" == 'null' ] && echo "no specific repo name was given" && exit 1
+
+# dealing with bare repo
+if [ ! -d $path ]; then
+ echo -e "$RED$path$NC doesn't exist."
+ read -n1 -r -p "Do you want to create it(y or n) " option
+
+ # set default value to 'n'
+ if [ $option != 'y' ] && [ $option != 'n' ]; then
+ option='n'
+ fi
+
+ # if y is given, create git directory
+ if [ $option == 'y' ]; then
+ mkdir -p "$path"
+ [ "$?" -ne 0 ] && echo "failed create path" || echo "$path created, now create repo"
+ fi
+
+ # quit script
+ [ $option == 'n' ] && echo -e "${YELLOW}quit script$NC"
+else
+ echo -e "${BLUE}$path${NC} exists, check if $repo exists"
+fi
+
+# check if repo already exists
+[ -d "$path/$repo" ] && \
+ if [ -z "$(git -C $path/$repo rev-parse)" ]; then
+ echo -e "${YELLOW}$repo$NC exists, please check your git repo"
+ elif [ -s "$path/$repo" ]; then
+ echo -e "${YELLOW}$repo$NC is not empty, please check directory"
+ fi && \
+ exit 1
+
+echo -e "${YELLOW}$repo$NC does not exist, create repo"
+git --bare init "$path/$repo" > /dev/null 2>&1
+#read owner
+read -r -p "Enter the owner of the repo: " owner
+#read description
+read -r -p "Enter the description for this repo: " desc
+# set info
+[ ! -z "$owner" ] && echo "[gitweb]" >> "$path/$repo/config" && echo " owner = $owner" >> "$path/$repo/config"
+[ ! -z "$desc" ] && echo "$desc" > "$path/$repo/description"
+
+echo -e "${YELLOW}finished bare repo creation!$NC"
+
+# set working tree
+echo ""
+echo -e "Centralized hooks are already set in ${BLUE}$config$NC"
+echo -e -n "Do you want to set working tree? (git repo will be created in ${BLUE}$work$NC y/n): "
+read -r wt
+
+if [ $wt == 'n' ] || [ $wt != 'y' ]; then
+ echo -e "${YELLOW}creation finished${NC}"
+ exit 1
+else
+ mkdir -p "$work/$repo"
+ [ "$?" -ne 0 ] && echo -e "failed creating ${BLUE}$work/$repo${NC}, please check permission" || echo -e "${YELLOW}creation finished${NC}"
+fi