File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 5151 " update" )
5252 report_info " cuos:update:start" " Update process was triggered"
5353 CONFIG=" $( echo " ${INPUT} " | jq -c ' .config // {}' ) "
54+ if ! echo " ${CONFIG} " | check_config; then
55+ report_err " cuos:update:err_invalid_config" " Update: Invalid configuration provided."
56+ echo " Invalid configuration provided."
57+ exit 0
58+ fi
5459
5560 # update and swap configuration (config -> new)
5661 NEW_CONFIG=" $( echo " ${CONFIG} " | jq -s ' .[0] * .[1]' " ${CONFIG_PATH} " -) " || exit 0
8186 " patch" )
8287 report_info " cuos:patch" " Patching the system"
8388 CONFIG=" $( echo " ${INPUT} " | jq -c ' .config // empty' ) "
89+ if ! echo " ${CONFIG} " | check_config; then
90+ report_err " cuos:update:err_invalid_config" " Update: Invalid configuration provided."
91+ echo " Invalid configuration provided."
92+ exit 0
93+ fi
8494 # save current config for rollback:
8595 cat " ${CONFIG_PATH} " > " ${NEXT_CONFIG_PATH} "
8696
Original file line number Diff line number Diff line change @@ -131,18 +131,18 @@ if ! docker ps --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}\$"; then
131131 DOCKER_ARGS=" $( docker inspect --format ' {{ index .Config.Labels "dev.cuos.app_command" }}' " ${INITIAL_IMAGE} " ) "
132132 if [[ -z " ${DOCKER_ARGS} " ]]; then
133133 DOCKER_ARGS=" \
134- --device /dev/tty1 \
134+ --device /dev/tty1 \
135135 --network=host \
136- --volume /var/run/docker.sock:/var/run/docker.sock \
136+ --volume /var/run/docker.sock:/var/run/docker.sock \
137137 --volume /root/.docker/config.json:/root/.docker/config.json:ro \
138138 --volume /system.json:/system.json:ro \
139139 --volume /etc/partition_mode:/etc/partition_mode:ro \
140140 --volume /var/run/cuos.sock:/var/run/cuos.sock \
141141 --volume /usr/local/share/ca-certificates/custom:/usr/local/share/ca-certificates/custom:ro"
142- fi
142+ fi
143143
144144 touch " ${HOME} /.docker/config.json"
145- # shellcheck disable=SC2086
145+ # shellcheck disable=SC2086
146146 docker run \
147147 --detach \
148148 --pull=never \
Original file line number Diff line number Diff line change @@ -252,6 +252,8 @@ expert() {
252252 term_all sudo -u nobody rvim /tmp/edit-system.json
253253 if ! jq . /tmp/edit-system.json > /dev/null 2>&1 ; then
254254 term msg " Invalid JSON"
255+ elif ! cat /tmp/edit-system.json | check_config; then
256+ term msg " Invalid Configuration"
255257 else
256258 cat /tmp/edit-system.json > /system.json
257259 api_stream " Applying system.json" cuos patch
Original file line number Diff line number Diff line change @@ -71,7 +71,6 @@ ensure_system_config() {
7171}
7272
7373check_schema_system_json () {
74- # TODO: Check system.json against JSON schema for security
7574 jv " ${SCRIPT_DIR} /system-schema.json" " /system.json"
7675}
7776
@@ -102,11 +101,15 @@ set_hostname() {
102101 --arg hn " ${SYSTEM_HOSTNAME} " \
103102 ' .hostname = $hn' \
104103 " ${CONFIG_PATH} "
105- fi
106- if [[ -n " ${SYSTEM_HOSTNAME} " ]]; then
104+ elif [[ -n " ${SYSTEM_HOSTNAME} " ]]; then
107105 echo " Setting hostname to $SYSTEM_HOSTNAME "
108106 echo " $SYSTEM_HOSTNAME " > " /etc/hostname"
109107 hostname " $SYSTEM_HOSTNAME "
108+ elif [[ -n " ${OLD_HOSTNAME} " ]]; then
109+ jq_replace \
110+ --arg hn " ${OLD_HOSTNAME} " \
111+ ' .hostname = $hn' \
112+ " ${CONFIG_PATH} "
110113 fi
111114 if [[ -n " ${REINIT:- } " && " ${OLD_HOSTNAME} " != " ${SYSTEM_HOSTNAME} " ]]; then
112115 systemctl restart networking
Original file line number Diff line number Diff line change @@ -117,3 +117,7 @@ state() {
117117 " ${state_file} " ) " || return " $? "
118118 echo " ${new_state} " > " ${state_file} "
119119}
120+
121+ check_config () {
122+ jv " ${SCRIPT_DIR} /system-schema.json" " /dev/stdin"
123+ }
You can’t perform that action at this time.
0 commit comments