Skip to content

Commit 1061f5f

Browse files
committed
Better persistance via setting Env variables
Better help for dmathicsscript and dmathicssserver Fix bug in term-background Revise symja example in mathics.sqlite
1 parent f2edf49 commit 1061f5f

File tree

4 files changed

+110
-20
lines changed

4 files changed

+110
-20
lines changed

docker/django-db/mathics.sqlite

0 Bytes
Binary file not shown.

script/dmathicsscript

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,75 @@ if [ -n "$DEBUG" ]; then
44
set -x
55
fi
66

7+
# The release name we are configured to run under.
8+
typeset dmathicsserver_version='1.0.0'
9+
710
# Allow customization using POSIX environment variables:
811
APP_DATADIR=${APP_DATADIR:-/tmp}
912
DOCKER=${DOCKER:-docker}
1013
TAG=${TAG:-latest}
1114

15+
XAUTH=${XAUTH:-$HOME/.Xauthority}
16+
touch $XAUTH
17+
18+
DEVICE=''
19+
if [[ -r /dev/dri ]]; then
20+
DEVICE='--device=/dev/dri:/dev/dri'
21+
fi
22+
23+
CONFIGDIR=${CONFIGDIR:-$HOME/.config/mathicsscript/}
24+
25+
1226
# TODO: allow setting:
13-
# XDG_CONFIG_HOME \
14-
# CONFIG_HOME \
15-
# CONFIGDIR \
1627
# MATHICSSCRIPT_HISTSIZE \
17-
# MATHICSSCRIPT_HISTFILE \
1828

1929
MATHICS_IMAGE=${MATHICS_IMAGE:-mathicsorg/mathics:${TAG}}
2030

21-
for arg in $@ ; do
31+
typeset -a stripped_args
32+
stripped_args=()
33+
34+
for arg in "$@" ; do
2235
case "$arg" in
36+
-h | --help | help )
37+
cat <<_EOH
38+
Usage: mathicsscript [OPTIONS] [FILE]
39+
40+
A command-line interface to Mathics run in a docker container
41+
42+
Options specfic to dmathicsserver:
43+
44+
-u | -U | --upgrade | upgrade
45+
Pull updates to the docker container if there is a new image.
46+
47+
-h| --help | help
48+
Show this help.
49+
50+
--dversion
51+
Show the dmathicsscript version and exit.
52+
53+
Useful Environment Variables:
54+
55+
APP_DATADIR: where application data should be saved. The default is: ${APP_DATADIR}
56+
DOCKER: the name of the docker program to run. The default is: ${DOCKER}
57+
CONFIGDIR: directory where Mathics command history is saved. The default is: ${CONFIGDIR}
58+
MATHICS_IMAGE: Mathics image to use. The default is: ${MATHICS_IMAGE}
59+
TAG: tag used in MATHICS_IMAGE above. The default is: ${TAG}
60+
XAUTH: .Xauthority file. The default is: ${XAUTH}
61+
62+
We will now pass help along to the docker image. Just a sec...
63+
64+
_EOH
65+
stripped_args+=("--help")
66+
;;
2367
-u | -U | --upgrade | upgrade)
2468
$DOCKER pull $MATHICS_IMAGE
25-
exit $?
26-
;;
69+
;;
70+
--dversion)
71+
echo "dmathicsserver version ${dmathicsserver_version}"
72+
exit 100
73+
;;
74+
default)
75+
stripped_args+=($arg)
2776
esac
2877
done
2978

@@ -41,13 +90,10 @@ else
4190
style="--style colorful"
4291
fi
4392

44-
XAUTH=${XAUTH:-$HOME/.Xauthority}
45-
touch $XAUTH
46-
47-
DEVICE=''
48-
if [[ -r /dev/dri ]]; then
49-
DEVICE='--device=/dev/dri:/dev/dri'
50-
fi
93+
# Show environment variables
94+
for env_setting in CONFIGDIR APP_DATADIR MATHICS_IMAGE DISPLAY; do
95+
echo $env_setting = ${!env_setting}
96+
done
5197

5298
$DOCKER run \
5399
--rm \
@@ -58,6 +104,7 @@ $DOCKER run \
58104
--network=host \
59105
--volume="$PWD":/app \
60106
--volume "${APP_DATADIR}:/usr/src/app/data" \
107+
--volume "${CONFIGDIR}:/usr/src/app/.config/mathicsscript" \
61108
$DEVICE \
62109
$MATHICS_IMAGE \
63-
--mode cli -- $style $@
110+
--mode cli -- $style $stripped_args

script/dmathicsserver

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ if [ -n "$DEBUG" ]; then
44
set -x
55
fi
66

7+
# The release name we are configured to run under.
8+
typeset dmathicsserver_version='1.0.0'
9+
710
# Allow customization using POSIX environment variables:
811
APP_DATADIR=${APP_DATADIR:-/tmp}
912
DOCKER=${DOCKER:-docker}
@@ -13,15 +16,51 @@ TAG=${TAG:-latest}
1316

1417
MATHICS_IMAGE=${MATHICS_IMAGE:-mathicsorg/mathics:${TAG}}
1518

19+
typeset -a stripped_args
20+
stripped_args=()
21+
1622
for arg in "$@" ; do
1723
case "$arg" in
24+
-h | --help | help )
25+
cat <<_EOH
26+
usage:
27+
dmathicsserver [options]
28+
29+
runs the Mathics command-line interface from a docker container.
30+
31+
Options specfic to dmathicsserver:
32+
33+
-u | -U | --upgrade | upgrade
34+
pull updates to the docker container if there is a new image
35+
36+
-h| --help | help
37+
show this help
38+
39+
-V| --version
40+
show the dmathicsscript version and exit
41+
42+
We will now pass help along to the docker image. Just a sec...
43+
44+
_EOH
45+
stripped_args+=("--help")
46+
;;
1847
-u | -U | --upgrade | upgrade)
1948
$DOCKER pull $MATHICS_IMAGE
20-
exit $?
21-
;;
49+
;;
50+
-v | -V | --version)
51+
echo "dmathicsserver version ${dmathicsserver_version}"
52+
exit 100
53+
;;
54+
default)
55+
stripped_args+=($arg)
2256
esac
2357
done
2458

59+
# Show environment variables
60+
for env_setting in MATHICS_DJANGO_DB_PATH APP_DATADIR MATHICS_IMAGE DISPLAY; do
61+
echo $env_setting = ${!env_setting}
62+
done
63+
2564
$DOCKER run \
2665
-it \
2766
--name mathics-django \
@@ -34,4 +73,4 @@ $DOCKER run \
3473
--volume="${APP_DATADIR}:/usr/src/app/data" \
3574
-p 8000:8000 \
3675
$MATHICS_IMAGE \
37-
--mode ui -- $@
76+
--mode ui -- $stripped_args

script/term-background.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,15 @@ if is_sourced; then
262262
if ((is_dark_bg == 1)); then
263263
export DARK_BG=1 # deprecated
264264
export LC_DARK_BG=1
265-
[[ -z $COLORFGBG ]] && export COLORFGBG='0;15'
265+
if [[ -z "$COLORFGBG" ]]; then
266+
export COLORFGBG='0;15'
267+
fi
266268
else
267269
export DARK_BG=0
268270
export LC_DARK_BG=0
269-
[[ -z $COLORFGBG ]] && export COLORFGBG='15;0'
271+
if [[ -z "$COLORFGBG" ]] ; then
272+
export COLORFGBG='15;0'
273+
fi
270274
fi
271275
fi
272276
else

0 commit comments

Comments
 (0)