initial code changes
This commit is contained in:
83
instance.sh
Normal file → Executable file
83
instance.sh
Normal file → Executable file
@@ -84,29 +84,20 @@ new_instance() {
|
||||
fi
|
||||
|
||||
if prompt_confirm "Ready to begin instance creation?"; then
|
||||
#CHANGE
|
||||
if [ -f /etc/octoprint_instances ]; then
|
||||
PORT=$(tail -1 /etc/octoprint_instances 2>/dev/null | sed -n -e 's/^.*\(port:\)\(.*\) udev:.*/\2/p')
|
||||
fi
|
||||
|
||||
if [ -z "$PORT" ]; then
|
||||
PORT=4999
|
||||
fi
|
||||
|
||||
PORT=$((PORT+1))
|
||||
PORT=5000
|
||||
PORTS_INUSE=$(join_by , $(cat /etc/octoprint_instances 2>/dev/null | sed -n -e 's/^.*\(port:\)\(.*\) udev:.*/\2/p'))
|
||||
until [[ "${PORTS_INUSE}" != *"${PORT}"* ]]; do ((PORT++)); done
|
||||
|
||||
echo Selected port is: $PORT
|
||||
#CHANGE
|
||||
OCTOUSER=$user
|
||||
OCTOPATH=$OCTOEXEC
|
||||
OCTOCONFIG="/home/$user"
|
||||
OCTOCONFIG="/opt/octoprint"
|
||||
|
||||
echo "Your new OctoPrint instance will be installed at ${cyan}/home/$user/.$INSTANCE${white}"
|
||||
echo "Your new OctoPrint instance will be installed at ${cyan}/opt/octoprint/$INSTANCE${white}"
|
||||
echo
|
||||
echo
|
||||
else
|
||||
if [ "$firstrun" == "true" ]; then
|
||||
echo "${red}You will need to restart your installation.${white}"
|
||||
echo "${red}Answer Y and re-run octoprint_deploy${white}"
|
||||
echo "${red}Answer Y and re-run octodocker_deploy${white}"
|
||||
remove_everything
|
||||
exit
|
||||
else
|
||||
@@ -115,7 +106,7 @@ new_instance() {
|
||||
fi
|
||||
|
||||
if [ -n "$TEMPLATE" ]; then
|
||||
BFOLD="/home/$user/.$TEMPLATE"
|
||||
BFOLD="/opt/octoprint/$INSTANCE$TEMPLATE"
|
||||
#check to make sure first run is complete
|
||||
if grep -q 'firstRun: true' $BFOLD/config.yaml; then
|
||||
echo "Template profile and admin user will have to be setup."
|
||||
@@ -148,14 +139,11 @@ new_instance() {
|
||||
|
||||
if prompt_confirm "Ready to write all changes. Do you want to proceed?"; then
|
||||
|
||||
sudo -u $user mkdir $OCTOCONFIG/.$INSTANCE
|
||||
mkdir $OCTOCONFIG/$INSTANCE
|
||||
|
||||
cat $SCRIPTDIR/octoprint_generic.service | \
|
||||
sed -e "s/OCTOUSER/$OCTOUSER/" \
|
||||
-e "s#OCTOPATH#$OCTOPATH#" \
|
||||
-e "s#OCTOCONFIG#$OCTOCONFIG#" \
|
||||
-e "s/NEWINSTANCE/$INSTANCE/" \
|
||||
-e "s/NEWPORT/$PORT/" > /etc/systemd/system/$INSTANCE.service
|
||||
cat $SCRIPTDIR/docker-compose.yml | \
|
||||
sed -e "s/NEWINSTANCE/$INSTANCE/" \
|
||||
-e "s/NEWPORT/$PORT/" > /opt/octoprint/docker-compose.yml
|
||||
|
||||
#write phase
|
||||
if [ -n "$UDEV" ] || [ -n "$USB" ]; then
|
||||
@@ -170,39 +158,37 @@ new_instance() {
|
||||
fi
|
||||
|
||||
if [ -n "$TEMPLATE" ]; then
|
||||
#There may be other combinations of things to include/exclude
|
||||
echo "${magenta}Copying template files....${white}"
|
||||
if [ $COPY -eq 1 ]; then
|
||||
sudo -u $user rsync -r \
|
||||
rsync -r \
|
||||
--exclude 'timelapse' \
|
||||
--exclude 'uploads' \
|
||||
--exclude 'logs' \
|
||||
$BFOLD/* $OCTOCONFIG/.$INSTANCE/
|
||||
$BFOLD/* $OCTOCONFIG/$INSTANCE/octoprint/
|
||||
fi
|
||||
if [ $COPY -eq 2 ]; then
|
||||
sudo -u $user rsync -r \
|
||||
rsync -r \
|
||||
--exclude 'timelapse' \
|
||||
--exclude 'logs' \
|
||||
$BFOLD/* $OCTOCONFIG/.$INSTANCE/
|
||||
$BFOLD/* $OCTOCONFIG/$INSTANCE/octoprint/
|
||||
fi
|
||||
echo "${magenta}Copying template files....${white}"
|
||||
#cp -rp $BFOLD/* $OCTOCONFIG/.$INSTANCE
|
||||
fi
|
||||
|
||||
#uniquify instances
|
||||
echo 'Uniquifying instance...'
|
||||
BASE=$OCTOCONFIG/.$INSTANCE
|
||||
sudo -u $user $OCTOEXEC --basedir $BASE config set appearance.name $INSTANCE
|
||||
sudo -u $user $OCTOEXEC --basedir $BASE config set server.commands.serverRestartCommand "sudo systemctl restart $INSTANCE"
|
||||
sudo -u $user $OCTOEXEC --basedir $BASE config set server.commands.systemRestartCommand "sudo reboot"
|
||||
sudo -u $user $OCTOEXEC --basedir $BASE config set plugins.discovery.upnpUuid $(uuidgen)
|
||||
sudo -u $user $OCTOEXEC --basedir $BASE config set plugins.errortracking.unique_id $(uuidgen)
|
||||
sudo -u $user $OCTOEXEC --basedir $BASE config set plugins.tracking.unique_id $(uuidgen)
|
||||
sudo -u $user $OCTOEXEC --basedir $BASE config set serial.port /dev/octo_$INSTANCE
|
||||
BASE=$OCTOCONFIG/$INSTANCE
|
||||
docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set appearance.name $INSTANCE
|
||||
docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set server.commands.serverRestartCommand "sudo systemctl restart $INSTANCE"
|
||||
docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set server.commands.systemRestartCommand "sudo reboot"
|
||||
docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set plugins.discovery.upnpUuid $(uuidgen)
|
||||
docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set plugins.errortracking.unique_id $(uuidgen)
|
||||
docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set plugins.tracking.unique_id $(uuidgen)
|
||||
docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set serial.port /dev/octo_$INSTANCE
|
||||
#clear additional ports
|
||||
sudo -u $user $OCTOEXEC --basedir $BASE config remove serial.additionalPorts
|
||||
sudo -u $user $OCTOEXEC --basedir $BASE config append_value serial.additionalPorts "/dev/octo_$INSTANCE"
|
||||
sudo -u $user $OCTOEXEC --basedir $BASE config set feature.modelSizeDetection false --bool
|
||||
sudo -u $user $OCTOEXEC --basedir $BASE config set webcam.ffmpeg /usr/bin/ffmpeg
|
||||
docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config remove serial.additionalPorts
|
||||
docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config append_value serial.additionalPorts "/dev/octo_$INSTANCE"
|
||||
docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set feature.modelSizeDetection false --bool
|
||||
docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set webcam.ffmpeg /usr/bin/ffmpeg
|
||||
|
||||
if [ "$HAPROXY" == true ]; then
|
||||
HAversion=$(haproxy -v | sed -n 's/^.*version \([0-9]\).*/\1/p')
|
||||
@@ -333,11 +319,10 @@ printer_udev() {
|
||||
|
||||
remove_instance() {
|
||||
opt=$1
|
||||
#disable and remove service file
|
||||
if [ -f /etc/systemd/system/$opt.service ]; then
|
||||
systemctl stop $opt.service
|
||||
systemctl disable $opt.service
|
||||
rm /etc/systemd/system/$opt.service 2>/dev/null
|
||||
#stop and remove docker
|
||||
if [ "$(docker ps -a | grep $opt)" ]; then
|
||||
docker stop $opt
|
||||
docker rm $opt
|
||||
fi
|
||||
|
||||
#Get all cameras associated with this instance.
|
||||
@@ -350,7 +335,7 @@ remove_instance() {
|
||||
#remove udev entry
|
||||
sed -i "/$opt/d" /etc/udev/rules.d/99-octoprint.rules
|
||||
#remove files
|
||||
rm -rf /home/$user/.$opt
|
||||
rm -rf /opt/octoprint/s$opt
|
||||
#remove from octoprint_instances
|
||||
sed -i "/$opt/d" /etc/octoprint_instances
|
||||
#remove haproxy entry
|
||||
|
||||
Reference in New Issue
Block a user