Updates for packages

This commit is contained in:
DarkFeather 2024-09-02 23:54:57 -05:00
parent f139ea55b4
commit 59b3181d61
Signed by: DarkFeather
GPG Key ID: 1CC1E3F4ED06F296
17 changed files with 473 additions and 54 deletions

View File

@ -1,4 +1,4 @@
binlist = ldap-adduser ldap-userreport ldap-resetpass binlist = ldap-adduser ldap-userreport ldap-resetpass ldap-recreateuser
filelist = sample-user.ldif filelist = sample-user.ldif
compile: compile:

View File

@ -0,0 +1,22 @@
#!/bin/bash
uid="$1"
userfile="/etc/openldap/users.d/$uid.ldif"
if [ -z "$uid" ]; then
echo "Need a user ID (uid)!"
exit 1
fi
if [ ! -f "$userfile" ]; then
ldapsearch -x "uid=${uid}" > "$userfile"
echo "$userfile" had to be created -- please validate before re-running this script.
exit 2
fi
read -sp 'cn=root,dc=aninix,dc=net Password: ' rootdnpw
ldapdelete -D 'cn=root,dc=aninix,dc=net' -w "$rootdnpw" -H ldap://127.0.0.1 "uid=$uid,ou=People,dc=aninix,dc=net" && \
ldapadd -D 'cn=root,dc=aninix,dc=net' -w "$rootdnpw" -H ldap://127.0.0.1 -f "$userfile"
exit $?

View File

@ -7,8 +7,25 @@ if [ -z "$uid" ]; then
exit 1 exit 1
fi fi
ldappasswd -D 'cn=root,dc=aninix,dc=net' -W -H ldap://127.0.0.1 "uid=$uid,ou=People,dc=aninix,dc=net" read -sp 'cn=root,dc=aninix,dc=net Password: ' rootdnpw
#ldapmodify -D 'cn=root,dc=aninix,dc=net' -W -H ldap://127.0.0.1 -f <(printf "dn: uid=$uid,ou=People,dc=aninix,dc=net\nchangetype: modify\nadd: pwdReset\npwdReset: TRUE\n\n") ldappasswd -D 'cn=root,dc=aninix,dc=net' -w "$rootdnpw" -H ldap://127.0.0.1 "uid=$uid,ou=People,dc=aninix,dc=net" && \
ldapmodify -D 'cn=root,dc=aninix,dc=net' -w "$rootdnpw" -H ldap://127.0.0.1 -f <(cat <<EOM
dn: uid=$uid,ou=People,dc=aninix,dc=net
changetype: modify
add: pwdReset
pwdReset: TRUE
EOM
)
echo 'As cn=root,cn=config...' && ldapmodify -D 'cn=root,cn=config' -W -H ldap://127.0.0.1 -f <(cat <<EOM
dn: uid=$uid,ou=People,dc=aninix,dc=net
changetype: modify
delete: pwdChangedTime
EOM
)
exit $? exit $?

View File

@ -1,54 +1,95 @@
#!/bin/bash #!/bin/bash
hostname=`hostname` function getLDAPAttr() {
errortext="ERROR:NEVER" ### Get an LDAP attribute
arg="$1" # param: filter
# param attribute
function shortshow() { filter="${1}"
echo ${user}": "$email attribute="${2}"
ldapsearch -x "${filter}" "${attribute}" | grep -E "^${attribute}: " | sed "s/${attribute}: //"
} }
basedn=`ldapsearch -x '(cn=root)' dn | grep -E ^dn:\ | sed 's/dn: cn=root,//'` # Clear cleanup files
ldif="/root/cleanup.ldif"
>"${ldif}"
bash="/root/cleanup.bash"
echo "#!/bin/bash" > "${bash}"
for user in `ldapsearch -x -b "ou=People,$basedn" '(uid=*)' uid | grep -E ^uid:\ | sed 's/^uid: //'`; do # Attributes
basedn=`getLDAPAttr '(cn=root)' dn | sed 's/cn=root,//'`
pwdMaxAge=`getLDAPAttr '(&(cn=default)(objectClass=pwdPolicy))' pwdMaxAge`
warning=`getLDAPAttr '(&(cn=default)(objectClass=pwdPolicy))' pwdExpireWarning`
pwdWarnAge=$(( $pwdMaxAge - $warning ))
unset EXPIRED EXPIRING OK PENDING
### Check all users
for user in `ldapsearch -x -b "ou=People,$basedn" uid | grep -E ^uid:\ | sed 's/^uid: //'`; do
# Pull changed stats # Pull changed stats
lastChanged=`/usr/sbin/ldapsearch -x "(uid=$user)" + | grep pwdChangedTime | cut -f 2 -d ' '` lastChanged=`/usr/sbin/ldapsearch -x "(uid=$user)" + | grep pwdChangedTime | cut -f 2 -d ' '`
created=`/usr/sbin/ldapsearch -x "(uid=$user)" + | grep createTimestamp | cut -f 2 -d ' '` # created=`/usr/sbin/ldapsearch -x "(uid=$user)" + | grep createTimestamp | cut -f 2 -d ' '`
email=`/usr/sbin/ldapsearch -x "(uid=$user)" | grep mail | cut -f 2 -d ' '` # email=`/usr/sbin/ldapsearch -x "(uid=$user)" | grep mail | cut -f 2 -d ' '`
# If user has PENDING changed, report
if [ -z "$lastChanged" ]; then if [ -z "$lastChanged" ]; then
lastChanged="$errortext"; if [ -z "${PENDING}" ]; then
PENDING="${user}"
else
PENDING="${PENDING},${user}"
fi
else else
delta="$(( `date +%s` - `date -d $(echo $lastChanged | head -c 8) +%s`))" delta="$(( `date +%s` - `date -d $(echo $lastChanged | head -c 8) +%s`))"
fi
lastlog=`lastlog -u $user | tail -n 1` # Report if user is expired
if [ `echo $lastlog | grep -c 'Never logged in'` -gt 0 ]; then if [ $delta -gt $pwdMaxAge ]; then
lastlog=$errortext if [ -z "${EXPIRED}" ]; then
EXPIRED="${user}"
else else
lastlog=`echo $lastlog | awk '{$1="";$2="";$3="";print $0 }'` EXPIRED="${EXPIRED},${user}"
fi fi
printf "User $user (email: $email, created: $created) last changed their password on $lastChanged. They last logged in to SSH on $hostname on $lastlog\n" | ( printf "dn: uid=${user},ou=People,${basedn}\nchangetype: delete\n\n" >> "${ldif}"
case "$arg" in printf "rm -Rf `getent passwd "${user}" | cut -f 6 -d ':'`\n" >> "${bash}"
"--inactive")
if grep -E $errortext'$' &> /dev/null; then shortshow; fi # Report if the user is expiring and needs to update their password.
;; elif [ $delta -gt $pwdWarnAge ] && [ $delta -le $pwdMaxAge ]; then
"--needschange") if [ -z "${EXPIRING}" ]; then
if [ "$lastChanged" == "$errortext" ]; then EXPIRING="${user}"
shortshow
else else
if [ $delta -gt 28512000 ] && [ $delta -lt 31536000 ]; then shortshow; fi EXPIRING="${EXPIRING},${user}"
fi
# Record the user account is OK.
else
if [ -z "${OK}" ]; then
OK="${user}"
else
OK="${OK},${user}"
fi
fi fi
;;
"--expired")
if [ "$lastChanged" != "$errortext" ] && [ "$delta" -ge 31536000 ]; then
shortshow;
fi fi
;;
*)
cat
;;
esac
)
done done
### Results
# Should always have OK users in the tree.
echo "OK: ${OK}"
# Report when there are users that have not changed their password.
# This may be normal, such as for new user accounts, and may not drive action.
if [ -n "$PENDING" ]; then
echo "PENDING: ${PENDING}"
fi
# Report when users are expiring -- give them several notices to fix it.
if [ -n "${EXPIRING}" ]; then
echo "EXPIRING: ${EXPIRING}"
ravensend -c "#tech" -m "The following users are expiring: ${EXPIRING}"
fi
# Report users that have expired. These users should be contacted or removed.
if [ -n "${EXPIRED}" ]; then
echo "EXPIRED: ${EXPIRED}"
echo "Expired users can be cleaned up with ${ldif} and ${bash}"
ravensend -c "#sharingan" -m 'Users have expired and need attention.'
fi

View File

@ -0,0 +1,24 @@
compile:
@echo Nothing to do
install: clean
mkdir -p ${pkgdir}/usr/local/bin/
for i in yggdrasil-get yggdrasil-lock yggdrasil-set-music-data yggdrasil-sha256 yggdrasil-sort-shows yggdrasil-unlock; do install -m 0750 -o root -g http $$i ${pkgdir}/usr/local/bin/; done
mkdir -p ${pkgdir}/usr/lib/systemd/system
for i in *.timer *.service; do install -m 0755 -o root -g root $$i ${pkgdir}/usr/lib/systemd/system; done
test: compile
@echo Nothing to do
clean:
git clean -fX
git clean -fd
diff:
@echo Nothing to do.
reverse:
@echo Nothing to do.
checkperm:
@echo Nothing to do.

View File

@ -0,0 +1,46 @@
depends=('bash>=4.4')
makedepends=('make>=4.2')
checkdepends=()
optdepends=()
pkgname="yggdrasil-scripts"
pkgver="$(git describe --tag --abbrev=0)"."$(git rev-parse --short HEAD)"
pkgrel=1
pkgrel() {
echo $(( `git log "$(git describe --tag --abbrev=0)"..HEAD | grep -c commit` + 1 ))
}
epoch="$(git log | grep -c commit)"
pkgdesc="$(head -n 1 README.md)"
arch=("x86_64")
url="$(git config remote.origin.url | sed 's/.git$//')"
license=('custom')
groups=()
provides=("${pkgname}")
conflicts=()
replaces=("${pkgname,,}", "aninix-${pkgname,,}")
backup=()
options=()
install=
changelog=
source=()
noextract=()
md5sums=()
validpgpkeys=()
prepare() {
git pull
}
build() {
make -C ..
}
check() {
chmod -R u+r ../pkg
make -C .. test
}
package() {
export pkgdir="${pkgdir}"
make -C .. install
install -D -m644 ../../../../LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

View File

@ -0,0 +1,90 @@
#!/bin/bash
export YGGDRASIL="/srv/yggdrasil"
option="$1"
path="$2"
newname="$3"
#Offer help
if [ "$option" == "" ] || [ "$option" == "-h" ] || [ "$option" == "--help" ] || [ "$path" == "" ] || [ $(echo $newname | grep -c '/') -ne 0 ]; then
echo "AniNIX::Yggdrasil Bash API"
echo 'Syntax: yggdrasil-get {dl|yt|mp3|sol|cp|mv} PATH [new file name in $PWD]'
echo "Option:"
echo "-- dl: Use wget"
echo "-- yt: Use youtube-dl"
echo "-- mp3: Use youtube-mp3"
echo "-- sol: Use solarmovie-vodlocker-dl"
echo "-- cp: Copy the file here."
echo "-- mv: Move the file here."
echo "-- mkdir: Make a folder"
exit;
fi
#Make sure we're in the Yggdrasil project.
if [ $(expr match "$PWD" "$YGGDRASIL") -ne $(expr length "$YGGDRASIL") ]; then
echo "Not in the Yggdrasil directory.";
exit;
fi
#unlock this directory
chmod ug+w "$PWD"
#Appropriately source the file
if [ $? -ne 0 ]; then
echo Couldn\'t unlock $PWD
exit
fi
if [ "$option" == "dl" ]; then
if [ "$newname" != "" ]; then
wget -O "$newname" "$path";
else
wget "$path";
fi
fi
if [ "$option" == "yt" ]; then
if [ `echo "$path" | grep -c '/watch?v='` -eq 1 ]; then
path="$(echo "$path" | cut -f 1 -d '&')"
fi
if [ "$newname" != "" ]; then
youtube-dl -o "$newname" "$path";
else
youtube-dl "$path";
fi
fi
if [ "$option" == "mp3" ]; then
if [ "$newname" != "" ]; then
echo "Renaming not available."
fi
if [ `echo "$path" | grep -c '/watch?v='` -eq 1 ]; then
path="$(echo "$path" | cut -f 1 -d '&')"
fi
youtube-mp3 "$path";
yggdrasil-set-music-data *.mp3
fi
if [ "$option" == "sol" ]; then
if [ "$newname" != "" ]; then
solarmovie-vodlocker-dl "$path" "$newname"
else
echo "Need a name."
fi
fi
if [ "$option" == "cp" ]; then
if [ "$newname" != "" ]; then
cp "$path" ./"$newname"
else
cp "$path" .
fi
fi
if [ "$option" == "mv" ]; then
if [ "$newname" != "" ]; then
mv "$path" ./"$newname"
else
mv "$path" .
fi
fi
if [[ "$option" == "mkdir" && "$path" != "" ]]; then
mkdir -p "$path"
fi
#Lock
chmod -R ug-w "$PWD"

View File

@ -0,0 +1,5 @@
#!/bin/bash
chown -P -R DarkFeather:http /srv/yggdrasil
find -P /srv/yggdrasil/ -type f -exec chmod 0440 {} \;
find -P /srv/yggdrasil/ -type d -exec chmod 0550 {} \;
chmod -R u+w /srv/yggdrasil/new_acquisition

View File

@ -0,0 +1,48 @@
#!/bin/bash
parser="$(echo $PWD | rev)"
IFS="
"
partist="$(echo $parser | cut -f 2 -d '/' | rev)"
palbum="$(echo $parser | cut -f 1 -d '/' | rev)"
pgenre="$(echo $parser | cut -f 3 -d '/' | rev)"
if [ "$partist" == "" ] || [ "$palbum" == "" ] || [ "$pgenre" == "" ]; then
echo "This script expects a format of "'$MUSICBASEPATH'"/Genre/Artist/Album/Song.ext"
exit;
fi
echo Expected metadata:
echo Artist: $partist
echo Album: $palbum
echo Genre: $pgenre
echo
for i in $@; do
if [ ! -f "$i" ]; then
echo File doesn\'t exist. $i
continue;
fi
ffartist="$(ffprobe -hide_banner -i $i 2>&1 | grep artist | grep -v 'album_artist' | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' | sed -e 's/*[[:space:]]$//')"
ffalbum="$(ffprobe -hide_banner -i $i 2>&1 | grep album | grep -v 'album_artist' | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' | sed -e 's/*[[:space:]]$//')"
ffgenre="$(ffprobe -hide_banner -i $i 2>&1 | grep genre | head -n 1 | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' | sed -e 's/*[[:space:]]$//')"
echo For \[$i\]...
unset tags
echo Found artist \[$ffartist\]
if [ "$partist" != "$ffartist" ]; then
export tags=$tags" -metadata artist=\"$partist\""
fi
echo Found album \[$ffalbum\]
if [ "$ffalbum" != "$palbum" ]; then
export tags=$tags" -metadata album=\"$palbum\""
fi
echo Found genre \[$ffgenre\]
if [ "$ffgenre" != "$pgenre" ]; then
export tags=$tags" -metadata genre=\"$pgenre\""
fi
if [ "$tags" != "" ]; then
bash -c "ffmpeg -hide_banner -i \"$i\"$tags \"$i.ffmpeg.mp3\""
mv "$i.ffmpeg.mp3" "$i"
fi
echo
done

View File

@ -0,0 +1,26 @@
#!/bin/bash
set -x
basedir="/srv/yggdrasil"
shafile="$basedir""/library.sha256"
option="$1"
if [ "$option" == "-h" ] || [ "$option" == "--help" ]; then
echo Usage: $0 '[verify]'
exit 1
fi
if [[ "$option" != "verify" ]]; then
chmod u+w "$basedir"
touch "$shafile"
chmod u+w "$shafile"
find "$basedir" -type f -exec sha256sum {} \; > "$shafile"
chmod u-w "$basedir" "$shafile"
exit 0;
else
echo "These files have problems:"
sha256sum -c "$shafile";
exit $?;
fi

View File

@ -0,0 +1,74 @@
#!/bin/bash
baseDir="/srv/yggdrasil/Videos/Shows"
# Helptext
function usage() {
echo Sort files from /srv/yggdrasil/new_acquisition into appropriate show directories.
echo
echo Usage: $0 '[ -h ] [ -f fileToUse ] [ -c ] [ -n ] [ -q ] [ -v ]'
echo ' -c: Create sample sort file'
echo ' -f: Use this sort file'
echo ' -h: print this helptext.'
echo ' -n: Do not lock the libary -- this is useful for sorting other things after execution.'
echo ' -q: Mute output'
echo ' -v: Increase verbosity'
}
# Handle a file
# param file: the file to parse
function HandleFile() {
file="$1"
# Sort out file metadata
dirtyshowname="$(echo "$file" | sed 's/.[Ss][0-9].[Ee][0-9].*$//')"
showname="$(ls -1 "$baseDir" | grep -iE "$dirtyshowname")"
epinfo="$(echo "$file" | sed "s/^${dirtyshowname}.//" | head -c 6)"
season="$(echo "$epinfo" | head -c 3 | tail -c 2)"
episode="$(echo -n "$epinfo" | tail -c 2)"
target="$baseDir"/"$showname"/Season\ "$season"
# Ensure metadata sorting didn't return nulls
for i in dirtyshowname showname epinfo season episode target; do
if [ -z "${!i}" ]; then
echo ERROR: Could not handle "$file" because we could not find $i
return
fi
done
# Make sure target exists
# Move file to target
if [ ! -d "$(dirname "$target")" ]; then
echo WARN -- could not find the right show to sort "$file"
fi
# Make sure the show folder exists
mkdir -p "$target"
mv "$file" "$target"
}
# Parse arguments.
while getopts 'b:cf:hnqv' OPTION; do
case "$OPTION" in
b) baseDir="${OPTARG}" ;;
h) usage; exit 0 ;;
l) exec $0 $(echo $@ | sed "s/-s\s+${OPTARG}(.|$)//") | tee -a "${OPTARG}" ;;
n) nolock="1" ;;
q) exec $0 $(echo $@ | sed 's/-q//') &>/dev/null ;;
v) set -x ;;
*) usage; exit 1 ;;
esac
done
cd /srv/yggdrasil/new_acquisition
echo INFO Unlocking filestore
if [ `whoami` != "root" ]; then yggdrasil-unlock; fi
echo INFO Sorting....
# Find all files matching *S??E??* syntax
ls -1d *[S,s]??[E,e]??* 2>/dev/null | while read file; do
HandleFile "${file}"
done
if [ -z "$nolock" ] && [ `whoami` != "root" ]; then
echo INFO Locking filestore
yggdrasil-lock &>/dev/null
fi

View File

@ -0,0 +1,12 @@
[Unit]
Description=AniNIX/Yggdrasil | Sort shows
[Service]
ExecStartPre=/usr/local/bin/yggdrasil-unlock
ExecStart=/usr/local/bin/yggdrasil-sort-shows
ExecStartPost=/usr/local/bin/yggdrasil-lock
KillMode=process
Type=oneshot
RemainAfterExit=no
User=root
Group=root

View File

@ -0,0 +1,10 @@
[Unit]
Description=AniNIX/Yggdrasil | Sort shows timer
[Timer]
OnCalendar=*:0/15
AccuracySec=12h
Persistent=true
[Install]
WantedBy=timers.target

View File

@ -0,0 +1,2 @@
#!/bin/bash
find -P /srv/yggdrasil -type d -exec chmod u+w {} \;

View File

@ -5,6 +5,8 @@
package: package:
name: name:
- emby-server - emby-server
- perl-image-exiftool
- ffmpeg
- name: Yggdrasil directories - name: Yggdrasil directories
become: yes become: yes
@ -15,16 +17,16 @@
group: http group: http
mode: 2750 mode: 2750
loop: loop:
- /srv/yggdrasil - /home/yggdrasil
- /srv/yggdrasil/Digital_Library - /home/yggdrasil/Digital_Library
- /srv/yggdrasil/Music - /home/yggdrasil/Music
- /srv/yggdrasil/Videos - /home/yggdrasil/Videos
- /srv/yggdrasil/Videos/Shows - /home/yggdrasil/Videos/Shows
- /srv/yggdrasil/Videos/Movies - /home/yggdrasil/Videos/Movies
- /srv/yggdrasil/Software - /home/yggdrasil/Software
- name: LiveTV channels - name: LiveTV channels
command: /bin/bash -c "curl -s https://raw.githubusercontent.com/iptv-org/iptv/master/streams/us.m3u | egrep -A 1 '{{ iptv_location }}' 2>&1 | egrep -v '^--$'" command: /bin/bash -c "curl -s https://raw.githubusercontent.com/iptv-org/iptv/master/streams/us.m3u | grep -A 1 -E '{{ iptv_location }}' 2>&1 | grep -vE '^--$'"
register: livetv_channels register: livetv_channels
- name: Write to file - name: Write to file