2016-03-22 17:28:56 +02:00
|
|
|
#!/gns3/bin/busybox sh
|
2016-03-01 19:38:03 +02:00
|
|
|
#
|
|
|
|
# Copyright (C) 2016 GNS3 Technologies Inc.
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
#
|
|
|
|
# This script is injected into the container and launch before
|
2016-05-18 12:23:45 +03:00
|
|
|
# the start command of the container
|
2016-03-01 19:38:03 +02:00
|
|
|
#
|
2016-03-22 17:28:56 +02:00
|
|
|
OLD_PATH="$PATH"
|
2018-10-06 18:06:24 +03:00
|
|
|
PATH=/gns3/bin:/tmp/gns3/bin:/sbin
|
2016-03-22 17:28:56 +02:00
|
|
|
|
|
|
|
# bootstrap busybox commands
|
|
|
|
if [ ! -d /tmp/gns3/bin ]; then
|
2016-06-07 10:26:27 +03:00
|
|
|
busybox mkdir -p /tmp/gns3/bin
|
|
|
|
/gns3/bin/busybox --install -s /tmp/gns3/bin
|
2016-03-22 17:28:56 +02:00
|
|
|
fi
|
2016-03-01 19:38:03 +02:00
|
|
|
|
2016-06-06 13:39:29 +03:00
|
|
|
# Restore file permission and mount volumes
|
2016-06-07 10:27:37 +03:00
|
|
|
echo "$GNS3_VOLUMES" | tr ":" "\n" | while read i
|
2016-06-01 19:16:56 +03:00
|
|
|
do
|
2017-07-02 12:10:25 +03:00
|
|
|
# ensure, that the mount directory exists
|
|
|
|
mkdir -p "$i"
|
|
|
|
|
2016-06-06 13:39:29 +03:00
|
|
|
# Copy original files if destination is empty (first start)
|
2017-12-17 23:35:26 +02:00
|
|
|
if [ ! -f "/gns3volumes$i/.gns3_perms" ]; then
|
|
|
|
cp -a "$i/." "/gns3volumes$i"
|
|
|
|
touch "/gns3volumes$i/.gns3_perms"
|
|
|
|
fi
|
2016-06-06 13:39:29 +03:00
|
|
|
|
|
|
|
mount --bind "/gns3volumes$i" "$i"
|
2017-12-17 23:35:26 +02:00
|
|
|
while IFS=: read PERMS OWNER GROUP FILE
|
|
|
|
do
|
|
|
|
[ -L "$FILE" ] || chmod "$PERMS" "$FILE"
|
|
|
|
chown -h "${OWNER}:${GROUP}" "$FILE"
|
|
|
|
done < "$i/.gns3_perms"
|
2016-06-01 19:16:56 +03:00
|
|
|
done
|
|
|
|
|
|
|
|
|
2016-03-01 19:38:03 +02:00
|
|
|
# /etc/hosts
|
|
|
|
[ -s /etc/hosts ] || cat > /etc/hosts << __EOF__
|
2016-06-07 10:26:27 +03:00
|
|
|
127.0.1.1 $HOSTNAME
|
|
|
|
127.0.0.1 localhost
|
|
|
|
::1 localhost ip6-localhost ip6-loopback
|
|
|
|
fe00::0 ip6-localnet
|
|
|
|
ff00::0 ip6-mcastprefix
|
|
|
|
ff02::1 ip6-allnodes
|
|
|
|
ff02::2 ip6-allrouters
|
2016-03-01 19:38:03 +02:00
|
|
|
__EOF__
|
|
|
|
|
2018-04-27 15:33:07 +03:00
|
|
|
# imitate docker's `ExtraHosts` behaviour
|
|
|
|
sed -i '/GNS3_EXTRA_HOSTS_START/,/GNS3_EXTRA_HOSTS_END/d' /etc/hosts
|
|
|
|
[ -n "$GNS3_EXTRA_HOSTS" ] && cat >> /etc/hosts << __EOF__
|
|
|
|
# GNS3_EXTRA_HOSTS_START
|
|
|
|
$GNS3_EXTRA_HOSTS
|
|
|
|
# GNS3_EXTRA_HOSTS_END
|
|
|
|
__EOF__
|
|
|
|
|
2016-03-01 19:38:03 +02:00
|
|
|
# configure loopback interface
|
|
|
|
ip link set dev lo up
|
|
|
|
|
2016-05-06 20:07:18 +03:00
|
|
|
# Wait for all eth available
|
2016-06-07 10:26:27 +03:00
|
|
|
while true
|
2016-05-06 20:07:18 +03:00
|
|
|
do
|
|
|
|
grep $GNS3_MAX_ETHERNET /proc/net/dev > /dev/null && break
|
|
|
|
sleep 0.5
|
2016-06-07 10:26:27 +03:00
|
|
|
done
|
2016-05-06 20:07:18 +03:00
|
|
|
|
2016-03-30 11:29:10 +03:00
|
|
|
# activate eth interfaces
|
2016-03-01 19:38:03 +02:00
|
|
|
sed -n 's/^ *\(eth[0-9]*\):.*/\1/p' < /proc/net/dev | while read dev; do
|
2016-06-07 10:26:27 +03:00
|
|
|
ip link set dev $dev up
|
2016-03-01 19:38:03 +02:00
|
|
|
done
|
|
|
|
|
2016-03-30 11:29:10 +03:00
|
|
|
# configure network interfaces
|
2016-03-24 18:08:16 +02:00
|
|
|
ifup -a -f
|
2016-03-22 17:28:56 +02:00
|
|
|
|
2016-03-01 19:38:03 +02:00
|
|
|
# continue normal docker startup
|
2020-03-19 09:20:27 +02:00
|
|
|
eval HOME=$(echo ~${GNS3_USER-root})
|
|
|
|
exec su ${GNS3_USER-root} -p -- /gns3/run-cmd.sh "$OLD_PATH" "$@"
|