Skip to content

Commit 2664ef3

Browse files
committed
Updated the docker init-script to not re-install MySQL; it can cause more trouble than it might save; added a guard against trying to set up the ietf database if MySQL isn't running; and changed the final working directory to be the same as where the user invoked the 'docker/run' command. If not started via docker/run, drop into the home directory.
- Legacy-Id: 10461
1 parent bfc42ae commit 2664ef3

1 file changed

Lines changed: 31 additions & 21 deletions

File tree

docker/docker-init.sh

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22

33
echo "Gathering info ..."
44
MYSQLDIR="$(mysqld --verbose --help 2>/dev/null | awk '$1 == "datadir" { print $2; exit }')"
5+
if [ ! "$USER" ]; then
6+
echo "Environment variable USER is not set -- will set USER='django'."
7+
USER="django"
8+
fi
59

610
echo "Checking if MySQL base data exists ..."
711
if [ ! -d $MYSQLDIR/mysql ]; then
8-
echo "Re-installing MySQL ..."
9-
apt-get update && apt-get install --reinstall mysql-server
12+
echo "WARNING: Expected the directory $MYSQLDIR/mysql/ to exist -- have you downloaded and unpacked the IETF binary database tarball?"
1013
fi
1114

12-
1315
echo "Checking if MySQL is running ..."
1416
if ! /etc/init.d/mysql status; then
1517
echo "Starting mysql ..."
@@ -18,25 +20,32 @@ fi
1820

1921
echo "Checking if the IETF database exists at $MYSQLDIR ..."
2022
if [ ! -d $MYSQLDIR/ietf_utf8 ]; then
23+
if [ -z "$DATADIR" ]; then
24+
echo "DATADIR is not set, but the IETF database needs to be set up -- can't continue, exiting the docker init script."
25+
exit 1
26+
fi
2127
ls -l $MYSQLDIR
2228

23-
echo "Creating database ..."
24-
mysqladmin -u root --default-character-set=utf8 create ietf_utf8
25-
26-
echo "Setting up permissions ..."
27-
mysql -u root ietf_utf8 <<< "GRANT ALL PRIVILEGES ON ietf_utf8.* TO django@localhost IDENTIFIED BY 'RkTkDPFnKpko'; FLUSH PRIVILEGES;"
28-
29-
echo "Fetching database ..."
30-
DUMPDIR=/home/$USER/$DATADIR
31-
wget -N -P $DUMPDIR http://www.ietf.org/lib/dt/sprint/ietf_utf8.sql.gz
32-
33-
echo "Loading database ..."
34-
gunzip < $DUMPDIR/ietf_utf8.sql.gz \
35-
| pv --progress --bytes --rate --eta --cursor --size $(gzip --list --quiet $DUMPDIR/ietf_utf8.sql.gz | awk '{ print $2 }') \
36-
| sed -e 's/ENGINE=MyISAM/ENGINE=InnoDB/' \
37-
| mysql --user=django --password=RkTkDPFnKpko -s -f ietf_utf8 \
38-
&& rm /tmp/ietf_utf8.sql.gz
39-
29+
if ! /etc/init.d/mysql status; then
30+
echo "Didn't find the IETF database, but can't set it up either, as MySQL isn't running."
31+
else
32+
echo "Creating database ..."
33+
mysqladmin -u root --default-character-set=utf8 create ietf_utf8
34+
35+
echo "Setting up permissions ..."
36+
mysql -u root ietf_utf8 <<< "GRANT ALL PRIVILEGES ON ietf_utf8.* TO django@localhost IDENTIFIED BY 'RkTkDPFnKpko'; FLUSH PRIVILEGES;"
37+
38+
echo "Fetching database ..."
39+
DUMPDIR=/home/$USER/$DATADIR
40+
wget -N -P $DUMPDIR http://www.ietf.org/lib/dt/sprint/ietf_utf8.sql.gz
41+
42+
echo "Loading database ..."
43+
gunzip < $DUMPDIR/ietf_utf8.sql.gz \
44+
| pv --progress --bytes --rate --eta --cursor --size $(gzip --list --quiet $DUMPDIR/ietf_utf8.sql.gz | awk '{ print $2 }') \
45+
| sed -e 's/ENGINE=MyISAM/ENGINE=InnoDB/' \
46+
| mysql --user=django --password=RkTkDPFnKpko -s -f ietf_utf8 \
47+
&& rm /tmp/ietf_utf8.sql.gz
48+
fi
4049
fi
4150

4251
if ! id -u "$USER" &> /dev/null; then
@@ -68,7 +77,8 @@ if [ ! -f /opt/home/$USER/datatracker/lib/site-python/settings_local.py ]; then
6877
fi
6978

7079
chown -R $USER /opt/home/$USER
71-
cd /home/$USER
80+
cd /home/$USER/
81+
cd /home/$USER/$CWD
7282

7383
echo "Done!"
7484

0 commit comments

Comments
 (0)