mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 03:16:10 -06:00 
			
		
		
		
	allow to set email and password as lxc-install.sh parameter
This commit is contained in:
		@@ -6,39 +6,96 @@
 | 
				
			|||||||
# Will set-up paperless, apache2 and proftpd
 | 
					# Will set-up paperless, apache2 and proftpd
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
# lxc launch ubuntu: paperless
 | 
					# lxc launch ubuntu: paperless
 | 
				
			||||||
# lxc exec paperless -- sh -c "wget https://raw.githubusercontent.com/maur/paperless/master/docs/examples/lxc/lxc-install.sh && /bin/bash lxc-install.sh"
 | 
					# lxc exec paperless -- sh -c "sudo apt-get update && sudo apt-get install -y wget"
 | 
				
			||||||
 | 
					# lxc exec paperless -- sh -c "wget https://raw.githubusercontent.com/maur/paperless/master/docs/examples/lxc/lxc-install.sh && /bin/bash lxc-install.sh --email "
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
 | 
					set +e
 | 
				
			||||||
 | 
					PASSWORD=$(< /dev/urandom tr -dc _A-Z-a-z-0-9+@%^{} | head -c20;echo;)
 | 
				
			||||||
 | 
					EMAIL=
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Add paperless user with no password
 | 
					function displayHelp() {
 | 
				
			||||||
adduser --disabled-password --gecos "" paperless
 | 
					    echo "available parameters:
 | 
				
			||||||
# Add ftpupload
 | 
					    -e <email> | --email <email> 
 | 
				
			||||||
adduser --disabled-password --gecos "" ftpupload
 | 
					    -p <password> | --password <password>
 | 
				
			||||||
echo "Set ftpupload password: "
 | 
					    "
 | 
				
			||||||
passwd ftpupload
 | 
					}
 | 
				
			||||||
# Allow paperless group to access
 | 
					
 | 
				
			||||||
adduser paperless ftpupload
 | 
					POSITIONAL=()
 | 
				
			||||||
chmod g+w /home/ftpupload 
 | 
					while [[ $# -gt 0 ]]
 | 
				
			||||||
 | 
					do
 | 
				
			||||||
 | 
					key="$1"
 | 
				
			||||||
 | 
					i=$key
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					case $i in
 | 
				
			||||||
 | 
					    -e|--email)
 | 
				
			||||||
 | 
					      EMAIL="${2}"
 | 
				
			||||||
 | 
					      shift
 | 
				
			||||||
 | 
					      shift
 | 
				
			||||||
 | 
					    ;;
 | 
				
			||||||
 | 
					    -p|--password)
 | 
				
			||||||
 | 
					      PASSWORD="${2}"
 | 
				
			||||||
 | 
					      shift
 | 
				
			||||||
 | 
					      shift
 | 
				
			||||||
 | 
					    ;;
 | 
				
			||||||
 | 
					    --default|-h|--help)
 | 
				
			||||||
 | 
					      shift
 | 
				
			||||||
 | 
					      displayHelp
 | 
				
			||||||
 | 
					      exit 0
 | 
				
			||||||
 | 
					    ;;
 | 
				
			||||||
 | 
					    *)
 | 
				
			||||||
 | 
					      echo "argument: $i not recognized"
 | 
				
			||||||
 | 
					      exit 2
 | 
				
			||||||
 | 
					    ;;
 | 
				
			||||||
 | 
					esac
 | 
				
			||||||
 | 
					done
 | 
				
			||||||
 | 
					set -- "${POSITIONAL[@]}" # restore positional parameters
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if [ -z $EMAIL ]; then
 | 
				
			||||||
 | 
					  echo "missing email, try running with -h "
 | 
				
			||||||
 | 
					  exit 3
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if [ $(grep -c paperless /etc/passwd) -eq 0 ]; then
 | 
				
			||||||
 | 
					  # Add paperless user with no password
 | 
				
			||||||
 | 
					  adduser --disabled-password --gecos "" paperless
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if [ $(grep -c ftpupload /etc/passwd) -eq 0 ]; then
 | 
				
			||||||
 | 
					  # Add ftpupload
 | 
				
			||||||
 | 
					  adduser --disabled-password --gecos "" ftpupload
 | 
				
			||||||
 | 
					  echo "Set ftpupload password: "
 | 
				
			||||||
 | 
					  #passwd ftpupload
 | 
				
			||||||
 | 
					  #TODO: generate some password and allow parameter 
 | 
				
			||||||
 | 
					  echo "ftpupload:ftpuploadpassword" | chpasswd
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if [ $(id -nG paperless | grep -Fcw ftpupload) -eq 0 ]; then
 | 
				
			||||||
 | 
					  # Allow paperless group to access
 | 
				
			||||||
 | 
					  adduser paperless ftpupload
 | 
				
			||||||
 | 
					  chmod g+w /home/ftpupload 
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Get apt up to date
 | 
					# Get apt up to date
 | 
				
			||||||
apt-get update
 | 
					apt-get update
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Needed for plain Paperless
 | 
					# Needed for plain Paperless
 | 
				
			||||||
apt-get -y install unpaper gnupg libpoppler-cpp-dev python3-pyocr tesseract-ocr imagemagick optipng
 | 
					apt-get -y install unpaper gnupg libpoppler-cpp-dev python3-pyocr tesseract-ocr imagemagick optipng git
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Needed for Apache
 | 
					# Needed for Apache
 | 
				
			||||||
apt-get -y install apache2 libapache2-mod-wsgi-py3
 | 
					apt-get -y install apache2 libapache2-mod-wsgi-py3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Install ftp server and make sure all uplaoded files are owned by paperless
 | 
					if [ ! -f /etc/proftpd/proftpd.conf -o $(grep -c paperless /etc/proftpd/proftpd.conf) -eq 0 ]; then
 | 
				
			||||||
apt-get -y install proftpd
 | 
					  # Install ftp server and make sure all uplaoded files are owned by paperless
 | 
				
			||||||
cat <<EOF >> /etc/proftpd/proftpd.conf
 | 
					  apt-get -y install proftpd
 | 
				
			||||||
<Directory /home/ftpupload/>
 | 
					  cat <<EOF >> /etc/proftpd/proftpd.conf
 | 
				
			||||||
  UserOwner   paperless
 | 
					  <Directory /home/ftpupload/>
 | 
				
			||||||
  GroupOwner  paperless
 | 
					    UserOwner   paperless
 | 
				
			||||||
</Directory>
 | 
					    GroupOwner  paperless
 | 
				
			||||||
 | 
					  </Directory>
 | 
				
			||||||
EOF
 | 
					EOF
 | 
				
			||||||
systemctl restart proftpd
 | 
					  systemctl restart proftpd
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#Get Paperless from git 
 | 
					#Get Paperless from git 
 | 
				
			||||||
su -c "cd /home/paperless ; git clone https://github.com/maur/paperless" paperless
 | 
					su -c "cd /home/paperless ; git clone https://github.com/maur/paperless" paperless
 | 
				
			||||||
@@ -58,16 +115,23 @@ sed  -i "s/#PAPERLESS_SECRET_KEY.*/PAPERLESS_SECRET_KEY=$SECRET/" /etc/paperless
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#Initialise the SQLite database 
 | 
					#Initialise the SQLite database 
 | 
				
			||||||
su -c "cd /home/paperless/paperless/src/ ; ./manage.py migrate" paperless
 | 
					su -c "cd /home/paperless/paperless/src/ ; ./manage.py migrate" paperless
 | 
				
			||||||
 | 
					echo "if superuser doesn't exists, create one with login: paperless and password: ${PASSWORD}"
 | 
				
			||||||
#Create a user for your Paperless instance
 | 
					#Create a user for your Paperless instance
 | 
				
			||||||
su -c "cd /home/paperless/paperless/src/ ; ./manage.py createsuperuser" paperless
 | 
					su -c "cd /home/paperless/paperless/src/ ; echo ./manage.py create_superuser_with_password --username paperless --email ${EMAIL} --password ${PASSWORD} --preserve" paperless
 | 
				
			||||||
# 167 static files copied to '/home/paperless/paperless/static'.
 | 
					su -c "cd /home/paperless/paperless/src/ ; ./manage.py create_superuser_with_password --username paperless --email ${EMAIL} --password ${PASSWORD} --preserve" paperless
 | 
				
			||||||
su -c "cd /home/paperless/paperless/src/ ; ./manage.py collectstatic" paperless
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Set-up apache
 | 
					if [ ! -d /home/paperless/paperless/static ]; then
 | 
				
			||||||
cp /home/paperless/paperless/docs/examples/lxc/paperless.conf /etc/apache2/sites-available/
 | 
					  # 167 static files copied to '/home/paperless/paperless/static'.
 | 
				
			||||||
a2dissite 000-default.conf
 | 
					  su -c "cd /home/paperless/paperless/src/ ; ./manage.py collectstatic" paperless
 | 
				
			||||||
a2ensite paperless.conf
 | 
					fi
 | 
				
			||||||
systemctl reload apache2
 | 
					
 | 
				
			||||||
 | 
					if [ ! -f /etc/apache2/sites-available/paperless.conf ]; then
 | 
				
			||||||
 | 
					  # Set-up apache
 | 
				
			||||||
 | 
					  cp /home/paperless/paperless/docs/examples/lxc/paperless.conf /etc/apache2/sites-available/
 | 
				
			||||||
 | 
					  a2dissite 000-default.conf
 | 
				
			||||||
 | 
					  a2ensite paperless.conf
 | 
				
			||||||
 | 
					  systemctl reload apache2
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
sed -e "s:home/paperless/project/virtualenv/bin/python:usr/bin/python3:" \
 | 
					sed -e "s:home/paperless/project/virtualenv/bin/python:usr/bin/python3:" \
 | 
				
			||||||
     /home/paperless/paperless/scripts/paperless-consumer.service \
 | 
					     /home/paperless/paperless/scripts/paperless-consumer.service \
 | 
				
			||||||
@@ -83,4 +147,6 @@ systemctl start paperless-consumer
 | 
				
			|||||||
# convert-im6.q16: not authorized
 | 
					# convert-im6.q16: not authorized
 | 
				
			||||||
# Security risk ?
 | 
					# Security risk ?
 | 
				
			||||||
# https://stackoverflow.com/questions/42928765/convertnot-authorized-aaaa-error-constitute-c-readimage-453
 | 
					# https://stackoverflow.com/questions/42928765/convertnot-authorized-aaaa-error-constitute-c-readimage-453
 | 
				
			||||||
mv /etc/ImageMagick-6/policy.xml /etc/ImageMagick-6/policy.xmlout
 | 
					if [ -f /etc/ImageMagick-6/policy.xml ]; then
 | 
				
			||||||
 | 
					  mv /etc/ImageMagick-6/policy.xml /etc/ImageMagick-6/policy.xmlout
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										38
									
								
								management/commands/create_superuser_with_password.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								management/commands/create_superuser_with_password.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,38 @@
 | 
				
			|||||||
 | 
					from django.contrib.auth.management.commands import createsuperuser
 | 
				
			||||||
 | 
					from django.core.management import CommandError
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class Command(createsuperuser.Command):
 | 
				
			||||||
 | 
					    help = 'Crate a superuser, and allow password to be provided'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def add_arguments(self, parser):
 | 
				
			||||||
 | 
					        super(Command, self).add_arguments(parser)
 | 
				
			||||||
 | 
					        parser.add_argument(
 | 
				
			||||||
 | 
					            '--password', dest='password', default=None,
 | 
				
			||||||
 | 
					            help='Specifies the password for the superuser.',
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					        parser.add_argument(
 | 
				
			||||||
 | 
					            '--preserve', dest='preserve', default=False, action='store_true',
 | 
				
			||||||
 | 
					            help='Exit normally if the user already exists.',
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def handle(self, *args, **options):
 | 
				
			||||||
 | 
					        password = options.get('password')
 | 
				
			||||||
 | 
					        username = options.get('username')
 | 
				
			||||||
 | 
					        database = options.get('database')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if password and not username:
 | 
				
			||||||
 | 
					            raise CommandError("--username is required if specifying --password")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if username and options.get('preserve'):
 | 
				
			||||||
 | 
					            exists = self.UserModel._default_manager.db_manager(database).filter(username=username).exists()
 | 
				
			||||||
 | 
					            if exists:
 | 
				
			||||||
 | 
					                self.stdout.write("User exists, exiting normally due to --preserve")
 | 
				
			||||||
 | 
					                return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        super(Command, self).handle(*args, **options)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if password:
 | 
				
			||||||
 | 
					            user = self.UserModel._default_manager.db_manager(database).get(username=username)
 | 
				
			||||||
 | 
					            user.set_password(password)
 | 
				
			||||||
 | 
					            user.save()
 | 
				
			||||||
		Reference in New Issue
	
	Block a user