You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
117 lines
3.0 KiB
117 lines
3.0 KiB
#!/bin/bash
|
|
|
|
CURDIR=$PWD
|
|
REQUIRED_PKGS=(file git bc)
|
|
|
|
function usage() {
|
|
echo 'usage: --host | --containers | --full | --one-container <CT_NAME>'
|
|
exit 1
|
|
}
|
|
|
|
function install_host() {
|
|
echo "install on: $HOSTNAME"
|
|
echo ----------------------
|
|
|
|
[ "$(id -u)" -ne 0 ] && echo 'root privilege required' && exit 1
|
|
|
|
if [[ ! $CURDIR == '/opt/debian-bash' ]]; then
|
|
# download and fullfill /opt/debian-bash, then run it from folder
|
|
|
|
if [[ -L /opt/debian-bash ]]; then
|
|
cd /opt/debian-bash && ./install.sh "$PARAM1"
|
|
exit 0
|
|
else
|
|
|
|
rm -rf /opt/debian-bash
|
|
TEMP=$(mktemp -d)
|
|
cd "$TEMP" || return
|
|
echo "$TEMP"
|
|
wget https://git.artcode.re/pvincent/debian-bash/archive/master.tar.gz
|
|
tar -xzf master.tar.gz
|
|
mv debian-bash /opt/
|
|
cd /opt/debian-bash || return
|
|
./install.sh "$PARAM1"
|
|
rm -rf "$TEMP"
|
|
exit 0
|
|
fi
|
|
|
|
else
|
|
echo "--------------------------------"
|
|
echo "debian-bash has been deprecated!"
|
|
echo "--------------------------------"
|
|
|
|
if [[ -z "$PS1" ]]; then
|
|
echo "--------------------------------------------------"
|
|
echo "automatic migration from debian-bash to miaou-bash"
|
|
echo "--------------------------------------------------"
|
|
answer='y'
|
|
else
|
|
read -rn1 -p 'Would you like to migrate to the new project named `miaou-bash`, (yN)?' answer
|
|
fi
|
|
|
|
if [[ "$answer" == 'y' ]];then
|
|
pushd /tmp
|
|
pushd /opt/debian-bash
|
|
./uninstall.sh
|
|
popd
|
|
rm -rf /opt/debian-bash
|
|
curl https://git.artcode.re/miaou/miaou-bash/raw/branch/main/install.sh | sudo bash -s
|
|
source /etc/bash.bashrc
|
|
exit 0
|
|
fi
|
|
echo "cancelled!"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
function install_containers() {
|
|
echo "install containers"
|
|
echo --------------------
|
|
|
|
# install inside active LXC containers
|
|
if [[ -f '/snap/bin/lxc' ]]; then
|
|
for container in $(/snap/bin/lxc list --format=json | yq '.[] | select(.state.status == "Running") | .name' -); do
|
|
install_one_container "$container"
|
|
echo
|
|
done
|
|
fi
|
|
|
|
}
|
|
|
|
function install_one_container() {
|
|
CT=$1
|
|
echo "install container <$CT>"
|
|
echo -------------------------
|
|
# install inside one active LXC container
|
|
if [[ -f '/snap/bin/lxc' ]]; then
|
|
echo "pushed to $CT"
|
|
/snap/bin/lxc file push /opt/debian-bash "${CT}/opt/" -r
|
|
/snap/bin/lxc exec "$CT" -- sh -c "cd /opt/debian-bash && ./install.sh --host"
|
|
fi
|
|
}
|
|
|
|
PARAM1=$1
|
|
|
|
case $PARAM1 in
|
|
"--host")
|
|
install_host
|
|
;;
|
|
"--containers")
|
|
install_containers
|
|
;;
|
|
"--one-container")
|
|
CT=$2
|
|
if [ ! -z "$CT" ]; then
|
|
install_one_container "$CT"
|
|
else
|
|
usage
|
|
fi
|
|
;;
|
|
"--full")
|
|
install_host
|
|
install_containers
|
|
;;
|
|
*)
|
|
usage
|
|
;;
|
|
esac
|