OILS / soil / common.sh View on Github | oils.pub

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