OILS / soil / common.sh View on Github | oilshell.org

106 lines, 70 significant
1# Common functions for soil/
2
3# Include guard.
4test -n "${__SOIL_COMMON_SH:-}" && return
5readonly __SOIL_COMMON_SH=1
6
7log() {
8 echo "$@" 1>&2
9}
10
11log-context() {
12 local label=$1
13
14 log ''
15 log "$label: running as user '$(whoami)' on host '$(hostname)' in dir $PWD"
16 log ''
17}
18
19dump-env() {
20 env | grep -v '^encrypted_' | sort
21}
22
23# dh, mb, op
24#_soil_service=mb
25_soil_service=dh
26
27case $_soil_service in
28 dh)
29 readonly SOIL_USER='travis_admin'
30 readonly SOIL_HOST='ci.oilshell.org'
31 readonly SOIL_HOST_DIR=~/ci.oilshell.org # used on server
32 readonly SOIL_REMOTE_DIR=ci.oilshell.org # used on client
33 ;;
34 mb)
35 readonly SOIL_USER='oils'
36 readonly SOIL_HOST='mb.oils.pub'
37 # Extra level
38 readonly SOIL_HOST_DIR=~/www/mb.oils.pub # used on server
39 readonly SOIL_REMOTE_DIR=www/mb.oils.pub # used on client
40 ;;
41 op)
42 readonly SOIL_USER='oils'
43 readonly SOIL_HOST='op.oils.pub'
44 readonly SOIL_HOST_DIR=~/op.oils.pub # used on server
45 readonly SOIL_REMOTE_DIR=op.oils.pub # used on client
46 ;;
47 *)
48 echo "Invalid Soil service $_soil_service" >& 2
49 exit 1
50 ;;
51esac
52
53readonly SOIL_USER_HOST="$SOIL_USER@$SOIL_HOST"
54
55readonly WWUP_URL="https://$SOIL_HOST/uuu/wwup.cgi"
56
57html-head() {
58 # TODO: Shebang line should change too
59 PYTHONPATH=. python3 doctools/html_head.py "$@"
60}
61
62# NOTE: soil-html-head and table-sort-html-head are distinct, because they
63# collide with <td> styling and so forth
64
65soil-html-head() {
66 local title="$1"
67 local web_base_url=${2:-'/web'}
68
69 html-head --title "$title" \
70 "$web_base_url/base.css?cache=0" "$web_base_url/soil.css?cache=0"
71}
72
73table-sort-html-head() {
74 local title="$1"
75 local web_base_url=${2:-'/web'}
76
77 html-head --title "$title" \
78 "$web_base_url/base.css?cache=0" \
79 "$web_base_url/ajax.js?cache=0" \
80 "$web_base_url/table/table-sort.css?cache=0" "$web_base_url/table/table-sort.js?cache=0"
81}
82
83git-commit-dir() {
84 local prefix=$1
85
86 # written by save-metadata in soil/worker.sh
87 local commit_hash
88 commit_hash=$(cat _tmp/soil/commit-hash.txt)
89
90 local git_commit_dir="$SOIL_REMOTE_DIR/code/${prefix}jobs/git-$commit_hash"
91
92 echo $git_commit_dir
93}
94
95git-commit-url() {
96 local prefix=$1
97
98 # written by save-metadata in soil/worker.sh
99 local commit_hash
100 commit_hash=$(cat _tmp/soil/commit-hash.txt)
101
102 # https:// not working on Github Actions because of cert issues?
103 local url="https://$SOIL_HOST/code/${prefix}jobs/git-$commit_hash"
104
105 echo $url
106}