Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mk0ZT-0002lo-Kh for pgsql-www@arkaria.postgresql.org; Mon, 08 Nov 2021 09:04:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mk0ZS-00053I-JL for pgsql-www@arkaria.postgresql.org; Mon, 08 Nov 2021 09:04:06 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mk0ZS-000539-7N for pgsql-www@lists.postgresql.org; Mon, 08 Nov 2021 09:04:06 +0000 Received: from mail-lf1-x12b.google.com ([2a00:1450:4864:20::12b]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mk0ZP-0007NR-4b for pgsql-www@lists.postgresql.org; Mon, 08 Nov 2021 09:04:05 +0000 Received: by mail-lf1-x12b.google.com with SMTP id u11so34564235lfs.1 for ; Mon, 08 Nov 2021 01:04:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hagander-net.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=2ypp+PjC0xBuk6UudFh6H6BF6j8XmwPEHEs14IXErX4=; b=jc54ba8oRWlMwMCuIERp9cj93aeJtSqtFyLM8lW7PTFf8JnxSdFnd4s47RvakbSGY7 pgH7rRQx7MbeptsDb7HsbCHadHY6SqDjrXwqoYLfHB0SuRJ4aZ3URJFlGEyhPS0foAKJ 2Md/3YUh/drCPzlWisgocAjg4EqOBrhIgqg4TupHsM7xmE7zR9yLg9H8Qp4L+vFcTdRy AGGg37GHupzqXfPLc+ERj20NDZE8WuMvT2uFLQOCh0REcYueo+TBJlf2dq3OaGJHFanF bgsvUDLJUjrQNbuFi8AyZH+gB6qnojjqRIJwPNNT/ztfLJbg6je5ro5ptjITLiIUjEIV 94vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=2ypp+PjC0xBuk6UudFh6H6BF6j8XmwPEHEs14IXErX4=; b=AnR5v+ZiXuuATixv82HzuldTF3rC5LvgXwxvtCzIEh/FZKMo2pUE1vePhOca7rfzFU HkvZdXN+xIqwbvqv1MzhxU4nSPSyOKTy8HsGtqZfiQfiv94sRNKVD4w47jn/iyqqi+0q 5IGV+A9ovuwSNCEC8s1FMfCKL4L0VIhCFX2gl0dcIX07SPP4hNgJnzg+g3uVylTZbIuZ mdJ2sArEdc8PNHBF7cmd7bWCuDKVpbTP1eEe1q3MT2qhnPHzkK9WX4iV8jpeKPTybHrG JlQYVacuC1dfWNMyDAx+eWuv8NDdbU5encAsoYu2h51FAxDs4RwuIsLUsFvLw+0tO/dE ODeg== X-Gm-Message-State: AOAM531d2koigP/R/8sUPuFsbk5PKKe58gTyGwsfhxc7s/RpTTvR3iOe TV84aAFo8jwhtN9MnT02RDwId2/+mZZ0588TEa+vpA== X-Google-Smtp-Source: ABdhPJyCPbDZtChMxTDMzOqdVoxlFf8zCxGXZRQR7TVPkTg17d1/FSDV3FhY1lAub93i7LnBRfJEDgUoA4BZGka6wx8= X-Received: by 2002:a19:7419:: with SMTP id v25mr15557778lfe.159.1636362241642; Mon, 08 Nov 2021 01:04:01 -0800 (PST) MIME-Version: 1.0 References: <20211107164951.wxcyp7iar2s4mjkn@nixos> In-Reply-To: <20211107164951.wxcyp7iar2s4mjkn@nixos> From: Magnus Hagander Date: Mon, 8 Nov 2021 10:03:50 +0100 Message-ID: Subject: Re: [PATCH] Improve portability of pgweb/load_initial_data.sh To: Nils Cc: pgsql-www@lists.postgresql.org Content-Type: multipart/alternative; boundary="00000000000023229905d04346ce" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000023229905d04346ce Content-Type: text/plain; charset="UTF-8" Hi! Yeah, I think the fact that it says bash is just a "knee-jerk default" and not that it ever did either. So I have no problem changing that to sh. I'm a bit curious though, as to in which scenario this actually causes a problem? The second change I'm less sure about. There are many different things you could change to break a script. This is one of them. You could change PATH, or you could replace "find" or "xargs" with commands that don't work the same way. CDPATH is not a variable that should, I believe, ever be exported into non-interactive scripts in the first place. //Magnus On Sun, Nov 7, 2021 at 5:49 PM Nils wrote: > The shell script doesn't use bash extensions and bash may not be > available on all systems at that location. > > If CDPATH is set, in certain cases, the call to cd can result in > unwanted behaviour. > --- > pgweb/load_initial_data.sh | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/pgweb/load_initial_data.sh b/pgweb/load_initial_data.sh > index fb16e70c..c419f298 100755 > --- a/pgweb/load_initial_data.sh > +++ b/pgweb/load_initial_data.sh > @@ -1,4 +1,4 @@ > -#!/bin/bash > +#!/bin/sh > > # We keep this in a separate script because using initial_data.xxx in > django will overwrite > # critical data in the database when running a 'syncdb'. We'd like to > keep the ability to > @@ -8,7 +8,7 @@ echo WARNING: this may overwrite some data in the database > with an initial set o > echo 'Are you sure you want this (answer "yes" to overwrite)' > read R > > -cd $(dirname $0) > +CDPATH= cd $(dirname $0) > > if [ "$R" == "yes" ]; then > find . -name data.json | xargs ../manage.py loaddata > -- > 2.31.1 > > > > -- Magnus Hagander Me: https://www.hagander.net/ Work: https://www.redpill-linpro.com/ --00000000000023229905d04346ce Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi!

Yeah, I think the fact t= hat it says bash is just a "knee-jerk default" and not that it ev= er did either. So I have no problem changing that to sh. I'm a bit curi= ous though, as to in which scenario this actually causes a problem?

The second change I'm less sure about. There are many= different things you could change to break a script. This is one of them. = You could change PATH, or you could replace "find" or "xargs= " with commands that don't work the same way. CDPATH is not a vari= able that should, I believe, ever be exported into non-interactive scripts = in the first place.

//Magnus

On Sun, Nov 7, 2021 = at 5:49 PM Nils <nils@nilsand.re&= gt; wrote:
The s= hell script doesn't use bash extensions and bash may not be
available on all systems at that location.

If CDPATH is set, in certain cases, the call to cd can result in
unwanted behaviour.
---
=C2=A0pgweb/load_initial_data.sh | 4 ++--
=C2=A01 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/pgweb/load_initial_data.sh b/pgweb/load_initial_data.sh
index fb16e70c..c419f298 100755
--- a/pgweb/load_initial_data.sh
+++ b/pgweb/load_initial_data.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh

=C2=A0# We keep this in a separate script because using initial_data.xxx in= django will overwrite
=C2=A0# critical data in the database when running a 'syncdb'. We&#= 39;d like to keep the ability to
@@ -8,7 +8,7 @@ echo WARNING: this may overwrite some data in the database = with an initial set o
=C2=A0echo 'Are you sure you want this (answer "yes" to overw= rite)'
=C2=A0read R

-cd $(dirname $0)
+CDPATH=3D cd $(dirname $0)

=C2=A0if [ "$R" =3D=3D "yes" ]; then
=C2=A0 =C2=A0 find . -name data.json | xargs ../manage.py loaddata
--
2.31.1





--
=C2=A0Magnus Hagander
= =C2=A0Me: https://ww= w.hagander.net/
=C2=A0Work: https://www.redpill-linpro.com/
<= /div> --00000000000023229905d04346ce--