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

107 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=op
25#_soil_service=mb
26#_soil_service=dh
27
28case $_soil_service in
29 dh)
30 readonly SOIL_USER='travis_admin'
31 readonly SOIL_HOST='ci.oilshell.org'
32 readonly SOIL_HOST_DIR=~/ci.oilshell.org # used on server
33 readonly SOIL_REMOTE_DIR=ci.oilshell.org # used on client
34 ;;
35 mb)
36 readonly SOIL_USER='oils'
37 readonly SOIL_HOST='mb.oilshell.org'
38 # Extra level
39 readonly SOIL_HOST_DIR=~/www/mb.oilshell.org # used on server
40 readonly SOIL_REMOTE_DIR=www/mb.oilshell.org # used on client
41 ;;
42 op)
43 readonly SOIL_USER='oils'
44 readonly SOIL_HOST='op.oilshell.org'
45 readonly SOIL_HOST_DIR=~/op.oilshell.org # used on server
46 readonly SOIL_REMOTE_DIR=op.oilshell.org # used on client
47 ;;
48 *)
49 echo "Invalid Soil service $_soil_service" >& 2
50 exit 1
51 ;;
52esac
53
54readonly SOIL_USER_HOST="$SOIL_USER@$SOIL_HOST"
55
56readonly WWUP_URL="https://$SOIL_HOST/uuu/wwup.cgi"
57
58html-head() {
59 # TODO: Shebang line should change too
60 PYTHONPATH=. python3 doctools/html_head.py "$@"
61}
62
63# NOTE: soil-html-head and table-sort-html-head are distinct, because they
64# collide with <td> styling and so forth
65
66soil-html-head() {
67 local title=$1
68 local web_base_url=$2
69
70 html-head --title "$title" \
71 "$web_base_url/base.css?cache=0" "$web_base_url/soil.css?cache=0"
72}
73
74table-sort-html-head() {
75 local title="$1"
76 local web_base_url=${2:-'/web'}
77
78 html-head --title "$title" \
79 "$web_base_url/base.css?cache=0" \
80 "$web_base_url/ajax.js?cache=0" \
81 "$web_base_url/table/table-sort.css?cache=0" "$web_base_url/table/table-sort.js?cache=0"
82}
83
84git-commit-dir() {
85 local prefix=$1
86
87 # written by save-metadata in soil/worker.sh
88 local commit_hash
89 commit_hash=$(cat _tmp/soil/commit-hash.txt)
90
91 local git_commit_dir="$SOIL_REMOTE_DIR/code/${prefix}jobs/git-$commit_hash"
92
93 echo $git_commit_dir
94}
95
96git-commit-url() {
97 local prefix=$1
98
99 # written by save-metadata in soil/worker.sh
100 local commit_hash
101 commit_hash=$(cat _tmp/soil/commit-hash.txt)
102
103 # https:// not working on Github Actions because of cert issues?
104 local url="https://$SOIL_HOST/code/${prefix}jobs/git-$commit_hash"
105
106 echo $url
107}